Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 9 Jun 2007 07:54:30 GMT
From:      Andrew Turner <andrew@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 121252 for review
Message-ID:  <200706090754.l597sU1B022220@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=121252

Change 121252 by andrew@andrew_hermies on 2007/06/09 07:53:40

	- Add the facund.Computer class to allow communication between the UI and the network
	- Add a Connect and Disconnect button below the computer list
	- Add the local computer to the display
	- Fix facund.network.Connection to close the connection properly
	The front and back ends can now communicate with each other when the connect button is clicked. The only messages passed however are connection start and stop.

Affected files ...

.. //depot/projects/soc2007/andrew-update/frontend/facund-fe.glade#2 edit
.. //depot/projects/soc2007/andrew-update/frontend/facund.py#5 edit
.. //depot/projects/soc2007/andrew-update/frontend/facund/__init__.py#4 edit
.. //depot/projects/soc2007/andrew-update/frontend/facund/computer.py#1 add
.. //depot/projects/soc2007/andrew-update/frontend/facund/gui/computer_model.py#4 edit
.. //depot/projects/soc2007/andrew-update/frontend/facund/gui/main_window.py#4 edit
.. //depot/projects/soc2007/andrew-update/frontend/facund/network/__init__.py#4 edit

Differences ...

==== //depot/projects/soc2007/andrew-update/frontend/facund-fe.glade#2 (text+ko) ====

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.2.0 on Wed Jun  6 15:05:04 2007 by andrew@hermies.int.fubar.geek.nz-->
+<!--Generated with glade3 3.2.0 on Sat Jun  9 15:17:19 2007 by andrew@hermies.int.fubar.geek.nz-->
 <glade-interface>
   <widget class="GtkWindow" id="facundWindow">
     <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
@@ -180,11 +180,53 @@
             <property name="can_focus">True</property>
             <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
             <child>
-              <widget class="GtkTreeView" id="computerView">
+              <widget class="GtkVBox" id="vbox2">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="headers_clickable">True</property>
+                <child>
+                  <widget class="GtkTreeView" id="computerView">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                    <property name="headers_clickable">True</property>
+                  </widget>
+                </child>
+                <child>
+                  <widget class="GtkHBox" id="hbox1">
+                    <property name="visible">True</property>
+                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                    <child>
+                      <widget class="GtkButton" id="connectButton">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                        <property name="label" translatable="yes">Connect</property>
+                      </widget>
+                      <packing>
+                        <property name="padding">5</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkButton" id="disconnectButton">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                        <property name="label" translatable="yes">Disconnect</property>
+                      </widget>
+                      <packing>
+                        <property name="padding">5</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="padding">10</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
               </widget>
               <packing>
                 <property name="resize">False</property>
@@ -204,6 +246,8 @@
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                    <property name="editable">False</property>
+                    <property name="text" translatable="yes">	</property>
                   </widget>
                 </child>
               </widget>

==== //depot/projects/soc2007/andrew-update/frontend/facund.py#5 (text+ko) ====

@@ -27,7 +27,7 @@
 
 import socket
 
-import facund.gui, facund.network
+import facund, facund.gui, facund.network
 
 
 #try:
@@ -39,6 +39,9 @@
 
 if __name__ == "__main__":
 	model = facund.gui.ComputerTreeModel()
+	localComputer = facund.Computer("Fake disconnected computer", '/tmp/facund')
+	model.addComputer(localComputer)
+
 	mainWindow = facund.gui.MainWindow('facund-fe.glade')
 	mainWindow.setComputerTreeModel(model)
 

==== //depot/projects/soc2007/andrew-update/frontend/facund/__init__.py#4 (text+ko) ====

@@ -24,4 +24,6 @@
 # SUCH DAMAGE.
 #
 
+from computer import Computer
+
 __all__ = ["gui", "network"]

==== //depot/projects/soc2007/andrew-update/frontend/facund/gui/computer_model.py#4 (text+ko) ====

@@ -33,23 +33,31 @@
 	def __init__(self):
 		gtk.TreeStore.__init__(self, gobject.TYPE_STRING)
 
-		self.addComputer("Test")
-		#self.removeComputer("Test")
+		self.__computers = {}
 
-	def addComputer(self, computer, base_dirs = None):
+	def addComputer(self, computer):
 		'''Adds a computer to the computer tree view'''
-		if base_dirs is None:
-			base_dirs = ["Foo", "Bar"]
+
+		computer_name = computer.getName()
+		if self.__computers.has_key(computer_name):
+			# TODO: This should either raise an exception or just replace the item and update the tree view
+			return
+		self.__computers[computer_name] = computer
 
 		# Add the computer
 		iter = self.append(None)
-		self.set(iter, 0, computer)
+		self.set(iter, 0, computer_name)
 
 		# Add the children
-		for dir in base_dirs:
+		for dir in computer.getDirs():
 			child_iter = self.append(iter)
 			self.set(child_iter, 0, dir)
 
+	def getComputer(self, position):
+		'''Returns the computer at the given position in the tree'''
+		name = self[position][0]
+		return self.__computers[name]
+
 	def removeComputer(self, computer):
 		'''Removes a computer from the computer tree. TODO: Implement'''
 		iter = self.get_iter_from_string(computer)

==== //depot/projects/soc2007/andrew-update/frontend/facund/gui/main_window.py#4 (text+ko) ====

@@ -34,20 +34,64 @@
 
 	def __init__(self, glade_file):
 		gtk.gdk.threads_init()
-		self.xml = gtk.glade.XML(glade_file)
-		self.widget = self.xml.get_widget('facundWindow')
-            	self.widget.connect('destroy', lambda *w: gtk.main_quit())
+
+		self.__xml = gtk.glade.XML(glade_file)
+		self.__widget = self.__xml.get_widget('facundWindow')
+            	self.__widget.connect('destroy', lambda *w: gtk.main_quit())
 
 	def setComputerTreeModel(self, model):
 		'''Sets the model to use to for the computer tree'''
-		treeView = self.xml.get_widget('computerView')
+		self.__computerTreeModel = model
+		treeView = self.__xml.get_widget('computerView')
 		treeView.set_model(model)
 		cell = gtk.CellRendererText()
 		column = gtk.TreeViewColumn("Computer", cell, text=0)
 		treeView.append_column(column)
 
+		treeView.connect('cursor-changed', self.onSelectComputer)
+
+		# Add signal handlers to connect/disconnect
+		connectedButton = self.__xml.get_widget('connectButton')
+		connectedButton.connect('clicked', self.onConnectClick)
+		disconnectedButton = self.__xml.get_widget('disconnectButton')
+		disconnectedButton.connect('clicked', self.onDisconnectClick)
+
+	def setConnected(self, connected):
+		connectedButton = self.__xml.get_widget('connectButton')
+		disconnectedButton = self.__xml.get_widget('disconnectButton')
+
+		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.connect()
+		self.setConnected(computer.getConnectionStatus())
+
+	def onDisconnectClick(self, widget):
+		'''Signal handler for the connect button'''
+		treeView = self.__xml.get_widget('computerView')
+		computer = self.__getCurrentComputer(treeView)
+		computer.disconnect()
+		self.setConnected(computer.getConnectionStatus())
+
+	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())
+
 	def run(self):
 		'''Displays the main window. Does't return'''
-		self.widget.show()
+		self.__widget.show()
 		gtk.main()
 

==== //depot/projects/soc2007/andrew-update/frontend/facund/network/__init__.py#4 (text+ko) ====

@@ -34,18 +34,25 @@
 		self.bufSize = 1024
 		self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
 		self.socket.connect(server)
-		self.socket.send("<facund-client version=\"0\"/>")
+		self.socket.send("<facund-client version=\"0\">")
 
 		self.parser = xml.sax.make_parser()
 		self.parser.setContentHandler(self)
 
-		# Mark the class as ready and able to have __del__ called
+		self.canClose = False
+		# Mark the class as ready and able to disconnect
 		self.isReady = True
 
-	def __del__(self):
+	def disconnect(self):
 		if self.isReady:
+			self.isReady = False
+			# Send a connection close
+			self.socket.send("</facund-client>")
+
+			# Wait for the server to close the connection
+			while not self.canClose:
+				self.interact()
 			self.parser.close()
-			self.socket.send("</facund-client>")
 
 	def interact(self):
 		'''Reads data from the connection and passes it to the
@@ -56,3 +63,9 @@
 	def startElement(self, name, attributes):
 		print "> " + name
 
+	def endElement(self, name):
+		print "< " + name
+		# The server send a close message
+		if name == "facund-server":
+			self.canClose = True
+



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200706090754.l597sU1B022220>