- Can maximize one terminal (full-window) and then restore to previous layout.

- New pop-up menu items to test the feature
This commit is contained in:
Edoardo Batini 2008-05-15 02:59:54 +02:00
parent 01ce8d92fd
commit 8e2d3e9975
2 changed files with 55 additions and 70 deletions

View File

@ -11,3 +11,6 @@
.git/refs .git/refs
.git .git
.gitignore .gitignore
build
build/bzr
status

View File

@ -84,9 +84,6 @@ class TerminatorTerm:
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]
# EDO: could be:
# os.environ['PWD']
self.clipboard = gtk.clipboard_get (gtk.gdk.SELECTION_CLIPBOARD) self.clipboard = gtk.clipboard_get (gtk.gdk.SELECTION_CLIPBOARD)
self.scrollbar_position = self.conf.scrollbar_position self.scrollbar_position = self.conf.scrollbar_position
@ -497,9 +494,6 @@ class TerminatorTerm:
item.connect ("activate", lambda menu_item: self.terminator.hide_all_but_me (self)) item.connect ("activate", lambda menu_item: self.terminator.hide_all_but_me (self))
menu.append (item) menu.append (item)
item = gtk.MenuItem ()
menu.append (item)
item = gtk.MenuItem (_("Go B_ack")) item = gtk.MenuItem (_("Go B_ack"))
item.connect ("activate", lambda menu_item: self.terminator.show_back_others (self)) item.connect ("activate", lambda menu_item: self.terminator.show_back_others (self))
menu.append (item) menu.append (item)
@ -541,7 +535,6 @@ class TerminatorTerm:
class Terminator: class Terminator:
def __init__ (self, profile, command = None, fullscreen = False, maximise = False, borderless = False): def __init__ (self, profile, command = None, fullscreen = False, maximise = False, borderless = False):
self.restore = []
self.profile = profile self.profile = profile
self.command = command self.command = command
@ -597,7 +590,7 @@ class Terminator:
# FIXME: This should be really be decided from some kind of profile # FIXME: This should be really be decided from some kind of profile
term = (TerminatorTerm (self, self.profile, self.command)) term = (TerminatorTerm (self, self.profile, self.command))
self.term_list = [term] self.term_list = [term]
self.widget_history=[self.window, term]
self.window.add (term.get_box ()) self.window.add (term.get_box ())
self.window.show () self.window.show ()
@ -605,7 +598,7 @@ class Terminator:
""" Maximize the Terminator window.""" """ Maximize the Terminator window."""
self.window.maximize () self.window.maximize ()
def toggle_fullscreen (self): def fullscreen_toggle (self):
""" Toggle the fullscreen state of the window. If it is in """ Toggle the fullscreen state of the window. If it is in
fullscreen state, it will be unfullscreened. If it is not, it fullscreen state, it will be unfullscreened. If it is not, it
will be set to fullscreen state. will be set to fullscreen state.
@ -665,7 +658,7 @@ class Terminator:
mask = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK mask = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK
if (keyname == 'F11'): if (keyname == 'F11'):
self.toggle_fullscreen () self.fullscreen_toggle ()
return (True) return (True)
if (event.state & mask) == mask: if (event.state & mask) == mask:
@ -678,67 +671,62 @@ class Terminator:
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. """
# create a new terminal and parent pane. # create a new terminal and parent pane.
terminal = TerminatorTerm (self, self.profile, None, widget.get_cwd()) terminal = TerminatorTerm (self, self.profile, None, widget.get_cwd())
pane = (vertical) and gtk.VPaned () or gtk.HPaned () pane = (vertical) and gtk.VPaned () or gtk.HPaned ()
# get the parent of the provided terminal # get the parent of the provided terminal
parent = widget.get_box ().get_parent () parent = widget.get_box ().get_parent ()
if isinstance (parent, gtk.Window): if isinstance (parent, gtk.Window):
# We have just one term # We have just one term
# [Window, Terminal]
widget.get_box ().reparent (pane) widget.get_box ().reparent (pane)
pane.pack1 (widget.get_box (), True, True) pane.pack1 (widget.get_box (), True, True)
pane.pack2 (terminal.get_box (), True, True) pane.pack2 (terminal.get_box (), True, True)
parent.add (pane) parent.add (pane)
position = (vertical) and parent.allocation.height \ position = (vertical) and parent.allocation.height \
or parent.allocation.width or parent.allocation.width
# After:
# Code needed to store application widget structure. # [Window, Pane, OldTerminal, NewTerminal]
# self.widgets.insert(0, pane)
# get widget index, add pane before her in widget_history self.widgets.append(terminal)
# and a terminal after her
for n in range(len(self.widget_history)):
if self.widget_history[n] == widget:
self.widget_history.insert(n, pane)
self.widget_history.insert(n+2, terminal)
print self.widget_history
if isinstance (parent, gtk.Paned): if isinstance (parent, gtk.Paned):
# We are inside a split term # We are inside a split term
position = (vertical) and widget.get_box().allocation.height \ position = (vertical) and widget.get_box().allocation.height \
or widget.get_box().allocation.width or widget.get_box().allocation.width
## ... Pane, ClickedTerminal, Terminal ...
## becomes
## ... Pane, Pane, ClickedTerminal, NewTerminal, Terminal]
if (widget.get_box () == parent.get_child1 ()): if (widget.get_box () == parent.get_child1 ()):
widget.get_box ().reparent (pane) widget.get_box ().reparent (pane)
parent.pack1 (pane, True, True) parent.pack1 (pane, True, True)
## ... Pane, Terminal, ClickedTerminal ...
## becomes
## ... Pane, Terminal, Pane, ClickedTerminal, NewTerminal]
else: else:
widget.get_box ().reparent (pane) widget.get_box ().reparent (pane)
parent.pack2 (pane, True, True) parent.pack2 (pane, True, True)
pane.pack1 (widget.get_box (), True, True) pane.pack1 (widget.get_box (), True, True)
pane.pack2 (terminal.get_box (), True, True) pane.pack2 (terminal.get_box (), True, True)
i = self.widgets.index(widget)
self.widgets.insert(i, pane)
self.widgets.insert(i+2, terminal)
# show all, set position of the divider # show all, set position of the divider
pane.show () pane.show ()
pane.set_position (position / 2) pane.set_position (position / 2)
terminal.get_box ().show () terminal.get_box ().show ()
# insert the term reference into the list # insert the term reference into the list
index = self.term_list.index (widget) index = self.term_list.index (widget)
self.term_list.insert (index + 1, terminal) self.term_list.insert (index + 1, terminal)
# make the new terminal grab the focus # make the new terminal grab the focus
terminal._vte.grab_focus () terminal._vte.grab_focus ()
return (terminal) return (terminal)
def closeterm (self, widget): def closeterm (self, widget):
parent = widget.get_box ().get_parent () parent = widget.get_box ().get_parent ()
sibling = None sibling = None
@ -748,6 +736,14 @@ class Terminator:
self.on_destroy_event (parent, gtk.gdk.Event (gtk.gdk.DESTROY)) self.on_destroy_event (parent, gtk.gdk.Event (gtk.gdk.DESTROY))
return return
i = self.widgets.index(widget)
if isinstance(self.widgets[i-1], gtk.Paned):
del(self.widgets[i])
del(self.widgets[i-1])
else:
del(self.widgets[i])
del(self.widgets[i-2])
if isinstance (parent, gtk.Paned): if isinstance (parent, gtk.Paned):
index = self.term_list.index (widget) index = self.term_list.index (widget)
grandparent = parent.get_parent () grandparent = parent.get_parent ()
@ -806,7 +802,6 @@ class Terminator:
self.term_list[previous]._vte.grab_focus () self.term_list[previous]._vte.grab_focus ()
def resizeterm (self, widget, keyname): def resizeterm (self, widget, keyname):
vertical = False vertical = False
if keyname in ('Up', 'Down'): if keyname in ('Up', 'Down'):
vertical = True vertical = True
@ -816,7 +811,6 @@ class Terminator:
return return
parent = self.get_first_parent_paned(widget.get_box (),vertical) parent = self.get_first_parent_paned(widget.get_box (),vertical)
if parent == None: if parent == None:
return return
@ -833,58 +827,46 @@ class Terminator:
if keyname in ('Up', 'Left'): if keyname in ('Up', 'Left'):
move = -10 move = -10
parent_position = parent.get_position()
move = max(2, parent_position + move) move = max(2, parent_position + move)
move = min(maxi, move) move = min(maxi, move)
parent.set_position(move) parent.set_position(move)
def hide_all_but_me (self, widget): def hide_all_but_me (self, widget):
"""Proof of concept: Maximize an instance of TerminatorTerm """Proof of concept: Maximize an instance of TerminatorTerm
Only first split is kept in memory...
""" """
parent = widget.get_box ().get_parent () parent = widget.get_box ().get_parent ()
##TRY TO SHOW ONLY ONE AND KEEP PREVIOUS LAYOUT
if isinstance (parent, gtk.Window): if isinstance (parent, gtk.Window):
# We have just one term # We have just one term
return return
else: else:
me = None self.window.remove(self.window.get_children()[0])
for n in self.widget_history: widget.get_box().reparent(self.window)
if n == widget:
me = n def show_back_others(self, widget):
else:
try:
self.window.remove(n)
except:
self.window.remove(n.get_box())
if me:
me.get_box ().reparent(self.window)
def show_back_others (self, widget):
"""Proof of concept: Go back to previous application """Proof of concept: Go back to previous application
widget structure. widget structure.
Still positions are not stored in 'widget_history' list.
Maximizing first terminal in and restoring
previous layout works perfectly; maximizing second
terminal doesn't restore properly, yet!
""" """
## HERE TERMINALS AND PANES SHOULD POP BACK! for n in self.window.get_children():
number_of_widgets = len(self.widget_history) self.window.remove(n)
if number_of_widgets == 2: # just a gtk.Window and a TerminatorTerm self.restore()
return
def restore(self):
if isinstance(self.widgets[0], TerminatorTerm):
self.window.add (self.widgets[0].get_box ())
else: else:
# Clean Window self.window.add (self.restore_tree (self.widgets[0]))
for n in self.window.get_children(): self.window.show_all()
self.window.remove(n)
self.widget_history[1].pack1(self.widget_history[2].get_box()) def restore_tree(self, widget):
self.widget_history[1].pack1(self.widget_history[3].get_box()) if isinstance(widget, TerminatorTerm):
self.window.add(self.widget_history[1]) return widget.get_box()
self.window.show_all() else:
return i = self.widgets.index(widget)
widget.add1 (self.restore_tree (self.widgets[i+1]))
widget.add2 (self.restore_tree (self.widgets[i+2]))
widget.show()
return widget
def get_first_parent_paned (self, widget, vertical = None): def get_first_parent_paned (self, widget, vertical = None):
"""This method returns the first parent pane of a widget. """This method returns the first parent pane of a widget.