Improvement to dropdown navigation plugin
svn: r21102
This commit is contained in:
parent
7a5e277b38
commit
d4e85e7336
@ -273,8 +273,7 @@ class Navigator(object):
|
|||||||
self.pages[old_page][1].inactive()
|
self.pages[old_page][1].inactive()
|
||||||
self.pages[index][1].active(self.active_cat, self.active_view)
|
self.pages[index][1].active(self.active_cat, self.active_view)
|
||||||
self.pages[index][1].view_changed(self.active_cat, self.active_view)
|
self.pages[index][1].view_changed(self.active_cat, self.active_view)
|
||||||
if self.pages:
|
self.title_label.set_text(self.pages[index][0])
|
||||||
self.title_label.set_text(self.pages[index][0])
|
|
||||||
|
|
||||||
def cb_close_clicked(self, button):
|
def cb_close_clicked(self, button):
|
||||||
"""
|
"""
|
||||||
|
@ -57,24 +57,16 @@ class DropdownSidebar(BaseSidebar):
|
|||||||
self.button_handlers = []
|
self.button_handlers = []
|
||||||
|
|
||||||
self.window = Gtk.ScrolledWindow()
|
self.window = Gtk.ScrolledWindow()
|
||||||
vbox = Gtk.VBox()
|
grid = Gtk.Grid()
|
||||||
self.window.add_with_viewport(vbox)
|
self.window.add_with_viewport(grid)
|
||||||
self.window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
|
self.window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
|
||||||
self.window.show()
|
self.window.show()
|
||||||
|
|
||||||
use_text = config.get('interface.sidebar-text')
|
use_text = config.get('interface.sidebar-text')
|
||||||
for cat_num, cat_name, cat_icon in categories:
|
for cat_num, cat_name, cat_icon in categories:
|
||||||
|
self.__make_category(grid, use_text, cat_num, cat_name, cat_icon)
|
||||||
|
|
||||||
# create the button and add it to the sidebar
|
grid.show_all()
|
||||||
button = self.__make_sidebar_button(use_text, cat_num,
|
|
||||||
cat_name, cat_icon)
|
|
||||||
vbox.pack_start(button, False, True, 0)
|
|
||||||
|
|
||||||
# Enable view switching during DnD
|
|
||||||
button.drag_dest_set(0, [], 0)
|
|
||||||
button.connect('drag_motion', self.cb_switch_page_on_dnd, cat_num)
|
|
||||||
|
|
||||||
vbox.show_all()
|
|
||||||
|
|
||||||
def get_top(self):
|
def get_top(self):
|
||||||
"""
|
"""
|
||||||
@ -146,31 +138,32 @@ class DropdownSidebar(BaseSidebar):
|
|||||||
"""
|
"""
|
||||||
self.viewmanager.goto_page(cat_num, view_num)
|
self.viewmanager.goto_page(cat_num, view_num)
|
||||||
|
|
||||||
def __make_sidebar_button(self, use_text, index, page_title, page_stock):
|
def __make_category(self, grid, use_text, cat_num, cat_name, cat_icon):
|
||||||
"""
|
"""
|
||||||
Create the sidebar button. The page_title is the text associated with
|
Create a row in the sidebar for a category.
|
||||||
the button.
|
|
||||||
"""
|
"""
|
||||||
top = Gtk.HBox()
|
|
||||||
|
|
||||||
# create the button
|
# create the button
|
||||||
button = Gtk.ToggleButton()
|
button = Gtk.ToggleButton()
|
||||||
button.set_relief(Gtk.ReliefStyle.NONE)
|
button.set_relief(Gtk.ReliefStyle.NONE)
|
||||||
button.set_alignment(0, 0.5)
|
button.set_alignment(0, 0.5)
|
||||||
self.buttons.append(button)
|
self.buttons.append(button)
|
||||||
|
|
||||||
button2 = Gtk.Button()
|
# create the drop-down button to display views
|
||||||
button2.set_relief(Gtk.ReliefStyle.NONE)
|
if len(self.views[cat_num]) > 1:
|
||||||
button2.set_alignment(0.5, 0.5)
|
dropdown = Gtk.Button()
|
||||||
arrow = Gtk.Arrow(Gtk.ArrowType.DOWN, Gtk.ShadowType.NONE)
|
dropdown.set_relief(Gtk.ReliefStyle.NONE)
|
||||||
button2.add(arrow)
|
dropdown.set_alignment(0.5, 0.5)
|
||||||
button2.connect('clicked', self.__view_clicked, index)
|
arrow = Gtk.Arrow(Gtk.ArrowType.DOWN, Gtk.ShadowType.NONE)
|
||||||
|
dropdown.add(arrow)
|
||||||
|
dropdown.connect('clicked', self.__view_clicked, cat_num)
|
||||||
|
dropdown.set_tooltip_text(_('Click to select a view'))
|
||||||
|
grid.attach(dropdown, 1, cat_num, 1, 1)
|
||||||
|
|
||||||
# add the tooltip
|
# add the tooltip
|
||||||
button.set_tooltip_text(page_title)
|
button.set_tooltip_text(cat_name)
|
||||||
|
|
||||||
# connect the signal, along with the index as user data
|
# connect the signal, along with the cat_num as user data
|
||||||
handler_id = button.connect('clicked', self.__category_clicked, index)
|
handler_id = button.connect('clicked', self.__category_clicked, cat_num)
|
||||||
self.button_handlers.append(handler_id)
|
self.button_handlers.append(handler_id)
|
||||||
button.show()
|
button.show()
|
||||||
|
|
||||||
@ -180,25 +173,26 @@ class DropdownSidebar(BaseSidebar):
|
|||||||
hbox.show()
|
hbox.show()
|
||||||
image = Gtk.Image()
|
image = Gtk.Image()
|
||||||
if use_text:
|
if use_text:
|
||||||
image.set_from_stock(page_stock, Gtk.IconSize.BUTTON)
|
image.set_from_stock(cat_icon, Gtk.IconSize.BUTTON)
|
||||||
else:
|
else:
|
||||||
image.set_from_stock(page_stock, Gtk.IconSize.DND)
|
image.set_from_stock(cat_icon, Gtk.IconSize.DND)
|
||||||
image.show()
|
image.show()
|
||||||
hbox.pack_start(image, False, False, 0)
|
hbox.pack_start(image, False, False, 0)
|
||||||
hbox.set_spacing(4)
|
hbox.set_spacing(4)
|
||||||
|
|
||||||
# add text if requested
|
# add text if requested
|
||||||
if use_text:
|
if use_text:
|
||||||
label = Gtk.Label(label=page_title)
|
label = Gtk.Label(label=cat_name)
|
||||||
label.show()
|
label.show()
|
||||||
hbox.pack_start(label, False, True, 0)
|
hbox.pack_start(label, False, True, 0)
|
||||||
|
|
||||||
button.add(hbox)
|
button.add(hbox)
|
||||||
|
|
||||||
top.pack_start(button, False, True, 0)
|
# Enable view switching during DnD
|
||||||
top.pack_start(button2, False, True, 0)
|
button.drag_dest_set(0, [], 0)
|
||||||
|
button.connect('drag_motion', self.cb_switch_page_on_dnd, cat_num)
|
||||||
|
|
||||||
return top
|
grid.attach(button, 0, cat_num, 1, 1)
|
||||||
|
|
||||||
def cb_switch_page_on_dnd(self, widget, context, xpos, ypos, time, page_no):
|
def cb_switch_page_on_dnd(self, widget, context, xpos, ypos, time, page_no):
|
||||||
"""
|
"""
|
||||||
|
@ -106,10 +106,9 @@ class ExpanderSidebar(BaseSidebar):
|
|||||||
"""
|
"""
|
||||||
Called when the active view is changed.
|
Called when the active view is changed.
|
||||||
"""
|
"""
|
||||||
if cat_num is None:
|
|
||||||
return
|
|
||||||
# Expand category
|
# Expand category
|
||||||
self.expanders[cat_num].set_expanded(True)
|
if cat_num is not None:
|
||||||
|
self.expanders[cat_num].set_expanded(True)
|
||||||
# Set new button as selected
|
# Set new button as selected
|
||||||
button_num = self.lookup[(cat_num, view_num)]
|
button_num = self.lookup[(cat_num, view_num)]
|
||||||
self.__handlers_block()
|
self.__handlers_block()
|
||||||
|
Loading…
Reference in New Issue
Block a user