Refactored statusbar width
svn: r17898
This commit is contained in:
parent
58eb8627e9
commit
768fe26346
@ -71,22 +71,14 @@ class Statusbar(gtk.HBox):
|
|||||||
gobject.PARAM_READWRITE),
|
gobject.PARAM_READWRITE),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, min_width=30):
|
def __init__(self):
|
||||||
gtk.HBox.__init__(self)
|
gtk.HBox.__init__(self)
|
||||||
|
|
||||||
# initialize pixel/character scale
|
|
||||||
pl = pango.Layout(self.get_pango_context())
|
|
||||||
pl.set_text("M")
|
|
||||||
(self._char_width, h) = pl.get_pixel_size()
|
|
||||||
|
|
||||||
# initialize property values
|
# initialize property values
|
||||||
self.__has_resize_grip = True
|
self.__has_resize_grip = True
|
||||||
|
|
||||||
# create the main statusbar with id #0
|
# create the main statusbar with id #0
|
||||||
main_bar = gtk.Statusbar()
|
main_bar = gtk.Statusbar()
|
||||||
main_bar.set_size_request(min_width*self._char_width, -1)
|
|
||||||
main_bar.show()
|
main_bar.show()
|
||||||
self.pack_start(main_bar)
|
self.pack_start(main_bar, fill=True, expand=True)
|
||||||
self._bars = {0: main_bar}
|
self._bars = {0: main_bar}
|
||||||
self._set_resize_grip()
|
self._set_resize_grip()
|
||||||
|
|
||||||
@ -123,18 +115,6 @@ class Statusbar(gtk.HBox):
|
|||||||
|
|
||||||
bar.set_has_resize_grip(self.get_property('has-resize-grip'))
|
bar.set_has_resize_grip(self.get_property('has-resize-grip'))
|
||||||
|
|
||||||
def _set_packing(self):
|
|
||||||
"""Set packing style of the statusbars.
|
|
||||||
|
|
||||||
All bars are packed with "expand"=True, "fill"=True parameters,
|
|
||||||
except the last one, which is packed with "expand"=False, "fill"=False.
|
|
||||||
|
|
||||||
"""
|
|
||||||
for bar in self.get_children():
|
|
||||||
self.set_child_packing(bar, True, True, 0, gtk.PACK_START)
|
|
||||||
|
|
||||||
self.set_child_packing(bar, False, False, 0, gtk.PACK_START)
|
|
||||||
|
|
||||||
def _get_next_id(self):
|
def _get_next_id(self):
|
||||||
"""Get next unused statusbar id.
|
"""Get next unused statusbar id.
|
||||||
"""
|
"""
|
||||||
@ -146,7 +126,7 @@ class Statusbar(gtk.HBox):
|
|||||||
|
|
||||||
# Public API
|
# Public API
|
||||||
|
|
||||||
def insert(self, index=-1, min_width=30, ralign=False):
|
def insert(self, index=-1, min_width=None, ralign=False):
|
||||||
"""Insert a new statusbar.
|
"""Insert a new statusbar.
|
||||||
|
|
||||||
Create a new statusbar and insert it at the given index. Index starts
|
Create a new statusbar and insert it at the given index. Index starts
|
||||||
@ -155,12 +135,10 @@ class Statusbar(gtk.HBox):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
new_bar = gtk.Statusbar()
|
new_bar = gtk.Statusbar()
|
||||||
new_bar.set_size_request(min_width*self._char_width, -1)
|
|
||||||
new_bar.show()
|
new_bar.show()
|
||||||
self.pack_start(new_bar)
|
self.pack_start(new_bar, fill=True, expand=True)
|
||||||
self.reorder_child(new_bar, index)
|
self.reorder_child(new_bar, index)
|
||||||
self._set_resize_grip()
|
self._set_resize_grip()
|
||||||
self._set_packing()
|
|
||||||
|
|
||||||
if ralign:
|
if ralign:
|
||||||
frame = new_bar.get_children()[0]
|
frame = new_bar.get_children()[0]
|
||||||
@ -196,7 +174,8 @@ class Statusbar(gtk.HBox):
|
|||||||
programming fault.
|
programming fault.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return self._bars[bar_id].push(context_id, text)
|
# HACK: add an extra space so grip doesn't overlap
|
||||||
|
return self._bars[bar_id].push(context_id, text + " ")
|
||||||
|
|
||||||
def pop(self, context_id, bar_id=0):
|
def pop(self, context_id, bar_id=0):
|
||||||
"""Remove the top message from a statusbar's stack.
|
"""Remove the top message from a statusbar's stack.
|
||||||
@ -244,16 +223,16 @@ def main(args):
|
|||||||
statusbar = Statusbar()
|
statusbar = Statusbar()
|
||||||
vbox.pack_end(statusbar, False)
|
vbox.pack_end(statusbar, False)
|
||||||
|
|
||||||
statusbar.push(1, "This is my statusbar...")
|
statusbar.push(1, "My statusbar")
|
||||||
|
|
||||||
my_statusbar = statusbar.insert(min_width=24)
|
my_statusbar = statusbar.insert()
|
||||||
statusbar.push(1, "Testing status bar width", my_statusbar)
|
statusbar.push(1, "Testing width", my_statusbar)
|
||||||
|
|
||||||
yet_another_statusbar = statusbar.insert(1, 11)
|
yet_another_statusbar = statusbar.insert()
|
||||||
statusbar.push(1, "A short one", yet_another_statusbar)
|
statusbar.push(1, "A short one", yet_another_statusbar)
|
||||||
|
|
||||||
last_statusbar = statusbar.insert(min_width=41, ralign=True)
|
last_statusbar = statusbar.insert(ralign=True)
|
||||||
statusbar.push(1, "The last statusbar has always fixed width",
|
statusbar.push(1, "The last statusbar",
|
||||||
last_statusbar)
|
last_statusbar)
|
||||||
|
|
||||||
win.show_all()
|
win.show_all()
|
||||||
|
Loading…
Reference in New Issue
Block a user