Skip to content

Commit

Permalink
Merge pull request #1664 from QuLogic/navigator-update
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-Hall committed Apr 15, 2024
2 parents 31e3e67 + 73ab187 commit e660429
Showing 3 changed files with 46 additions and 110 deletions.
2 changes: 1 addition & 1 deletion gramps/gui/grampsgui.py
Original file line number Diff line number Diff line change
@@ -215,7 +215,7 @@
<attribute name="label" translatable="yes">F_ull Screen</attribute>
</item>
</section>
<section id="ViewsInCatagory">
<section id="ViewsInCategory">
</section>
</submenu>
<submenu id="m5" groups='RO'>
152 changes: 44 additions & 108 deletions gramps/gui/navigator.py
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
#
# -------------------------------------------------------------------------
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GObject

# -------------------------------------------------------------------------
#
@@ -45,7 +45,7 @@
# Constants
#
# -------------------------------------------------------------------------
UICATEGORY = """ <section id="ViewsInCatagory">
UICATEGORY = """ <section id="ViewsInCategory">
%s
</section>
"""
@@ -83,7 +83,8 @@ class Navigator:

def __init__(self, viewmanager):
self.viewmanager = viewmanager
self.pages = []
self.pages = {}
self._active_page = None
self.active_cat = None
self.active_view = None

@@ -92,63 +93,39 @@ def __init__(self, viewmanager):
self.merge_ids = []

self.top = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.top.show()

self.select_button = Gtk.ComboBoxText()
self.select_button.show()
self.top.pack_end(self.select_button, False, True, 0)

frame = Gtk.Frame()
hbox = Gtk.Box()
hbox.show()
frame.add(hbox)
frame.show()

self.select_button = Gtk.ToggleButton()
self.select_button.set_relief(Gtk.ReliefStyle.NONE)
select_hbox = Gtk.Box()
self.title_label = Gtk.Label(label="")
arrow = Gtk.Arrow(
arrow_type=Gtk.ArrowType.DOWN, shadow_type=Gtk.ShadowType.NONE
self.stack = Gtk.Stack(homogeneous=False)
self.stack.show()
self.stack.connect("notify::visible-child-name", self.cb_switch_page)
self.top.pack_start(self.stack, True, True, 0)

self.select_button.bind_property(
"active-id",
self.stack,
"visible-child-name",
GObject.BindingFlags.BIDIRECTIONAL,
)
select_hbox.pack_start(self.title_label, False, True, 0)
select_hbox.pack_end(arrow, False, True, 0)
self.select_button.add(select_hbox)

self.select_button.connect("button_press_event", self.__menu_button_pressed)

# close_button = Gtk.Button()
# img = Gtk.Image.new_from_icon_name('window-close', Gtk.IconSize.MENU)
# close_button.set_image(img)
# close_button.set_relief(Gtk.ReliefStyle.NONE)
# close_button.connect('clicked', self.cb_close_clicked)
hbox.pack_start(self.select_button, False, True, 0)
# hbox.pack_end(close_button, False, True, 0)

self.top.pack_end(frame, False, True, 0)

self.menu = Gtk.Menu()
self.menu.show()
self.menu.connect("deactivate", cb_menu_deactivate, self.select_button)

self.notebook = Gtk.Notebook()
self.notebook.show()
self.notebook.set_show_tabs(False)
self.notebook.set_show_border(False)
self.notebook.connect("switch_page", self.cb_switch_page)
self.top.show()
self.top.pack_start(self.notebook, True, True, 0)

def load_plugins(self, dbstate, uistate):
"""
Load the sidebar plugins.
"""
menuitem = """
<item>
<attribute name="action">win.ViewInCatagory</attribute>
<attribute name="action">win.ViewInCategory</attribute>
<attribute name="label" translatable="yes">%s</attribute>
<attribute name="target">%d %d</attribute>
</item>
"""
baritem = """
<child>
<object class="GtkToggleToolButton" id="bar%d">
<property name="action-name">win.ViewInCatagory</property>
<property name="action-name">win.ViewInCategory</property>
<property name="action-target">'%d %d'</property>
<property name="icon-name">%s</property>
<property name="tooltip_text" translatable="yes">%s</property>
@@ -187,7 +164,7 @@ def load_plugins(self, dbstate, uistate):
if view_num < 9:
accel = "<PRIMARY><ALT>%d" % ((view_num % 9) + 1)
self.viewmanager.uimanager.app.set_accels_for_action(
"win.ViewInCatagory('%d %d')" % (cat_num, view_num), [accel]
"win.ViewInCategory('%d %d')" % (cat_num, view_num), [accel]
)
uimenuitems += menuitem % (page[0].name, cat_num, view_num)

@@ -232,22 +209,17 @@ def add(self, title, sidebar, order):
"""
Add a page to the sidebar for a plugin.
"""
self.pages.append((title, sidebar))
self.pages[title] = sidebar
page = sidebar.get_top()
# hide for now so notebook is only size of active page
page.get_child().hide()
index = self.notebook.append_page(page, Gtk.Label(label=title))
self.stack.add_named(page, title)

menu_item = Gtk.MenuItem(label=title)
if order == START:
self.menu.prepend(menu_item)
self.notebook.set_current_page(index)
self.select_button.prepend(id=title, text=title)
self.select_button.set_active_id(title)
else:
self.menu.append(menu_item)
menu_item.connect("activate", self.cb_menu_activate, index)
menu_item.show()
self.select_button.append(id=title, text=title)

if self.notebook.get_n_pages() == 2:
if len(self.stack.get_children()) == 2:
self.select_button.show_all()

def view_changed(self, cat_num, view_num):
@@ -267,7 +239,7 @@ def view_changed(self, cat_num, view_num):

if cat_num in self.ui_category:
action = (
"ViewInCatagory",
"ViewInCategory",
self.cb_view_clicked,
"",
str(cat_num) + " " + str(view_num),
@@ -279,8 +251,8 @@ def view_changed(self, cat_num, view_num):

# Call the view_changed method for the active sidebar
try:
sidebar = self.pages[self.notebook.get_current_page()][1]
except IndexError:
sidebar = self.pages[self.stack.get_visible_child_name()]
except KeyError:
return
sidebar.view_changed(cat_num, view_num)

@@ -291,56 +263,20 @@ def cb_view_clicked(self, radioaction, value):
cat_num, view_num = value.get_string().split()
self.viewmanager.goto_page(int(cat_num), int(view_num))

def __menu_button_pressed(self, button, event):
"""
Called when the button to select a sidebar page is pressed.
"""
if event.button == 1 and event.type == Gdk.EventType.BUTTON_PRESS:
button.grab_focus()
button.set_active(True)

self.menu.popup_at_widget(
button, Gdk.Gravity.SOUTH_WEST, Gdk.Gravity.NORTH_WEST, None
)

def cb_menu_activate(self, menu, index):
"""
Called when an item in the popup menu is selected.
"""
self.notebook.set_current_page(index)

def cb_switch_page(self, notebook, unused, index):
def cb_switch_page(self, stack, pspec):
"""
Called when the user has switched to a new sidebar plugin page.
"""
old_page = notebook.get_current_page()
if old_page != -1:
self.pages[old_page][1].inactive()
# hide so notebook is only size of active page
notebook.get_nth_page(old_page).get_child().hide()

self.pages[index][1].active(self.active_cat, self.active_view)
notebook.get_nth_page(index).get_child().show()
notebook.queue_resize()
old_page = self._active_page
if old_page is not None:
self.pages[old_page].inactive()

title = stack.get_visible_child_name()
if title is None:
# May happen during the time that the widgets have been created, but the
# pages haven't been added.
return
self.pages[title].active(self.active_cat, self.active_view)
if self.active_view is not None:
self.pages[index][1].view_changed(self.active_cat, self.active_view)
self.title_label.set_text(self.pages[index][0])

def cb_close_clicked(self, button):
"""
Called when the sidebar is closed.
"""
uimanager = self.viewmanager.uimanager
uimanager.get_action("/MenuBar/ViewMenu/Navigator").activate()


# -------------------------------------------------------------------------
#
# Functions
#
# -------------------------------------------------------------------------
def cb_menu_deactivate(menu, button):
"""
Called when the popup menu disappears.
"""
button.set_active(False)
self.pages[title].view_changed(self.active_cat, self.active_view)
self._active_page = title
2 changes: 1 addition & 1 deletion mac/gramps.accel
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@
# "win.TipOfDay": "",
# "win.Undo": "<Primary>z",
# "win.Redo": "<Primary><Shift>z",
# "win.ViewInCatagory": "",
# "win.ViewInCategory": "",
# "win.HomePerson": "<Alt>Home",
# "win.ExportTab": "",
# "win.Edit": "<Primary>Return",

0 comments on commit e660429

Please sign in to comment.