beginning with drag and drop

This commit is contained in:
Emmanuel Bretelle 2008-02-24 20:42:08 +00:00
parent 5a12e350af
commit 0da21aa1d8
2 changed files with 159 additions and 5 deletions

2
TODO
View File

@ -1,2 +1,4 @@
* Edit doc/terminatorrc.5 manpage to contain the information about the options
* Write a Tab feature for terminator
* Drag and Drop terms

View File

@ -157,12 +157,27 @@ class TerminatorTerm:
packfunc (self._vte)
packfunc (self._scrollbar, False)
self._vte.connect ("key-press-event", self.on_vte_key_press)
self._vte.connect ("button-press-event", self.on_vte_button_press)
self._vte.connect ("popup-menu", self.on_vte_popup_menu)
"""drag and drop"""
target = [ ( "vte", 0, 81 ) ]
self._vte.drag_source_set( gtk.gdk.CONTROL_MASK | gtk.gdk.BUTTON3_MASK, target, gtk.gdk.ACTION_MOVE)
self._vte.drag_dest_set(gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT |gtk.DEST_DEFAULT_DROP ,target, gtk.gdk.ACTION_MOVE)
self._vte.connect("drag-begin", self.on_drag_begin)
self._vte.connect("drag-data-get", self.on_drag_data_get, self)
self._vte.connect("drag-end", self.on_drag_end)
self._vte.connect("drag-data-delete", self.on_drag_data_delete)
self._vte.connect("drag-motion", self.on_drag_motion)
self._vte.connect("drag-drop", self.on_drag_drop)
self._vte.connect("drag-data-received", self.on_drag_data_received, self)
# self._vte.connect ("window-title-changed", self.on_vte_title_change)
exit_action = self.gconf_client.get_string (self.profile + "/exit_action")
if not exit_action:
if self.defaults['child_restart']:
@ -171,7 +186,11 @@ class TerminatorTerm:
exit_action = "close"
if exit_action == "restart":
self._vte.connect ("child-exited", self.spawn_child)
if exit_action == "close":
#gnome-terminal Bug: http://bugzilla.gnome.org/show_bug.cgi?id=518184
#/apps/gnome-terminal/profiles/<profile name>/exit_action might be
#set to "left" instead of close
# LP#194771
if exit_action in ("close", "left"):
self._vte.connect ("child-exited", lambda close_term: self.terminator.closeterm (self))
self._vte.add_events (gtk.gdk.ENTER_NOTIFY_MASK)
@ -186,6 +205,140 @@ class TerminatorTerm:
self.spawn_child ()
def on_drag_begin(self,widget, drag_context):
#parent is hbox
print "Drag begin on ",
parent = widget.get_parent()
print parent
def on_drag_data_get(self,widget, drag_context, selection_data, info, time, data):
print "Drag data get"
selection_data.set("vte",81, str(data.terminator.term_list.index (self)))
def on_drag_data_delete(self, widget, drag_context):
print "Drag data delete"
def on_drag_end(self, widget, drag_context):
print "Drag end"
def on_drag_motion(self, widget, drag_context, x, y, time):
return
print "Drag Motion on ",
parent = widget.get_parent()
print "%dx%d -> %dx%d" % (parent.allocation.width, parent.allocation.height , x, y)
coef1 = float(parent.allocation.height)/float(parent.allocation.width)
coef2 = -float(parent.allocation.height)/float(parent.allocation.width)
b1 = 0
b2 = parent.allocation.height
print "%f %f %d %d" %(coef1, coef2, b1,b2)
if (x*coef1 + b1 > y ) and (x*coef2 + b2 < y ):
print "right"
if (x*coef1 + b1 > y ) and (x*coef2 + b2 > y ):
print "top"
if (x*coef1 + b1 < y ) and (x*coef2 + b2 > y ):
print "left"
if (x*coef1 + b1 < y ) and (x*coef2 + b2 < y ):
print "bottom"
def on_drag_drop(self, widget, drag_context, x, y, time):
print "Drag Drop on",
parent = widget.get_parent()
print parent,
def on_drag_data_received(self, widget, drag_context, x, y, selection_data, info, time, data):
print "Drag Data Received on "
widgetsrc = data.terminator.term_list[int(selection_data.data)]
srchbox = widgetsrc.get_box()
dsthbox = widget.get_parent()
coef1 = float(widget.allocation.height)/float(widget.allocation.width)
coef2 = -float(widget.allocation.height)/float(widget.allocation.width)
b1 = 0
b2 = dsthbox.allocation.height
if (x*coef1 + b1 > y ) and (x*coef2 + b2 < y ):
pos = "right"
if (x*coef1 + b1 > y ) and (x*coef2 + b2 > y ):
pos = "top"
if (x*coef1 + b1 < y ) and (x*coef2 + b2 > y ):
pos = "left"
if (x*coef1 + b1 < y ) and (x*coef2 + b2 < y ):
pos = "bottom"
if dsthbox == srchbox:
print "on itself"
return
dstpaned = dsthbox.get_parent()
srcpaned = srchbox.get_parent()
if isinstance(dstpaned, gtk.Window) and isinstance(srcpaned, gtk.Window):
print "Only one terminal"
return
"""remove src pane"""
if srcpaned.get_child1() == srchbox:
srcsibling = srcpaned.get_child2()
else:
srcsibling = srcpaned.get_child1()
srcgdparent = srcpaned.get_parent()
if isinstance (srcgdparent, gtk.Window):
print "SRC = window"
srcpaned.remove(srchbox)
srcpaned.remove(srcsibling)
srcgdparent.remove(srcpaned)
srcpaned.destroy()
srcgdparent.add(srcsibling)
srcsibling.reparent(srcgdparent)
if isinstance (srcgdparent, gtk.Paned):
print "SRC = paned"
srcpaned.remove(srchbox)
srcgdparent.remove(srcpaned)
srcsibling.reparent(srcgdparent)
srcpaned.destroy()
dstpaned = dsthbox.get_parent()
if isinstance (dstpaned, gtk.Window):
print "DST = window"
# We have just one term
pane = (pos in ("top", "bottom")) and gtk.VPaned() or gtk.HPaned()
dsthbox.reparent (pane)
#srchbox.reparent(pane)
pane.pack1 (dsthbox, True, True)
pane.pack2 (srchbox, True, True)
dstpaned.add(pane)
position = (pos in ("top", "bottom")) and dstpaned.allocation.height or dstpaned.allocation.width
if isinstance (dstpaned, gtk.Paned):
print "DST = paned"
pane = (pos in ("top", "bottom")) and gtk.VPaned() or gtk.HPaned()
position = (pos in ("top", "bottom")) and dstpaned.allocation.height or dstpaned.allocation.width
print "%s %d" % (pos, position)
if (dsthbox == dstpaned.get_child1 ()):
dsthbox.reparent (pane)
dstpaned.pack1 (pane, True, True)
else:
dsthbox.reparent (pane)
dstpaned.pack2 (pane, True, True)
pane.pack1 (dsthbox, True, True)
pane.pack2 (srchbox, True, True)
pane.show_all()
pane.set_position (position / 2)
def spawn_child (self, event=None):
update_records = self.gconf_client.get_bool (self.profile + "/update_records") or True
login = self.gconf_client.get_bool (self.profile + "/login_shell") or False
@ -345,9 +498,8 @@ class TerminatorTerm:
if event.button == 1:
self._vte.grab_focus ()
return False
# Right mouse button should display a context menu
if event.button == 3:
# Right mouse button should display a context menu if ctrl not pressed
if event.button == 3 and event.state & gtk.gdk.CONTROL_MASK == 0:
self.do_popup (event)
return True