[Geany-Devel] Toggle menu and status bars

Colomban Wendling lists.ban at xxxxx
Mon Jul 4 16:23:16 UTC 2016


Le 02/07/2016 à 11:08, Vasiliy Faronov a écrit :
> Hi,
> 
> Most of the time, when using Geany, I don't need the menu and status
> bars; they are just noise. But occasionally I want to check the status
> bar (e.g. for the line/column number) or browse the menu. So I want to
> toggle their visibility with a keystroke.
> 
> I wrote a simple plugin for that: https://github.com/vfaronov/geany-togglebars
> 
> The problem is, the menu and status bars are not exposed in
> geany.main_widgets, so I have to find them manually, which makes the
> plugin brittle as it relies on a specific window layout.
> 
> Perhaps there is a better way to do it?

You could use a more solid resolve_widget() function, that doesn't rely
on the layout, something like that:

> def resolve_widget(widget, expected_type):
>     if isinstance(widget, expected_type):
>         return widget
>     elif isinstance(widget, Gtk.Container):
>         for child in widget.get_children():
>             ret = resolve_widget(child, expected_type)
>             if ret:
>                 return ret
>     return None

Also, your plugin is a bit dangerous for the new user if I read it
correctly: you do not bind the keybinding by default (which is good),
but you hide the menubar by default.  This means that the user enabling
your plugin might be totally lost with no way of recovering his/her
menubar to even access the preferences and set a keybinding.

I guess you did that because you didn't wanna bother about a
configuration file for saving the state for such a little thing you
probably didn't mean to publish so much, but if you do want to publish
it it'd be important to resolve this.

Regards,
Colomban


More information about the Devel mailing list