Create an EditableLabel class

* make TerminatorNotebookTabLabel use it
 * reuse it in TerminatorTermTitle
This commit is contained in:
Emmanuel Bretelle 2009-08-14 20:15:32 +02:00
parent 2ac04e20be
commit 51ff0bcb41
2 changed files with 11 additions and 57 deletions

View File

@ -23,7 +23,6 @@ pygtk.require ("2.0")
import gobject, gtk, pango import gobject, gtk, pango
from terminatorlib.version import APP_NAME, APP_VERSION from terminatorlib.version import APP_NAME, APP_VERSION
from terminatorlib import config from terminatorlib import config
from config import dbg, err, debug from config import dbg, err, debug
@ -32,6 +31,8 @@ from terminatorlib.terminatorterm import TerminatorTerm
from terminatorlib.prefs_profile import ProfileEditor from terminatorlib.prefs_profile import ProfileEditor
from terminatorlib import translation from terminatorlib import translation
from terminatorlib.terminatoreditablelabel import TerminatorEditableLabel
try: try:
import deskbar.core.keybinder as bindkey import deskbar.core.keybinder as bindkey
except: except:
@ -72,32 +73,24 @@ class TerminatorWindowTitle:
class TerminatorNotebookTabLabel(gtk.HBox): class TerminatorNotebookTabLabel(gtk.HBox):
_terminator = None _terminator = None
_notebook = None _notebook = None
_label = None
_icon = None _icon = None
_label = None
_button = None _button = None
_ebox = None
_autotitle = None
custom = None
def __init__(self, title, notebook, terminator): def __init__(self, title, notebook, terminator):
gtk.HBox.__init__(self, False) gtk.HBox.__init__(self, False)
self._notebook = notebook self._notebook = notebook
self._terminator = terminator self._terminator = terminator
self.custom = False
self._label = gtk.Label(title) self._label = TerminatorEditableLabel(title)
self.update_angle() self.update_angle()
self._ebox = gtk.EventBox () self.pack_start(self._label, True, True)
self._ebox.set_visible_window (False)
self._ebox.add (self._label)
self.pack_start(self._ebox, True, True)
self._icon = gtk.Image() self._icon = gtk.Image()
self._icon.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) self._icon.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
self.update_closebut() self.update_closebut()
self._ebox.connect ("button-press-event", self.on_click_title)
self.show_all() self.show_all()
@ -154,9 +147,7 @@ class TerminatorNotebookTabLabel(gtk.HBox):
break break
def set_title(self, title, force=False): def set_title(self, title, force=False):
self._autotitle = title self._label.set_text(title, force)
if not self.custom or force:
self._label.set_text(title)
def get_title(self): def get_title(self):
return self._label.get_text() return self._label.get_text()
@ -167,43 +158,6 @@ class TerminatorNotebookTabLabel(gtk.HBox):
def width_request(self): def width_request(self):
return self.size_request()[0] return self.size_request()[0]
def on_click_title(self, widget, event):
if event.type == gtk.gdk._2BUTTON_PRESS and self._ebox in self.get_children ():
self.remove (self._ebox)
self._entry = gtk.Entry ()
self._entry.set_text (self._label.get_text ())
self._entry.show ()
self.pack_start (self._entry)
self.reorder_child (self._entry, 0)
self._notebook.connect ("switch-page", self.entry_to_label)
self._entry.connect ("activate", self.on_entry_activated)
self._entry.connect ("key-press-event", self.on_entry_keypress)
self._entry.grab_focus ()
def entry_to_label (self, widget, page, page_num):
if (self._entry):
self.remove (self._entry)
self.add (self._ebox)
self._entry = None
self.reorder_child (self._ebox, 0)
self._ebox.show_all ()
def on_entry_activated (self, widget):
entry = self._entry.get_text ()
label = self._label.get_text ()
if entry == '':
self.custom = False
self.set_title (self._autotitle)
elif entry != label:
self.custom = True
self.set_title (self._entry.get_text (), True)
self.entry_to_label (None, None, None)
def on_entry_keypress (self, widget, event):
key = gtk.gdk.keyval_name (event.keyval)
if key == 'Escape':
self.entry_to_label (None, None, None)
class Terminator: class Terminator:
options = None options = None

View File

@ -30,7 +30,7 @@ from terminatorlib.config import dbg, err, debug
#import encoding list #import encoding list
from terminatorlib.encoding import TerminatorEncoding from terminatorlib.encoding import TerminatorEncoding
from terminatorlib.terminatoreditablelabel import TerminatorEditableLabel
# import translation support # import translation support
from terminatorlib import translation from terminatorlib import translation
@ -62,7 +62,7 @@ class TerminatorTermTitle (gtk.EventBox):
def __init__ (self, terminal, terminator, configwanted = False): def __init__ (self, terminal, terminator, configwanted = False):
gtk.EventBox.__init__ (self) gtk.EventBox.__init__ (self)
self._title = gtk.Label () self._title = TerminatorEditableLabel()
self._group = gtk.Label () self._group = gtk.Label ()
self._separator = gtk.VSeparator () self._separator = gtk.VSeparator ()
self._ebox = gtk.EventBox () self._ebox = gtk.EventBox ()
@ -92,12 +92,12 @@ class TerminatorTermTitle (gtk.EventBox):
self._hbox.pack_start (self._title, True, True) self._hbox.pack_start (self._title, True, True)
self.add (self._hbox) self.add (self._hbox)
self._title.show () self._title.show_all ()
self._hbox.show () self._hbox.show ()
self.wanted = configwanted self.wanted = configwanted
self.connect ("button-release-event", self.on_clicked) self.connect ("button-press-event", self.on_clicked)
def connect_icon (self, func): def connect_icon (self, func):
self._ebox.connect ("button-release-event", func) self._ebox.connect ("button-release-event", func)