Fixed issue of not re-docking gramplet from whence it came (reported by Rob); refined some code

svn: r13999
This commit is contained in:
Doug Blank 2010-01-08 20:06:51 +00:00
parent 2f7f7ac5f8
commit debfc3dd78

View File

@ -212,6 +212,10 @@ class GrampletWindow(ManagedWindow.ManagedWindow):
""" """
self.title = gramplet.title + " " + _("Gramplet") self.title = gramplet.title + " " + _("Gramplet")
self.gramplet = gramplet self.gramplet = gramplet
# Keep track of what state it was in:
self.docked_state = gramplet.state
# Now detach it
self.gramplet.set_state("detached")
ManagedWindow.ManagedWindow.__init__(self, gramplet.uistate, [], self.title) ManagedWindow.ManagedWindow.__init__(self, gramplet.uistate, [], self.title)
self.set_window(gtk.Dialog("",gramplet.uistate.window, self.set_window(gtk.Dialog("",gramplet.uistate.window,
gtk.DIALOG_DESTROY_WITH_PARENT, gtk.DIALOG_DESTROY_WITH_PARENT,
@ -269,18 +273,33 @@ class GrampletWindow(ManagedWindow.ManagedWindow):
""" """
self.gramplet.gvoptions.hide() self.gramplet.gvoptions.hide()
self.gramplet.viewpage.detached_gramplets.remove(self.gramplet) self.gramplet.viewpage.detached_gramplets.remove(self.gramplet)
self.gramplet.state = "maximized" if self.docked_state == "minimized":
self.gramplet.set_state("minimized")
else:
self.gramplet.set_state("maximized")
parent = self.gramplet.viewpage.get_column_frame(self.gramplet.column) parent = self.gramplet.viewpage.get_column_frame(self.gramplet.column)
self.gramplet.mainframe.reparent(parent) self.gramplet.mainframe.reparent(parent)
# FIXME: Put the gramplet in the same column/row where it came from, if you can. viewpage = self.gramplet.viewpage
# This will put it at the bottom of column: col = self.gramplet.column
expand,fill,padding,pack = parent.query_child_packing(self.gramplet.mainframe) stack = []
parent.set_child_packing(self.gramplet.mainframe, for gframe in viewpage.columns[col]:
self.gramplet.expand, gramplet = viewpage.frame_map[str(gframe)]
fill, if gramplet.row > self.gramplet.row:
padding, viewpage.columns[col].remove(gframe)
pack) stack.append(gframe)
# end FIXME expand = self.gramplet.state == "maximized" and self.gramplet.expand
column = viewpage.columns[col]
column.pack_start(self.gramplet.mainframe, expand=expand)
for gframe in stack:
gramplet = viewpage.frame_map[str(gframe)]
expand = gramplet.state == "maximized" and gramplet.expand
viewpage.columns[col].pack_start(gframe, expand=expand)
# Now make sure they all have the correct expand:
for gframe in viewpage.columns[col]:
gramplet = viewpage.frame_map[str(gframe)]
expand, fill, padding, pack = column.query_child_packing(gramplet.mainframe)
expand = gramplet.state == "maximized" and gramplet.expand
column.set_child_packing(gramplet.mainframe, expand, fill, padding, pack)
self.gramplet.gvclose.show() self.gramplet.gvclose.show()
self.gramplet.gvstate.show() self.gramplet.gvstate.show()
self.gramplet.gvproperties.show() self.gramplet.gvproperties.show()
@ -375,7 +394,7 @@ class GuiGramplet(object):
Detach the gramplet from the GrampletView, and open in own window. Detach the gramplet from the GrampletView, and open in own window.
""" """
# hide buttons: # hide buttons:
self.set_state("detached") #self.set_state("detached")
self.viewpage.detached_gramplets.append(self) self.viewpage.detached_gramplets.append(self)
# make a window, and attach it there # make a window, and attach it there
self.detached_window = GrampletWindow(self) self.detached_window = GrampletWindow(self)
@ -870,7 +889,7 @@ class GrampletView(PageView):
# put the gramplets where they go: # put the gramplets where they go:
# sort by row # sort by row
gramplets.sort(key=lambda x: x.row) gramplets.sort(key=lambda x: x.row)
rows = [0] * max(self.column_count, 1)
for cnt, gramplet in enumerate(gramplets): for cnt, gramplet in enumerate(gramplets):
# see if the user wants this in a particular location: # see if the user wants this in a particular location:
# and if there are that many columns # and if there are that many columns
@ -880,6 +899,8 @@ class GrampletView(PageView):
# else, spread them out: # else, spread them out:
pos = cnt % self.column_count pos = cnt % self.column_count
gramplet.column = pos gramplet.column = pos
gramplet.row = rows[gramplet.column]
rows[gramplet.column] += 1
if recolumn and (gramplet.state == "detached" or gramplet.state == "closed"): if recolumn and (gramplet.state == "detached" or gramplet.state == "closed"):
continue continue
if gramplet.state == "minimized": if gramplet.state == "minimized":
@ -1021,24 +1042,26 @@ class GrampletView(PageView):
fromcol.remove(mainframe) fromcol.remove(mainframe)
# now find where to insert in column: # now find where to insert in column:
stack = [] stack = []
current_row = 0
for gframe in self.columns[col]: for gframe in self.columns[col]:
gramplet = self.frame_map[str(gframe)]
gramplet.row = current_row
current_row += 1
rect = gframe.get_allocation() rect = gframe.get_allocation()
if y < (rect.y + 15): # starts at 0, this allows insert before if y < (rect.y + 15): # starts at 0, this allows insert before
self.columns[col].remove(gframe) self.columns[col].remove(gframe)
stack.append(gframe) stack.append(gframe)
maingramplet = self.frame_map.get(str(mainframe), None) maingramplet = self.frame_map.get(str(mainframe), None)
maingramplet.column = col maingramplet.column = col
if maingramplet.state == "maximized": maingramplet.row = current_row
expand = maingramplet.expand current_row += 1
else: expand = maingramplet.state == "maximized" and maingramplet.expand
expand = False
self.columns[col].pack_start(mainframe, expand=expand) self.columns[col].pack_start(mainframe, expand=expand)
for gframe in stack: for gframe in stack:
gramplet = self.frame_map[str(gframe)] gramplet = self.frame_map[str(gframe)]
if gramplet.state == "maximized": gramplet.row = current_row
expand = gramplet.expand current_row += 1
else: expand = gramplet.state == "maximized" and gramplet.expand
expand = False
self.columns[col].pack_start(gframe, expand=expand) self.columns[col].pack_start(gframe, expand=expand)
return True return True