zim-wiki team mailing list archive
-
zim-wiki team
-
Mailing list archive
-
Message #04195
Re: how to load another plugin's settings
Ah yes you are right. Will look into a plugin collaboration interface using
actions.
Regards,
Jaap
On Fri, Mar 31, 2017, 17:52 Will Foran <will.foran@xxxxxxxxx> wrote:
> This is great; thanks!
>
> Unfortunately, I don't see the journal plugin public methods in the
> actiongroup list! Maybe I'm looking in the wrong object? [0]
>
> But your suggestion lead me to a working calendar plugin reference (albeit
> a pretty gross kluge)
>
> calplug = [
> x[0] for x in self.window.ui.plugins._connected_signals.values()
> if "CalendarPlugin" in str(type(x[0]()))
> ]
> if(len(calplug)<=0): raise Exception("enable Journal plugin")
> calplug = calplug[0]()
> path = calplug.path_from_date(offset_time)
>
>
>
>
> [0]
> for ag in [self.window, self.window.ui]: print( [ x.get_name() for x in
> ag.actiongroup.list_actions() ] )
>
> ['set_toolbar_text_only', 'set_toolbar_icons_tiny',
> 'set_toolbar_icons_and_text', 'set_pathbar_none', 'toggle_statusbar',
> 'toggle_fullscreen', 'set_toolbar_icons_only', 'set_pathbar_history',
> 'toggle_panes', 'set_pathbar_recent_changed', 'set_pathbar_path',
> 'set_toolbar_icons_large', 'set_pathbar_recent', 'set_toolbar_icons_small',
> 'show_all_panes', 'toggle_toolbar', 'toggle_readonly']
>
> ['insert_menu', 'show_search', 'edit_menu', 'show_help_faq', 'show_about',
> 'new_page', 'toolbar_menu', 'open_page_parent', 'view_menu', 'attach_file',
> 'show_server_gui', 'search_menu', 'save_page', 'open_page_previous',
> 'delete_page', 'open_page_back_alt1', 'open_page_back', 'show_properties',
> 'open_page_home', 'file_menu', 'show_templateeditor', 'help_menu',
> 'tools_menu', 'show_preferences', 'open_attachments_folder', 'open_page',
> 'open_notebook_folder', 'show_export', 'format_menu', 'edit_page_source',
> 'go_menu', 'open_page_child', 'quit', 'open_new_window',
> 'show_search_backlinks', 'copy_location', 'import_page', 'save_copy',
> 'show_help_bugs', 'show_help', 'email_page', 'reload_page',
> 'open_document_folder', 'rename_page', 'open_page_next',
> 'manage_custom_tools', 'move_page', 'open_document_root', 'reload_index',
> 'new_sub_page', 'open_page_forward', 'show_recent_changes', 'pathbar_menu',
> 'show_help_keys', 'open_notebook', 'close', 'open_page_forward_alt1']
>
>
>
>
> On Fri, Mar 31, 2017 at 3:25 AM, Jaap Karssenberg <
> jaap.karssenberg@xxxxxxxxx> wrote:
>
> Hi Will,
>
> For the first question, I think importing the other plugin's preferences
> is not the right way to go. What you want is access to the "go_page_today"
> action. Let the journal plugin figure out how to do that. This way you are
> much more robust to changes in how the journal plugin works internally.
>
> Probably should have a formal interface to access actions defined by
> another plugin, but this will work:
>
> go_page_today_action
> = window.ui.actiongroup.get_action('go_page_today')
> go_page_today_action.activate()
> page = window.page
>
> Thus you only use the "public interface" of the plugin that shows in the
> user interface and automate that. A secondary benefit is that you don;t
> even have to know who provides this action. If someone develops an
> alternative plugin that supports this action, your plugin will still
> collaborate.
>
> If the journal plugin is not loaded, this will fail. Probably it is good
> to catch that case and show an popup that tells the user to also enable the
> other plugin.
>
> For debugging I myself just throw in a bunch of "print" statements. Of
> course unittests help to reduce the amount of re-starting you need to do to
> check functions :)
>
> Regards,
>
> Jaap
>
>
> On Thu, Mar 30, 2017 at 10:02 PM Will Foran <willforan+ubuntu@xxxxxxxxx>
> wrote:
>
> I'm trying extend the Now Button
> <https://github.com/Osndok/zim-plugin-nowbutton/blob/master/nowbutton.py>
> plugin to use the same path the journal plugin uses by calling
> path_from_date.
>
> I haven't figured out how to respect/load the granularity setting from
> preferences.conf. I am trying to explicitly set it using PluginManager or
> ConfigManager. Neither with success
>
> # get cal plug object a la tests/calendar.py
> calplugklass = PluginManager.get_plugin_class('calendar')
> calplug = calplugklass()
>
> prefs=calplug.config.get_config_dict('<profile>/preferences.conf')
> # ConfigManagerINIConfigFile w/ only with key as "CalendarPlugin", has default plugin vals (e.g. path=:Journal)
>
> # OR #
>
> prefs=zim.config.ConfigManager().get_config_dict('<profile>/preferences.conf')
> # ConfigManagerINIConfigFile has all sections of prefs.conf as keys, but ConfigDict's are all empty
>
>
>
> # want to set the cal props like
> calplug.preferences = prefs['CalendarPlugin']
> # so granularity respected by the calendar plugin is reflected here too
> cur_date_page = calplug.path_from_date(...)
>
> In the first pluginmanger attempt, the default values are seen not the
> values in my preferences.conf
> in the second attempt with configmanger, I see all the sections in my
> .conf (included a bogus [FooBar] section) but all the dictionaries are
> empty.
>
>
> I think I am missing something obvious. Any hints?
>
>
> As an aside, what is the best way to debug zim plugins? Currently, I make
> a change, sprinkling in raise Exception(prefs) and restart zim.
>
>
> Thanks!
> Will
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~zim-wiki
> Post to : zim-wiki@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~zim-wiki
> More help : https://help.launchpad.net/ListHelp
>
>
>
References