Adding buttons to the toolbar



Hi!

I was playing with epiphany-extensions and found that this can add a
button to the toolbar (it's kind of messy because it's a control-paste
from an etension but focus on the idea):

   def __init__(self):        #this is called only once
       shell = epiphany.ephy_shell_get_default()
       model = shell.get_toolbars_model(False)
       if model.get_name_flags('HideMenu') == 0:
           model.set_name_flags('HideMenu', 4) #EGG_TB_MODEL_NAME_KNOWN

   def _find_group(self, window):
       for group in window.get_ui_manager().get_action_groups():
           if group.get_name() == 'SpecialToolbarActions':
               return group
       else:
           raise AssertionError('Cannot find SpecialToolbarActions group')

   def attach(self, window): #this is the handler for attach_window
       actions = [('HideMenu', gtk.STOCK_GO_DOWN, 'Hi_de the menubar',
                    None, 'Hides the menubar', self._hmb_activate_cb)]
       group = self._find_group(window)
       group.add_actions(actions, window)

**********

Please note the lines:
       if model.get_name_flags('HideMenu') == 0:
           model.set_name_flags('HideMenu', 4) #EGG_TB_MODEL_NAME_KNOWN

If the (if) is removed, you will be able to add more and more clones
of your custom button to the toolbar after reloading the extension.

Now, the (if) avoids that... but if you remove the custom button from
the toolbar you will not have it available in the toolbar editor until
you reload the extension.

So my question is: How do I add a custom button to the toolbar that is
marked as unique so there can only be one copy of it and, of course,
it's not listed in the editor when it's already in the toolbar?

Greetings :)

--
"First they ignore you, then they laugh at you, then they fight you,
then you win"  -Ghandi

http://diego.aureal.com.pe



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]