Comment 21 for bug 1680891

Revision history for this message
Stephen Boddy (stephen-j-boddy) wrote :

OK, yeah, I totally misunderstood :-)

I see the problem now, but fixing it will take a bit of a refactor. You are creating a model when you construct the menu window. You create another *separate* model when you construct the config window. The user edits the second model with the config window, and when finished, writes this directly to the config file. The first model never gets updated. I see two possibilities:
1) Once the config has been written, trigger the menu window to re-read config. This is probably quicker and easier to do.
2) Another approach is to change all code to use a single shared model. This seems like it will be a bit more involved as my quick 60-second try failed elsewhere in the code. It would make the "Cancel" button in the edit window pointless however, which you might prefer to keep. Changes in edit would propagate immediately.

Small side note. Avoid tabs for indentation. Standard coding style for Terminator is 4 spaces per indentation level. Most editors can translate tabs to spaces for you, and handle indentation automatically.

Here's the changes I made to try and use a shared store, but it fails in the on_new method with an exception. And I have to stop now, so good luck ;-)

--- /home/steve/Downloads/ssh-menu-terminator-master/ssh_menu.py 2017-04-25 11:42:45.000000000 +0200
+++ ssh_menu.py 2017-04-26 08:26:15.459785141 +0200
@@ -26,6 +26,7 @@
     capabilities = ['terminal_menu']
     cmd_list = []
     conf_file = os.path.join(get_config_dir(),"ssh_menu")
+ store = Gtk.TreeStore(str,str,str)

     def __init__( self):
       config = Config()
@@ -130,15 +131,15 @@
     allgroups.append(self.cmd_list[elem]['group'])
       groups = list(set(allgroups))

- store = Gtk.TreeStore(str,str,str)
+ #store = Gtk.TreeStore(str,str,str)

       for group in groups:
- rabbit = store.append(None, [group,"blah","blah"])
- subgroup = [d for d in self.cmd_list if d['group'] == group]
- for command in subgroup:
- store.append(rabbit,[command['name'], command['command'], command['group']])
+ rabbit = self.store.append(None, [group,"blah","blah"])
+ subgroup = [d for d in self.cmd_list if d['group'] == group]
+ for command in subgroup:
+ self.store.append(rabbit,[command['name'], command['command'], command['group']])

- treeview = Gtk.TreeView(store)
+ treeview = Gtk.TreeView(self.store)
       selection = treeview.get_selection()
       selection.set_mode(Gtk.SelectionMode.SINGLE)

@@ -189,12 +190,12 @@
                         Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT
                       )
                     )
- store = Gtk.ListStore(str, str, str)
+ #store = Gtk.ListStore(str, str, str)

- for command in self.cmd_list:
- store.append([command['name'], command['command'], command['group']])
+ #for command in self.cmd_list:
+ # store.append([command['name'], command['command'], command['group']])

- treeview = Gtk.TreeView(store)
+ treeview = Gtk.TreeView(self.store)
       #treeview.connect("cursor-changed", self.on_cursor_changed, ui)
       selection = treeview.get_selection()
       selection.set_mode(Gtk.SelectionMode.SINGLE)
@@ -267,10 +268,10 @@
       res = window.run()
       if res == Gtk.ResponseType.ACCEPT:
         #we save the config
- iter = store.get_iter_first()
+ iter = self.store.get_iter_first()
         self.cmd_list = []
         while iter:
- (name, command, group) = store.get(iter,
+ (name, command, group) = self.store.get(iter,
                                               CC_COL_NAME,
                                               CC_COL_COMMAND,
                                               CC_COL_GROUP)
@@ -279,7 +280,7 @@
                             'command' : command,
                             'group' : group}
                               )
- iter = store.iter_next(iter)
+ iter = self.store.iter_next(iter)
         self._save_config()

       window.destroy()