323
323
## instantiate tabs
324
324
tabs = clicompanionlib.tabs.Tabs()
325
325
## instantiate controller.Actions, where all the button actions are
326
actions = clicompanionlib.controller.Actions()
326
self.actions = clicompanionlib.controller.Actions()
327
327
## instantiate 'File' and 'Help' Drop Down Menu [menus_buttons.py]
328
328
bar = clicompanionlib.menus_buttons.FileMenu()
329
menu_bar = bar.the_menu(actions, self.notebook, self.liststore)
329
menu_bar = bar.the_menu(self.actions, self.notebook, self.liststore)
332
332
## get row of a selection
333
333
def mark_selected(self, treeselection):
335
(model, pathlist)=treeselection.get_selected_rows()
335
(model, pathlist) = treeselection.get_selected_rows()
339
339
## double click to run a command
340
340
def treeview_clicked(widget, event):
341
341
if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS:
342
actions.run_command(self, self.notebook, self.liststore)
342
self.actions.run_command(self, self.notebook, self.liststore)
344
344
## press enter to run a command
345
345
def treeview_button(widget, event):
423
423
self.window.connect("key-press-event", self.key_clicked)
424
424
add_tab_button.connect("clicked", tabs.add_tab, self.notebook)
425
425
## right click menu event capture
426
self.treeview.connect ("button_press_event", bar.right_click, actions, self.treeview, self.notebook, self.liststore)
426
self.treeview.connect ("button_press_event", bar.right_click, self.actions, self.treeview, self.notebook, self.liststore)
428
# Allow enable drag and drop of rows including row move
429
self.treeview.enable_model_drag_source( gtk.gdk.BUTTON1_MASK,
431
gtk.gdk.ACTION_DEFAULT |
433
self.treeview.enable_model_drag_dest(TARGETS,
434
gtk.gdk.ACTION_DEFAULT)
436
self.treeview.connect ("drag_data_get", self.drag_data_get_event)
437
self.treeview.connect ("drag_data_received", self.drag_data_received_event)
429
440
#self.vte.grab_focus()
430
441
self.window.show_all()
444
def drag_data_get_event(self, treeview, context, selection, target_id,
449
treeselection = treeview.get_selection()
450
model, iter = treeselection.get_selected()
451
data = model.get(iter, 0, 1, 2)
452
selection.set(selection.target, 8, '\t'.join(data))
454
def drag_data_received_event(self, treeview, context, x, y, selection, info,
457
Executed when dropping.
460
model = treeview.get_model()
461
for data in selection.data.split('\n'):
462
# if we got an empty line skip it
463
if not data.replace('\r',''): continue
464
# format the incoming string
465
orig = data.replace('\r','').split('\t',2)
466
orig = tuple([ fld.strip() for fld in orig ])
467
# fill the empty fields
468
if len(orig) < 3: orig = orig + ('',)*(3-len(orig))
469
# if the element already exists delete it (dragged from clicompanion)
470
olditer = self.find_iter_by_tuple(orig, model)
471
if olditer: del model[olditer]
473
drop_info = treeview.get_dest_row_at_pos(x, y)
475
path, position = drop_info
476
iter = model.get_iter(path)
477
dest = tuple(model.get(iter, 0, 1, 2))
478
if (position == gtk.TREE_VIEW_DROP_BEFORE
479
or position == gtk.TREE_VIEW_DROP_INTO_OR_BEFORE):
480
model.insert_before(iter, orig)
481
self.drag_cmnd(orig, dest, before=True)
483
model.insert_after(iter, orig)
484
self.drag_cmnd(orig, dest, before=False)
487
iter = model[-1].iter
488
model.insert_after(iter, orig)
490
model.insert(0, orig)
492
dest = tuple(model.get(iter, 0, 1, 2))
493
self.drag_cmnd(orig, dest, before=False)
494
if context.action == gtk.gdk.ACTION_MOVE:
495
context.finish(True, True, etime)
496
self.actions.save_cmnds()
498
def find_iter_by_tuple(self, data, model):
500
if tuple(model.get(row.iter, 0, 1, 2)) == data:
504
def drag_cmnd(self, orig, dest, before=True):
506
Sync the CMNDS array with the drag and drop of the treeview.
517
## both from clicompanion
518
if i != None and j != None:
521
CMNDS.insert(j-1, cmnd)
523
CMNDS.insert(j, cmnd)
525
CMNDS.insert(j, cmnd)
527
CMNDS.insert(j+1, cmnd)
532
CMNDS.insert(j, cmnd)
534
CMNDS.insert(j+1, cmnd)