Add an "Open Preferences" icon to the GUI display

there will be times when mine does not have net access. i can’t depend on it in a configuration sense. i’m also thinking of running all my apps in separate containers.

I am working on the often requested modification to make my new Plugins and Preferences icons configurable (hide/unhide) on the icon toolbar.

I have it working but it has taken a complex nested if/else to make it happen. All my attempts (so far) to use a simpler code has failed.

In the grampsgui.py there is existing code to turn certain menu items on.

def do_startup(self):
    Gtk.Application.do_startup(self)
    self.uimanager = UIManager(self, UIDEFAULT)
    if not is_quartz():
        self.uimanager.show_groups = ['OSX']
    self.uimanager.update_menu(init=True)

The code to turn menus on can only run once. In the code, menu items tagged as OSX will be turned on. The code will accept multiple tags. The challenge is having more tags added if conditions are true.

My nested if/else logic

    if not is_quartz():
        if config.get('interface.toolbar-plugin'):
            if config.get('interface.toolbar-preference'):
                self.uimanager.show_groups = ['OSX', 'PP1', 'PP2']
            else:	
                self.uimanager.show_groups = ['OSX', 'PP1']
        else:
            if config.get('interface.toolbar-preference'):
                self.uimanager.show_groups = ['OSX', 'PP2']
            else:
                self.uimanager.show_groups = ['OSX']
    else:
        if config.get('interface.toolbar-plugin'):
            if config.get('interface.toolbar-preference'):
                self.uimanager.show_groups = ['PP1', 'PP2']
            else:	
                self.uimanager.show_groups = ['PP1']
        else:
            if config.get('interface.toolbar-preference'):
                self.uimanager.show_groups = ['PP2']

    self.uimanager.update_menu(init=True)

It works but as I said ugly.

I have tried a more elegant method to no avail.

    s_show = ""
    if not is_quartz():
        s_show = "'OSX'"
    if config.get('interface.toolbar-plugin'):
        if s_show:
            s_show += ", 'PP1'"
        else:
            s_show = "'PP1'"				
    if config.get('interface.toolbar-preference'):
        if s_show:
            s_show += ", 'PP2'"
        else:
            s_show = "'PP2'"				
    self.uimanager.show_groups = ["%(s_show)s"]
    self.uimanager.update_menu(init=True)

Any help pointing out my error will be much appreciated. I am not a coder. I can only cut and paste and tweak what others have thought out how to do.

I think its something like that :\

s_show = []
if not is_quartz():
    s_show.append('OSX')
if config.get('interface.toolbar-plugin'):
    s_show.append('PP1')
if config.get('interface.toolbar-preference'):
    s_show.append('PP2')
if s_show:			
    self.uimanager.show_groups = s_show
    self.uimanager.update_menu(init=True)

Best regards.

2 Likes

Thank You!!!

So much more ‘elegant’ solution than the nested if/else. And it works without having to add the commas and the space between the appended options.

Thank You!!!