Date: Sun, 8 Jul 2007 06:40:09 GMT From: Andrew Turner <andrew@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 123092 for review Message-ID: <200707080640.l686e9qC041812@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=123092 Change 123092 by andrew@andrew_hermies on 2007/07/08 06:39:39 Add a controller to sit between the computer model and the gui Create a method to populate the children of a computer when connected or remove them Allow the controller to be set in the frontend Move the connected logic from the gui to the controller Move the handler used when an item is selected from the tree view to the controller Affected files ... .. //depot/projects/soc2007/andrew-update/frontend/facund.py#7 edit .. //depot/projects/soc2007/andrew-update/frontend/facund/__init__.py#6 edit .. //depot/projects/soc2007/andrew-update/frontend/facund/controller.py#1 add .. //depot/projects/soc2007/andrew-update/frontend/facund/gui/computer_model.py#5 edit .. //depot/projects/soc2007/andrew-update/frontend/facund/gui/main_window.py#5 edit Differences ... ==== //depot/projects/soc2007/andrew-update/frontend/facund.py#7 (text+ko) ==== @@ -40,10 +40,12 @@ if __name__ == "__main__": model = facund.gui.ComputerTreeModel() localComputer = facund.Computer("Local computer", '/tmp/facund') + localComputer.addDir('/') model.addComputer(localComputer) mainWindow = facund.gui.MainWindow('facund-fe.glade') - mainWindow.setComputerTreeModel(model) + + controller = facund.Controller(model, mainWindow); - mainWindow.run() + controller.run() ==== //depot/projects/soc2007/andrew-update/frontend/facund/__init__.py#6 (text+ko) ==== @@ -24,7 +24,9 @@ # SUCH DAMAGE. # -from computer import Computer +from call import * +from computer import * +from controller import * from data import * __all__ = ["gui", "network"] ==== //depot/projects/soc2007/andrew-update/frontend/facund/gui/computer_model.py#5 (text+ko) ==== @@ -34,6 +34,7 @@ gtk.TreeStore.__init__(self, gobject.TYPE_STRING) self.__computers = {} + self.__iterators = {} def addComputer(self, computer): '''Adds a computer to the computer tree view''' @@ -47,11 +48,23 @@ # Add the computer iter = self.append(None) self.set(iter, 0, computer_name) + self.__iterators[computer] = iter + self.populateComputer(computer) - # Add the children - for dir in computer.getDirs(): - child_iter = self.append(iter) - self.set(child_iter, 0, dir) + def populateComputer(self, computer): + if computer.getConnectionStatus(): + # Add the directories + iter = self.__iterators[computer] + for dir in computer.getDirs(): + dir_iter = self.append(iter) + self.set(dir_iter, 0, dir.getName()) + # Add the commands for each directory + for command in dir.getCommands(): + command_iter = self.append(dir_iter) + self.set(command_iter, 0, command) + else: + pass + def getComputer(self, position): '''Returns the computer at the given position in the tree''' ==== //depot/projects/soc2007/andrew-update/frontend/facund/gui/main_window.py#5 (text+ko) ==== @@ -39,6 +39,9 @@ self.__widget = self.__xml.get_widget('facundWindow') self.__widget.connect('destroy', lambda *w: gtk.main_quit()) + def setController(self, controller): + self.__controller = controller + def setComputerTreeModel(self, model): '''Sets the model to use to for the computer tree''' self.__computerTreeModel = model @@ -63,32 +66,26 @@ connectedButton.set_sensitive(not connected) disconnectedButton.set_sensitive(connected) - def __getCurrentComputer(self, treeView): - '''Finds the currently selected computer''' - cursor = treeView.get_cursor() - position = cursor[0][0] - computer = self.__computerTreeModel.getComputer(position) - return computer - def onConnectClick(self, widget): '''Signal handler for the connect button''' treeView = self.__xml.get_widget('computerView') - computer = self.__getCurrentComputer(treeView) + computer = self.__controller.getCurrentComputer() computer.connect() self.setConnected(computer.getConnectionStatus()) + self.__computerTreeModel.populateComputer(computer) def onDisconnectClick(self, widget): '''Signal handler for the connect button''' treeView = self.__xml.get_widget('computerView') - computer = self.__getCurrentComputer(treeView) + computer = self.__controller.getCurrentComputer() computer.disconnect() self.setConnected(computer.getConnectionStatus()) + self.__computerTreeModel.populateComputer(computer) def onSelectComputer(self, widget): '''Signal handler for when the selected item is changed''' - computer = self.__getCurrentComputer(widget) - # Marke the computer as (dis)connected - self.setConnected(computer.getConnectionStatus()) + cursor = widget.get_cursor() + self.__controller.onComputerTreeSelect(cursor[0]) def run(self): '''Displays the main window. Does't return'''
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707080640.l686e9qC041812>