[gevice] porting to pygobject



commit b847a058d879bd7b941d2e6f5f4da81ab5f1ebd6
Author: Alejandro Valdes Jimenez <avaldes gnome org>
Date:   Tue Oct 4 11:29:50 2011 -0300

    porting to pygobject

 ChangeLog             |    7 +++++++
 src/gevice.py         |   45 +++++++++++++++++++++------------------------
 src/gevicedatabase.py |   22 +++++++---------------
 src/gevicedevice.py   |    9 ++++-----
 4 files changed, 39 insertions(+), 44 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e6371c0..8d51660 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-10-04  Alejandro Valdes Jimenez  <avaldes gnome org>
+	* src/gevice.py: 
+		* show_message(). Add new parameter "window". This indicate the father window where show the message
+		* on_action_save(). rewritten.
+	* src/gevicedatabase.py: show_message() parameters are changed
+	* src/gevicedevice.py: show_message() parameters are changed
+
 2011-10-03  Alejandro Valdes Jimenez  <avaldes gnome org>
 	* New Tag GEVICE_1_0_0
 	* INSTALL-DBASE: update instructions.
diff --git a/src/gevice.py b/src/gevice.py
index a22b609..4cb82c7 100755
--- a/src/gevice.py
+++ b/src/gevice.py
@@ -47,7 +47,7 @@ class Gevice:
     self.connected_to_database = False
     self.context_id = None
     
-    # model for users
+    # model for list of users for SSH session
     self.modelusers = Gtk.ListStore(str)
     
     # model for devices
@@ -95,13 +95,12 @@ class Gevice:
     self.hbox = Gtk.HBox(homogeneous=False, spacing=0)
     self.vbox_main.pack_start (self.hbox,False,False,0)
     
-    # create users combobox
+    # create users combobox for SSH session
     self.separator_user = Gtk.SeparatorToolItem()
     self.toolitem_user = Gtk.ToolItem()
     self.maintoolbar.insert(self.toolitem_user,12)
     
-    self.vboxcombo = Gtk.VBox(homogeneous=False, spacing=0)
-    #self.combobox_user = Gtk.ComboBox(model=self.modelusers,has_entry=True)
+    self.vboxcombo = Gtk.VBox(homogeneous=False,spacing=0)
     self.combobox_user = Gtk.ComboBox(model=self.modelusers,has_entry=False)
     self.vboxcombo.pack_end (self.combobox_user,True,False,0)
     self.toolitem_user.add(self.vboxcombo)
@@ -114,8 +113,6 @@ class Gevice:
     
     # add treeview to vboxtreeview
     self.scroll = Gtk.ScrolledWindow()
-    #self.scroll.set_shadow_type("GTK_SHADOW_ETCHED_IN")
-    #self.scroll.set_policy("GTK_POLICY_AUTOMATIC","GTK_POLICY_AUTOMATIC")
     self.scroll.add (self.gmodel.treeview)
     self.vboxtreeview.add (self.scroll)
     
@@ -123,7 +120,6 @@ class Gevice:
     self.notebook.set_scrollable (True)
     self.notebook.set_show_border (False)
     self.notebook.set_show_tabs (True)
-    #self.notebook.set_group_id(1)
     
     self.hpaned.add2 (self.notebook)
     # a negative value means that the position is unset.
@@ -195,13 +191,13 @@ class Gevice:
       ])
     
     self.actiongroup_window.add_radio_actions([
-      ('ssh', Gtk.STOCK_ADD, _('ssh'),None, _('Use ssh protocol'), 0),
+      ('ssh', None, _('ssh'),None, _('Use ssh protocol'), 0),
       ('telnet', Gtk.STOCK_ADD, _('telnet'),None, _('Use telnet protocol'), 1),
       ('local', Gtk.STOCK_ADD, _('local'),None, _('Open local terminal'), 2),
       ],0, self.on_action_radio)
       
     self.actiongroup_window.add_actions([
-      ('Connect', Gtk.STOCK_JUMP_TO, _('Connect'), None, _('Connect to'), self.on_action_connect),
+      ('Connect', Gtk.STOCK_NETWORK, _('Open terminal'), None, _('Open terminal'), self.on_action_connect),
       ])
     
     self.actiongroup_model.set_sensitive (False)
@@ -219,9 +215,11 @@ class Gevice:
   def main(self):
     Gtk.main()
   
-  def show_message (self,msg,type_msg,buttons):
-    #dialog = Gtk.MessageDialog(None,Gtk.DIALOG_MODAL,type_msg,buttons,msg)
-    dialog = Gtk.Dialog(config.PACKAGE,self.window_main,flags=0,buttons=(buttons))
+  def show_message (self,msg,type_msg,buttons,window):
+    if (window == None):
+      window = self.window_main
+      
+    dialog = Gtk.Dialog(config.PACKAGE,window,flags=0,buttons=(buttons))
     
     label = Gtk.Label(msg)
     content_area = dialog.get_content_area()
@@ -234,8 +232,6 @@ class Gevice:
     return result
   
   def close_page_of_notebook(self,widget,vpaned):
-    "close page of notebook"
-    
     page = self.notebook.page_num(vpaned)
     self.notebook.remove_page(page)
     
@@ -281,11 +277,12 @@ class Gevice:
     else:
       i = self.gmodel.get_iter_selected (self.gmodel.treeview)
       if i["iter"]:
-        # get data from device selected
+        # get data from device selected (devicename, IP)
         data = self.gmodel.get_data_of_device_from_model(self.gmodel.treeview)
         label.set_text(data[0])
         proto = self.get_protocol_selected()
 	
+	# get name of user selected (for ssh session)
 	model_user = self.combobox_user.get_model()
 	iter_user = self.combobox_user.get_active_iter()
 	user = model_user.get(iter_user,0)
@@ -296,7 +293,6 @@ class Gevice:
 	  hbox_term2,terminal2 = gvte.new_terminal (self)
 	  vpaned.add2 (hbox_term2)
 	  terminal2.fork_command_full (Vte.PtyFlags.DEFAULT, None, [proto,'-l',user[0],data[2]], [], GLib.SpawnFlags.SEARCH_PATH, None, None)
-	  #terminal2.fork_command (proto,['bash','-l',user,data[2]],[],config.DEFAULT_TMP)
         
     page = self.notebook.append_page(vpaned,hbox_label)
     self.notebook.set_tab_reorderable(vpaned,True)
@@ -311,12 +307,10 @@ class Gevice:
     
     hbox_image = Gtk.HBox(homogeneous=False,spacing=0)
     image = Gtk.Image()
-    #image.set_from_stock(id_stock,Gtk.ICON_SIZE_MENU)
     image.set_from_stock(id_stock,Gtk.IconSize.MENU)
     hbox_image.pack_start(image,True,False,False)
     
     button = Gtk.Button()
-    #button.set_relief('GTK_RELIEF_NONE')
     
     button.add(hbox_image)
     button.set_sensitive (sensitive)
@@ -534,12 +528,15 @@ class Gevice:
     gevice.connected_to_database = False
     
   def on_action_save (gevice,action,data):
-    gevice.gdbase = gevicedatabase.GeviceDatabase ()
-    gevice.gdbase.load_interface (gevice,"save")
-    gevice.gdbase.label_host.set_text (gevice.gpref.host)
-    gevice.gdbase.label_dbase.set_text (gevice.gpref.dbase)
-    gevice.gdbase.label_user_dbase.set_text (gevice.gpref.user_dbase)
-    gevice.gdbase.show_interface()
+    #print gevice.gdbase.cur
+    gevice.gdbase.save_data_to_database(gevice)
+    result = gevice.show_message (_("Model saved"),None,(Gtk.STOCK_OK, Gtk.ResponseType.OK),None)
+    #gevice.gdbase = gevicedatabase.GeviceDatabase ()
+    #gevice.gdbase.load_interface (gevice,"save")
+    #gevice.gdbase.label_host.set_text (gevice.gpref.host)
+    #gevice.gdbase.label_dbase.set_text (gevice.gpref.dbase)
+    #gevice.gdbase.label_user_dbase.set_text (gevice.gpref.user_dbase)
+    #gevice.gdbase.show_interface()
     
   def on_action_connect(self,action,data):
     flag = True
diff --git a/src/gevicedatabase.py b/src/gevicedatabase.py
index 9d01d9c..d3f737f 100644
--- a/src/gevicedatabase.py
+++ b/src/gevicedatabase.py
@@ -26,7 +26,7 @@ class GeviceDatabase:
             conn = psycopg2.connect("dbname=" + gevice.gpref.dbase + " user=" + gevice.gpref.user_dbase + " host=" + gevice.gpref.host + " password=" + passwd)
             return conn
         except:
-	    result = gevice.show_message (_("Unable to connect to the database"),None,(Gtk.STOCK_OK, Gtk.ResponseType.OK))
+	    result = gevice.show_message (_("Unable to connect to the database"),None,(Gtk.STOCK_OK, Gtk.ResponseType.OK),self.window_database)
             return False
 
 
@@ -36,9 +36,7 @@ class GeviceDatabase:
             rows = self.cur.fetchall()
             return rows
         except:
-	    #result = gevice.show_message (_("Unable to execute SQL: " + sql),None,(Gtk.STOCK_OK, Gtk.ResponseType.OK))
-	    result = gevice.show_message (_("Unable to execute SQL: "),None,(Gtk.STOCK_OK, Gtk.ResponseType.OK))
-	    print sql
+	    result = gevice.show_message (_("Unable to execute SQL: " + sql),None,(Gtk.STOCK_OK, Gtk.ResponseType.OK),None)
             return False
         
     def execute_sql_insert (self,gevice,sql):
@@ -46,7 +44,7 @@ class GeviceDatabase:
             self.cur.execute(sql)
             return True
         except:
-            result = gevice.show_message (_("Unable to execute SQL: " + sql),Gtk.MESSAGE_ERROR,Gtk.BUTTONS_OK)
+	    result = gevice.show_message (_("Unable to execute SQL: " + sql),None,(Gtk.STOCK_OK, Gtk.ResponseType.OK),None)
             return False
             
     def execute_sql_delete (self,gevice,sql):
@@ -54,7 +52,7 @@ class GeviceDatabase:
             self.cur.execute(sql)
             return True
         except:
-            result = gevice.show_message (_("Unable to execute SQL: " + sql),Gtk.MESSAGE_ERROR,Gtk.BUTTONS_OK)
+	    result = gevice.show_message (_("Unable to execute SQL: " + sql),None,(Gtk.STOCK_OK, Gtk.ResponseType.OK),None)
             return False
 
     def execute_sql_update (self,gevice,sql):
@@ -62,7 +60,7 @@ class GeviceDatabase:
             self.cur.execute(sql)
             return True
         except:
-            result = gevice.show_message (_("Unable to execute SQL: " + sql),Gtk.MESSAGE_ERROR,Gtk.BUTTONS_OK)
+	    result = gevice.show_message (_("Unable to execute SQL: " + sql),None,(Gtk.STOCK_OK, Gtk.ResponseType.OK),None)
             return False
 
     def load_interface (self,gevice,action="connect"):
@@ -132,11 +130,8 @@ class GeviceDatabase:
 	    gevice.connected_to_database = True
 	    self.cur = self.conn.cursor()
 
-	    self.save_data_to_database(gevice)
-	
+	    self.save_data_to_database(gevice)	
 	    self.close_window (self.window_database)
-	else:
-	    gevice.connected_to_database = False
 
     def show_interface (self):
     	self.window_database.show_all()
@@ -166,14 +161,11 @@ class GeviceDatabase:
                     self.process_row (serial,None,0,gevice)
                     token = serial
             
-            gevice.gmodel.treeview.expand_all()
-        
+            gevice.gmodel.treeview.expand_all()        
         
         gevice.actiongroup_model.set_sensitive(True)
         gevice.actiongroup_device.set_sensitive (True)
 
-
-
     def process_row (self,serial,iterp,id_type_link,gevice):
         sql = "select nom_disp,id_modelo,nom_tipo_disp || ' ' || nom_marca || ' ' || nom_modelo, "
         sql = sql + "ip_disp,serial,obs_disp,ubicacion,id_rack,ptas_disp "
diff --git a/src/gevicedevice.py b/src/gevicedevice.py
index 3f39425..09c59ba 100644
--- a/src/gevicedevice.py
+++ b/src/gevicedevice.py
@@ -111,8 +111,7 @@ class GeviceDevice:
         data = gevice.gmodel.get_data_of_device_from_model(gevice.gmodel.treeview)
 	
 	result = gevice.show_message (_("Do you want to remove: ") + data[0],
-	  None,
-	  (Gtk.STOCK_YES, Gtk.ResponseType.YES, Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
+	  None,(Gtk.STOCK_YES, Gtk.ResponseType.YES, Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL),None)
 
 	if result == Gtk.ResponseType.YES:
             i = gevice.gmodel.get_iter_selected (gevice.gmodel.treeview)
@@ -199,17 +198,17 @@ class GeviceDevice:
         
         if (not name.strip()):
             alldata = False
-            result = gevice.show_message (_("Enter name of device"),Gtk.MESSAGE_ERROR,Gtk.BUTTONS_OK)
+            result = gevice.show_message (_("Enter name of device"),Gtk.MESSAGE_ERROR,Gtk.BUTTONS_OK,None)
         elif (not serial.strip()):
             alldata = False
-            result = gevice.show_message (_("Enter serial number of device"),Gtk.MESSAGE_ERROR,Gtk.BUTTONS_OK)
+            result = gevice.show_message (_("Enter serial number of device"),Gtk.MESSAGE_ERROR,Gtk.BUTTONS_OK,None)
 
         gevice.gmodel.treestore.foreach(self.verify_serial,serial)
 
         if self.action == "add":
             if (self.exists_serial):
                 alldata = False
-                result = gevice.show_message (_("Serial number exist, view device: " + self.exists_serial_name),Gtk.MESSAGE_ERROR,Gtk.BUTTONS_OK)
+                result = gevice.show_message (_("Serial number exist, view device: " + self.exists_serial_name),Gtk.MESSAGE_ERROR,Gtk.BUTTONS_OK,None)
 
         if alldata:        
             iter_model = self.combo_model.get_active_iter()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]