本文整理汇总了Python中GTG.core.plugins.engine.PluginEngine.register_api方法的典型用法代码示例。如果您正苦于以下问题:Python PluginEngine.register_api方法的具体用法?Python PluginEngine.register_api怎么用?Python PluginEngine.register_api使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GTG.core.plugins.engine.PluginEngine
的用法示例。
在下文中一共展示了PluginEngine.register_api方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TaskEditor
# 需要导入模块: from GTG.core.plugins.engine import PluginEngine [as 别名]
# 或者: from GTG.core.plugins.engine.PluginEngine import register_api [as 别名]
#.........这里部分代码省略.........
self.textview.set_add_tag_callback(task.add_tag)
self.textview.set_remove_tag_callback(task.remove_tag)
self.textview.save_task_callback(self.light_save)
texte = self.task.get_text()
title = self.task.get_title()
# the first line is the title
self.textview.set_text("%s\n" % title)
# we insert the rest of the task
if texte:
self.textview.insert("%s" % texte)
else:
# If not text, we insert tags
if tags:
for t in tags:
self.textview.insert_text("%s, " % t.get_name())
self.textview.insert_text("\n")
# If we don't have text, we still need to insert subtasks if any
subtasks = task.get_children()
if subtasks:
self.textview.insert_subtasks(subtasks)
# We select the title if it's a new task
if thisisnew:
self.textview.select_title()
else:
self.task.set_to_keep()
self.textview.modified(full=True)
self.window.connect("destroy", self.destruction)
self.calendar.connect("date-changed", self.on_date_changed)
# plugins
self.pengine = PluginEngine()
self.plugin_api = PluginAPI(self.req, self.vmanager, self)
self.pengine.register_api(self.plugin_api)
self.pengine.onTaskLoad(self.plugin_api)
# Putting the refresh callback at the end make the start a lot faster
self.textview.refresh_callback(self.refresh_editor)
self.refresh_editor()
self.textview.grab_focus()
# restoring size and position, spatial tasks
if self.config is not None:
tid = self.task.get_id()
if self.config.has_section(tid):
if self.config.has_option(tid, "position"):
pos_x, pos_y = self.config.get(tid, "position")
self.move(int(pos_x), int(pos_y))
if self.config.has_option(tid, "size"):
width, height = self.config.get(tid, "size")
self.window.resize(int(width), int(height))
self.textview.set_editable(True)
self.window.show()
# Define accelerator-keys for this dialog
# TODO: undo/redo
def init_accelerators(self):
agr = Gtk.AccelGroup()
self.window.add_accel_group(agr)
# Escape and Ctrl-W close the dialog. It's faster to call close
# directly, rather than use the close button widget
key, modifier = Gtk.accelerator_parse('Escape')
agr.connect(key, modifier, Gtk.AccelFlags.VISIBLE, self.close)
示例2: Manager
# 需要导入模块: from GTG.core.plugins.engine import PluginEngine [as 别名]
# 或者: from GTG.core.plugins.engine.PluginEngine import register_api [as 别名]
class Manager(GObject.GObject):
__object_signal__ = (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE,
(GObject.TYPE_PYOBJECT,))
__object_string_signal__ = (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE,
(GObject.TYPE_PYOBJECT, GObject.TYPE_STRING, ))
__gsignals__ = {'tasks-deleted': __object_signal__,
'task-status-changed': __object_string_signal__,
}
# init ##################################################################
def __init__(self, req):
GObject.GObject.__init__(self)
self.req = req
self.config_obj = self.req.get_global_config()
self.browser_config = self.config_obj.get_subconfig("browser")
self.plugins_config = self.config_obj.get_subconfig("plugins")
self.task_config = self.config_obj.get_taskconfig()
# Editors
# This is the list of tasks that are already opened in an editor
# of course it's empty right now
self.opened_task = {}
self.browser = None
self.__start_browser_hidden = False
self.gtk_terminate = False # if true, the gtk main is not started
# if true, closing the last window doesn't quit GTG
# (GTG lives somewhere else without GUI, e.g. notification area)
self.daemon_mode = False
# Shared clipboard
self.clipboard = clipboard.TaskClipboard(self.req)
# Initialize Timer
self.config = self.req.get_config('browser')
self.timer = Timer(self.config)
# Browser (still hidden)
self.browser = TaskBrowser(self.req, self)
self.__init_plugin_engine()
if not self.__start_browser_hidden:
self.show_browser()
# Deletion UI
self.delete_dialog = None
# Preferences and Backends windows
# Initialize dialogs
self.preferences = PreferencesDialog(self.req, self)
self.plugins = PluginsDialog(self.config_obj)
self.edit_backends_dialog = None
# Tag Editor
self.tag_editor_dialog = None
# DBus
DBusTaskWrapper(self.req, self)
Log.debug("Manager initialization finished")
def __init_plugin_engine(self):
self.pengine = PluginEngine(GTG.PLUGIN_DIR)
# initializes the plugin api class
self.plugin_api = PluginAPI(self.req, self)
self.pengine.register_api(self.plugin_api)
# checks the conf for user settings
try:
plugins_enabled = self.plugins_config.get("enabled")
except configparser.Error:
plugins_enabled = []
for plugin in self.pengine.get_plugins():
plugin.enabled = plugin.module_name in plugins_enabled
# initializes and activates each plugin (that is enabled)
self.pengine.activate_plugins()
# Browser ##############################################################
def open_browser(self):
if not self.browser:
self.browser = TaskBrowser(self.req, self)
# notify user if backup was used
backend_dic = self.req.get_all_backends()
for backend in backend_dic:
if backend.get_name() == "backend_localfile" and \
backend.used_backup():
backend.notify_user_about_backup()
Log.debug("Browser is open")
# FIXME : the browser should not be the center of the universe.
# In fact, we should build a system where view can register themselves
# as "stay_alive" views. As long as at least one "stay_alive" view
# is registered, gtg keeps running. It quit only when the last
# "stay_alive view" is closed (and then unregistered).
# Currently, the browser is our only "stay_alive" view.
def close_browser(self, sender=None):
self.hide_browser()
# may take a while to quit
self.quit()
#.........这里部分代码省略.........
示例3: Manager
# 需要导入模块: from GTG.core.plugins.engine import PluginEngine [as 别名]
# 或者: from GTG.core.plugins.engine.PluginEngine import register_api [as 别名]
class Manager(object):
############## init #####################################################
def __init__(self, req):
self.req = req
self.config_obj = self.req.get_global_config()
self.config = self.config_obj.conf_dict
self.task_config = self.config_obj.task_conf_dict
# Editors
self.opened_task = {} # This is the list of tasks that are already
# opened in an editor of course it's empty
# right now
self.browser = None
self.__start_browser_hidden = False
self.gtk_terminate = False #if true, the gtk main is not started
#Shared clipboard
self.clipboard = clipboard.TaskClipboard(self.req)
#Browser (still hidden)
self.browser = TaskBrowser(self.req, self)
self.__init_plugin_engine()
if not self.__start_browser_hidden:
self.show_browser()
#Deletion UI
self.delete_dialog = None
#Preferences and Backends windows
# Initialize dialogs
self.preferences_dialog = None
self.edit_backends_dialog = None
#DBus
DBusTaskWrapper(self.req, self)
Log.debug("Manager initialization finished")
def __init_plugin_engine(self):
self.pengine = PluginEngine(GTG.PLUGIN_DIR)
# initializes the plugin api class
self.plugin_api = PluginAPI(self.req, self)
self.pengine.register_api(self.plugin_api)
# checks the conf for user settings
try:
plugins_enabled = self.config["plugins"]["enabled"]
except KeyError:
plugins_enabled = []
for plugin in self.pengine.get_plugins():
plugin.enabled = plugin.module_name in plugins_enabled
# initializes and activates each plugin (that is enabled)
self.pengine.activate_plugins()
############## Browser #################################################
def open_browser(self):
if not self.browser:
self.browser = TaskBrowser(self.req, self)
Log.debug("Browser is open")
#FIXME : the browser should not be the center of the universe.
# In fact, we should build a system where view can register themselves
# as "stay_alive" views. As long as at least one "stay_alive" view
# is registered, gtg keeps running. It quit only when the last
# "stay_alive view" is closed (and then unregistered).
# Currently, the browser is our only "stay_alive" view.
def close_browser(self,sender=None):
self.hide_browser()
#may take a while to quit
self.quit()
def hide_browser(self,sender=None):
self.browser.hide()
def iconify_browser(self,sender=None):
self.browser.iconify()
def show_browser(self,sender=None):
self.browser.show()
def is_browser_visible(self,sender=None):
return self.browser.is_visible()
def get_browser(self):
#used by the plugin api to hook in the browser
return self.browser
def start_browser_hidden(self):
self.__start_browser_hidden = True
################# Task Editor ############################################
def get_opened_editors(self):
'''
Returns a dict of task_uid -> TaskEditor, one for each opened editor
window
#.........这里部分代码省略.........
示例4: __init__
# 需要导入模块: from GTG.core.plugins.engine import PluginEngine [as 别名]
# 或者: from GTG.core.plugins.engine.PluginEngine import register_api [as 别名]
#.........这里部分代码省略.........
self.textview.set_add_tag_callback(task.add_tag)
self.textview.set_remove_tag_callback(task.remove_tag)
self.textview.save_task_callback(self.light_save)
texte = self.task.get_text()
title = self.task.get_title()
#the first line is the title
self.textview.set_text("%s\n"%title)
#we insert the rest of the task
if texte :
self.textview.insert("%s"%texte)
else :
#If not text, we insert tags
if tags :
for t in tags :
self.textview.insert_text("%s, "%t.get_name())
self.textview.insert_text("\n")
#If we don't have text, we still need to insert subtasks if any
subtasks = task.get_children()
if subtasks :
self.textview.insert_subtasks(subtasks)
#We select the title if it's a new task
if thisisnew :
self.textview.select_title()
else :
self.task.set_to_keep()
self.textview.modified(full=True)
self.window.connect("destroy", self.destruction)
self.calendar.connect("date-changed", self.on_date_changed)
# plugins
self.pengine = PluginEngine()
self.plugin_api = PluginAPI(self.req, self.vmanager, self)
self.pengine.register_api(self.plugin_api)
self.pengine.onTaskLoad(self.plugin_api)
#Putting the refresh callback at the end make the start a lot faster
self.textview.refresh_callback(self.refresh_editor)
self.refresh_editor()
self.textview.grab_focus()
#restoring size and position, spatial tasks
if self.config :
tid = self.task.get_id()
if tid in self.config:
if "position" in self.config[tid]:
pos = self.config[tid]["position"]
self.move(pos[0],pos[1])
#print "restoring position %s %s" %(pos[0],pos[1])
if "size" in self.config[tid]:
size = self.config[tid]["size"]
#print "size %s - %s" %(str(size[0]),str(size[1]))
#this eval(str()) is a ugly (!) hack to accept both int and str
#FIXME: Fix this!
self.window.resize(eval(str(size[0])),eval(str(size[1])))
self.textview.set_editable(True)
#Connection for the update
self.req.connect('task-modified',self.task_modified)
self.window.show()
#FIXME: avoid to update to many time when we modify from the editor itself
def task_modified(self,sender,tid):
self.refresh_editor(refreshtext=True)