~bdfhjk/clicompanion/version-parser-add

« back to all changes in this revision

Viewing changes to clicompanionlib/view.py

  • Committer: duanedesign
  • Date: 2011-03-18 15:46:30 UTC
  • Revision ID: duanedesign@gmail.com-20110318154630-h3419wkt7z3k3pff
drag and drop in command list

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
 
58
58
 
59
59
class MainWindow():
 
60
    liststore = gtk.ListStore(str, str, str)
60
61
 
61
62
    ## open file containing command list and put it in a variable
62
63
    def update(self, liststore):
69
70
            ## So, run self.setup() again.
70
71
            self.setup()
71
72
            ## Then, run me again.
72
 
            self.update(liststore)
 
73
            self.update(self.liststore)
73
74
 
74
75
        ## add bug data from .clicompanion --> bugdata --> to the liststore
75
76
        for line in bugdata.splitlines():
76
77
            l = line.split(':',2)
77
78
            commandplus = l[0], l[1]
78
79
            CMNDS.append(commandplus)
79
 
            liststore.append([l[0],l[1],l[2]])
 
80
            self.liststore.append([l[0],l[1],l[2]])
80
81
 
81
82
          
82
83
    #copy config file to user $HOME if does not exist
97
98
    
98
99
    
99
100
    #liststore in a scrolled window in an expander
100
 
    def expanded_cb(self, expander, params, notebook, treeview, liststore, search_box):
 
101
    def expanded_cb(self, expander, params, window, search_box):
101
102
        if expander.get_expanded():
102
103
 
103
104
            # Activate the search box when expanded
104
105
            search_box.set_sensitive(True)
105
106
        else:
106
107
            # De-activate the search box when not expanded
107
 
            search_box.set_sensitive(False)
 
108
            self.search_box.set_sensitive(False)
108
109
            expander.set_expanded(False)
109
110
            #expander.remove(expander.child)
110
111
            ##reset the size of the window to its original one
111
 
            self.window.resize(1, 1)
 
112
            window.resize(1, 1)
112
113
        return  
113
114
        
114
115
 
141
142
        
142
143
        ## Create UI widgets
143
144
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
144
 
        liststore = gtk.ListStore(str, str, str)
 
145
 
145
146
        treeview = gtk.TreeView()
146
147
        expander = gtk.Expander()
147
148
        scrolledwindow = gtk.ScrolledWindow()
163
164
        window.set_icon(icon)
164
165
        
165
166
        # get commands and put in liststore
166
 
        self.update(liststore) 
 
167
        self.update(self.liststore) 
167
168
        ## create the TreeViewColumns to display the data
168
169
        treeview.columns = [None]*3
169
170
        treeview.columns[0] = gtk.TreeViewColumn(_('Command'))
185
186
        
186
187
        ''' set treeview model and put treeview in the scrolled window
187
188
        and the scrolled window in the expander. '''
188
 
        treeview.set_model(liststore)
 
189
        treeview.set_model(self.liststore)
189
190
        scrolledwindow.add(treeview)
190
191
        expander.add(scrolledwindow)
191
192
        #self.window.show_all()
196
197
        actions = clicompanionlib.controller.Actions()
197
198
        ## instantiate 'File' and 'Help' Drop Down Menu [menus_buttons.py]
198
199
        bar = clicompanionlib.menus_buttons.FileMenu()
199
 
        menu_bar = bar.the_menu(actions, notebook, liststore)
 
200
        menu_bar = bar.the_menu(actions, notebook, self.liststore)
200
201
        
201
202
 
202
203
        ## get row of a selection
209
210
        ## double click to run a command    
210
211
        def treeview_clicked(widget, event):
211
212
            if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS:
212
 
                actions.run_command(self, notebook, liststore)
 
213
                actions.run_command(self, notebook, self.liststore)
213
214
 
214
215
        ## press enter to run a command                   
215
216
        def treeview_button(widget, event):
217
218
            #print keyname ##debug
218
219
            if event.type == gtk.gdk.KEY_PRESS:
219
220
                if keyname == 'RETURN':
220
 
                    actions.run_command(self, notebook, liststore)
 
221
                    actions.run_command(self, notebook, self.liststore)
221
222
                    
222
223
 
223
224
        selection = treeview.get_selection()
230
231
        #press enter to run command
231
232
        treeview.connect("key-press-event", treeview_button)
232
233
        
 
234
        ##drag and drop
 
235
        treeview.enable_model_drag_source(gtk.gdk.BUTTON1_MASK, TARGETS, gtk.gdk.ACTION_MOVE)
 
236
        treeview.enable_model_drag_dest(TARGETS, gtk.gdk.ACTION_MOVE)
 
237
        treeview.connect("drag_data_get", actions.drag_data_get_data)
 
238
        treeview.connect("drag_data_received", actions.drag_data_received_data)
233
239
        
234
240
        ## The search section
235
241
        search_label = gtk.Label(_("Search:"))
236
242
        search_label.set_alignment(xalign=-1, yalign=0)
237
243
        self.search_box = gtk.Entry()
238
 
        self.search_box.connect("changed", actions._filter_commands, liststore, treeview)
 
244
        self.search_box.connect("changed", actions._filter_commands, self.liststore, treeview)
239
245
        ## search box tooltip
240
246
        self.search_box.set_tooltip_text(_("Search your list of commands"))
241
247
        ## Set the search box sensitive OFF at program start, because
272
278
        notebook.append_page(gtk.Label(""), add_tab_button)
273
279
        
274
280
        ## buttons at bottom of main window [menus_buttons.py]
275
 
        button_box = bar.buttons(actions, 10, gtk.BUTTONBOX_END, notebook, liststore)
 
281
        button_box = bar.buttons(actions, 10, gtk.BUTTONBOX_END, notebook, self.liststore)
276
282
 
277
283
        ## vbox for search, notebook, buttonbar
278
284
        vbox = gtk.VBox()
285
291
        vbox.pack_start(button_box, False, False, 5)
286
292
        
287
293
        ## signals
288
 
        expander.connect('notify::expanded', self.expanded_cb, notebook, treeview, liststore, self.search_box)
 
294
        expander.connect('notify::expanded', self.expanded_cb, window, self.search_box)
289
295
        window.connect("delete_event", self.delete_event)
290
296
        add_tab_button.connect("clicked", tabs.add_tab, notebook)
291
297
        ## right click menu event capture
292
 
        treeview.connect ("button_press_event", bar.right_click, actions, treeview, notebook, liststore)
 
298
        treeview.connect ("button_press_event", bar.right_click, actions, treeview, notebook, self.liststore)
293
299
 
294
300
 
295
301
        #self.vte.grab_focus()