tidy up a little in preparation for release

This commit is contained in:
Chris Jones 2008-07-03 23:48:29 +01:00
parent 677046f1e0
commit 88eb16ce1e
3 changed files with 53 additions and 75 deletions

View File

@ -132,7 +132,6 @@ See the following bug report for more details:
https://bugs.launchpad.net/bugs/238070''')) https://bugs.launchpad.net/bugs/238070'''))
error.run () error.run ()
error.destroy () error.destroy ()
except: except:
pass pass

View File

@ -80,7 +80,6 @@ class TerminatorNotebookTabLabel(gtk.HBox):
def get_title(self): def get_title(self):
return self._label.get_text() return self._label.get_text()
class Terminator: class Terminator:
def __init__ (self, profile = None, command = None, fullscreen = False, maximise = False, borderless = False): def __init__ (self, profile = None, command = None, fullscreen = False, maximise = False, borderless = False):
self.profile = profile self.profile = profile
@ -513,9 +512,6 @@ class Terminator:
index = self.term_list.index(sibling) index = self.term_list.index(sibling)
self.term_list.insert (index + 1, terminal) self.term_list.insert (index + 1, terminal)
return (True) return (True)
return terminal
def splitaxis (self, widget, vertical=True): def splitaxis (self, widget, vertical=True):
""" Split the provided widget on the horizontal or vertical axis. """ """ Split the provided widget on the horizontal or vertical axis. """
@ -580,7 +576,6 @@ class Terminator:
grandparent.set_tab_label_packing(sibling, True, True, gtk.PACK_START) grandparent.set_tab_label_packing(sibling, True, True, gtk.PACK_START)
grandparent.set_tab_reorderable(sibling, True) grandparent.set_tab_reorderable(sibling, True)
grandparent.set_current_page(page) grandparent.set_current_page(page)
else: else:
grandparent.remove (parent) grandparent.remove (parent)
sibling.reparent (grandparent) sibling.reparent (grandparent)
@ -639,7 +634,6 @@ class Terminator:
return True return True
return False return False
def go_next (self, term): def go_next (self, term):
current = self.term_list.index (term) current = self.term_list.index (term)
next = None next = None
@ -657,13 +651,11 @@ class Terminator:
else: else:
next = current + 1 next = current + 1
nextterm = self.term_list[next] nextterm = self.term_list[next]
##we need to set the current page of each notebook ##we need to set the current page of each notebook
self._set_current_notebook_page_recursive(nextterm) self._set_current_notebook_page_recursive(nextterm)
nextterm._vte.grab_focus () nextterm._vte.grab_focus ()
def go_prev (self, term): def go_prev (self, term):
current = self.term_list.index (term) current = self.term_list.index (term)
@ -688,8 +680,7 @@ class Terminator:
##we need to set the current page of each notebook ##we need to set the current page of each notebook
self._set_current_notebook_page_recursive(previousterm) self._set_current_notebook_page_recursive(previousterm)
previousterm._vte.grab_focus () previousterm._vte.grab_focus ()
def _set_current_notebook_page_recursive(self, widget): def _set_current_notebook_page_recursive(self, widget):
page = self.get_first_notebook_page(widget) page = self.get_first_notebook_page(widget)
while page: while page:
@ -697,7 +688,6 @@ class Terminator:
page_num = page[0].page_num(page[1]) page_num = page[0].page_num(page[1])
page[0].set_current_page(page_num) page[0].set_current_page(page_num)
page = self.get_first_notebook_page(page[0]) page = self.get_first_notebook_page(page[0])
def resizeterm (self, widget, keyname): def resizeterm (self, widget, keyname):
vertical = False vertical = False

View File

@ -40,54 +40,10 @@ except:
error.run() error.run()
sys.exit (1) sys.exit (1)
TARGET_TYPE_VTE = 8
# Sort out cwd detection code, if available
pid_get_cwd = lambda pid: None
if platform.system() == 'FreeBSD':
try:
from terminatorlib import freebsd
pid_get_cwd = lambda pid: freebsd.get_process_cwd(pid)
dbg ('Using FreeBSD pid_get_cwd')
except:
dbg ('FreeBSD version too old for pid_get_cwd')
pass
elif platform.system() == 'Linux':
dbg ('Using Linux pid_get_cwd')
pid_get_cwd = lambda pid: os.path.realpath ('/proc/%s/cwd' % pid)
else:
dbg ('Unable to set a pid_get_cwd, unknown system: %s'%platform.system)
# import a library for viewing URLs
try:
# gnome.url_show() is really useful
dbg ('url_show: importing gnome module')
import gnome
url_show = gnome.url_show
except:
# webbrowser.open() is not really useful, but will do as a fallback
dbg ('url_show: gnome module failed, using webbrowser')
import webbrowser
url_show = webbrowser.open
dbg ('url_show: is set to: %s'%url_show)
def openurl (url):
dbg ('openurl: viewing %s'%url)
try:
if subprocess.call(["xdg-open", url]) != 0:
dbg ('openurl: xdg-open failed')
raise
except:
try:
dbg ('openurl: calling url_show')
url_show (url)
except:
dbg ('openurl: url_show failed. No URL for you')
pass
class TerminatorTerm (gtk.VBox): class TerminatorTerm (gtk.VBox):
matches = {} matches = {}
TARGET_TYPE_VTE = 8
def __init__ (self, terminator, profile = None, command = None, cwd = None): def __init__ (self, terminator, profile = None, command = None, cwd = None):
gtk.VBox.__init__ (self) gtk.VBox.__init__ (self)
@ -95,6 +51,34 @@ class TerminatorTerm (gtk.VBox):
self.conf = terminator.conf self.conf = terminator.conf
self.command = command self.command = command
# Sort out cwd detection code, if available
self.pid_get_cwd = lambda pid: None
if platform.system() == 'FreeBSD':
try:
from terminatorlib import freebsd
self.pid_get_cwd = lambda pid: freebsd.get_process_cwd(pid)
dbg ('Using FreeBSD self.pid_get_cwd')
except:
dbg ('FreeBSD version too old for self.pid_get_cwd')
pass
elif platform.system() == 'Linux':
dbg ('Using Linux self.pid_get_cwd')
self.pid_get_cwd = lambda pid: os.path.realpath ('/proc/%s/cwd' % pid)
else:
dbg ('Unable to set a self.pid_get_cwd, unknown system: %s'%platform.system)
# import a library for viewing URLs
try:
# gnome.url_show() is really useful
dbg ('url_show: importing gnome module')
import gnome
url_show = gnome.url_show
except:
# webbrowser.open() is not really useful, but will do as a fallback
dbg ('url_show: gnome module failed, using webbrowser')
import webbrowser
url_show = webbrowser.open
self.cwd = cwd or os.getcwd(); self.cwd = cwd or os.getcwd();
if not os.path.exists(self.cwd) or not os.path.isdir(self.cwd): if not os.path.exists(self.cwd) or not os.path.isdir(self.cwd):
self.cwd = pwd.getpwuid(os.getuid ())[5] self.cwd = pwd.getpwuid(os.getuid ())[5]
@ -139,8 +123,8 @@ class TerminatorTerm (gtk.VBox):
self._vte.connect ("popup-menu", self.on_vte_popup_menu) self._vte.connect ("popup-menu", self.on_vte_popup_menu)
"""drag and drop""" """drag and drop"""
srcvtetargets = [ ( "vte", gtk.TARGET_SAME_APP, TARGET_TYPE_VTE ) ] srcvtetargets = [ ( "vte", gtk.TARGET_SAME_APP, self.TARGET_TYPE_VTE ) ]
dsttargets = [ ( "vte", gtk.TARGET_SAME_APP, TARGET_TYPE_VTE ), ('text/plain', 0, 0) , ("STRING", 0, 0), ("COMPOUND_TEXT", 0, 0)] dsttargets = [ ( "vte", gtk.TARGET_SAME_APP, self.TARGET_TYPE_VTE ), ('text/plain', 0, 0) , ("STRING", 0, 0), ("COMPOUND_TEXT", 0, 0)]
self._vte.drag_source_set( gtk.gdk.CONTROL_MASK | gtk.gdk.BUTTON3_MASK, srcvtetargets, gtk.gdk.ACTION_MOVE) self._vte.drag_source_set( gtk.gdk.CONTROL_MASK | gtk.gdk.BUTTON3_MASK, srcvtetargets, gtk.gdk.ACTION_MOVE)
self._titlebox.drag_source_set( gtk.gdk.BUTTON1_MASK, srcvtetargets, gtk.gdk.ACTION_MOVE) self._titlebox.drag_source_set( gtk.gdk.BUTTON1_MASK, srcvtetargets, gtk.gdk.ACTION_MOVE)
#self._vte.drag_dest_set(gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT |gtk.DEST_DEFAULT_DROP ,dsttargets, gtk.gdk.ACTION_MOVE) #self._vte.drag_dest_set(gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT |gtk.DEST_DEFAULT_DROP ,dsttargets, gtk.gdk.ACTION_MOVE)
@ -161,8 +145,7 @@ class TerminatorTerm (gtk.VBox):
self._vte.connect ("grab-focus", self.on_vte_focus) self._vte.connect ("grab-focus", self.on_vte_focus)
self._vte.connect ("focus-out-event", self.on_vte_focus_out) self._vte.connect ("focus-out-event", self.on_vte_focus_out)
self._vte.connect ("focus-in-event", self.on_vte_focus_in) self._vte.connect ("focus-in-event", self.on_vte_focus_in)
exit_action = self.conf.exit_action exit_action = self.conf.exit_action
if exit_action == "restart": if exit_action == "restart":
self._vte.connect ("child-exited", self.spawn_child) self._vte.connect ("child-exited", self.spawn_child)
@ -184,7 +167,21 @@ class TerminatorTerm (gtk.VBox):
dbg ('SEGBUG: Setting COLORTERM') dbg ('SEGBUG: Setting COLORTERM')
os.putenv ('COLORTERM', 'gnome-terminal') os.putenv ('COLORTERM', 'gnome-terminal')
dbg ('SEGBUG: TerminatorTerm __init__ complete') dbg ('SEGBUG: TerminatorTerm __init__ complete')
def openurl (url):
dbg ('openurl: viewing %s'%url)
try:
if subprocess.call(["xdg-open", url]) != 0:
dbg ('openurl: xdg-open failed')
raise
except:
try:
dbg ('openurl: calling url_show')
url_show (url)
except:
dbg ('openurl: url_show failed. No URL for you')
pass
def on_drag_begin(self, widget, drag_context, data): def on_drag_begin(self, widget, drag_context, data):
dbg ('Drag begins') dbg ('Drag begins')
widget.drag_source_set_icon_pixbuf(self.terminator.icon_theme.load_icon (APP_NAME, 48, 0)) widget.drag_source_set_icon_pixbuf(self.terminator.icon_theme.load_icon (APP_NAME, 48, 0))
@ -192,8 +189,7 @@ class TerminatorTerm (gtk.VBox):
def on_drag_data_get(self,widget, drag_context, selection_data, info, time, data): def on_drag_data_get(self,widget, drag_context, selection_data, info, time, data):
dbg ("Drag data get") dbg ("Drag data get")
selection_data.set("vte",info, str(data.terminator.term_list.index (self))) selection_data.set("vte",info, str(data.terminator.term_list.index (self)))
def on_drag_motion(self, widget, drag_context, x, y, time, data): def on_drag_motion(self, widget, drag_context, x, y, time, data):
dbg ("Drag Motion on ") dbg ("Drag Motion on ")
""" """
@ -216,7 +212,6 @@ text/plain
#on self #on self
return return
alloc = widget.allocation alloc = widget.allocation
rect = gtk.gdk.Rectangle(0, 0, alloc.width, alloc.height) rect = gtk.gdk.Rectangle(0, 0, alloc.width, alloc.height)
widget.window.invalidate_rect(rect, True) widget.window.invalidate_rect(rect, True)
@ -227,8 +222,7 @@ text/plain
color = self._vte.get_style ().text[gtk.STATE_NORMAL] color = self._vte.get_style ().text[gtk.STATE_NORMAL]
else: else:
color = gtk.gdk.color_parse (self.conf.foreground_color) color = gtk.gdk.color_parse (self.conf.foreground_color)
context.set_source_rgba(color.red, color.green, color.blue, 0.5) context.set_source_rgba(color.red, color.green, color.blue, 0.5)
pos = self.get_location(widget, x, y) pos = self.get_location(widget, x, y)
@ -258,8 +252,7 @@ text/plain
context.line_to(i[0],i[1]) context.line_to(i[0],i[1])
context.fill() context.fill()
def on_drag_drop(self, widget, drag_context, x, y, time): def on_drag_drop(self, widget, drag_context, x, y, time):
parent = widget.get_parent() parent = widget.get_parent()
dbg ('Drag drop on %s'%parent) dbg ('Drag drop on %s'%parent)
@ -296,7 +289,6 @@ text/plain
data.terminator.add(self, widgetsrc,pos) data.terminator.add(self, widgetsrc,pos)
return return
def get_location(self, vte, x, y): def get_location(self, vte, x, y):
pos = "" pos = ""
#get the diagonales function for the receiving widget #get the diagonales function for the receiving widget
@ -304,7 +296,7 @@ text/plain
coef2 = -float(vte.allocation.height)/float(vte.allocation.width) coef2 = -float(vte.allocation.height)/float(vte.allocation.width)
b1 = 0 b1 = 0
b2 = vte.allocation.height b2 = vte.allocation.height
#determine position in rectangle #determine position in rectangle
""" """
-------- --------
|\ /| |\ /|
@ -325,7 +317,6 @@ text/plain
pos = "bottom" pos = "bottom"
return pos return pos
def add_matches (self, lboundry="[[:<:]]", rboundry="[[:>:]]"): def add_matches (self, lboundry="[[:<:]]", rboundry="[[:>:]]"):
userchars = "-A-Za-z0-9" userchars = "-A-Za-z0-9"
passchars = "-A-Za-z0-9,?;.:/!%$^*&~\"#'" passchars = "-A-Za-z0-9,?;.:/!%$^*&~\"#'"
@ -424,7 +415,7 @@ text/plain
""" Return the current working directory of the subprocess. """ Return the current working directory of the subprocess.
This function requires OS specific behaviours This function requires OS specific behaviours
""" """
cwd = pid_get_cwd (self._pid) cwd = self.pid_get_cwd (self._pid)
dbg ('get_cwd found: %s'%cwd) dbg ('get_cwd found: %s'%cwd)
return (cwd) return (cwd)
@ -597,12 +588,10 @@ text/plain
else: else:
widget.show () widget.show ()
def paste_clipboard(self): def paste_clipboard(self):
self._vte.paste_clipboard() self._vte.paste_clipboard()
self._vte.grab_focus() self._vte.grab_focus()
#keybindings for the individual splited terminals (affects only the #keybindings for the individual splited terminals (affects only the
#the selected terminal) #the selected terminal)
def on_vte_key_press (self, term, event): def on_vte_key_press (self, term, event):