def create_helper_application(type, Name, Exec, **param): '''Like create_mime_application() but defines a zim specific helper. Type can e.g. be 'web_browser', 'file_browser' or 'email_client'. ''' dir = XDG_DATA_HOME.subdir('zim/applications') param['X-Zim-AppType'] = type return _create_application(dir, Name, Exec, **param)
def _application_dirs(): # Generator for application directories, first check zim specific paths, # then general applications for dir in data_dirs('applications'): yield dir yield XDG_DATA_HOME.subdir('applications') for dir in XDG_DATA_DIRS: yield dir.subdir('applications')
def setUp(self): folder = LocalFolder(XDG_DATA_HOME.subdir('zim/templates').path) assert 'tests/tmp' in folder.path.replace('\\', '/') if folder.exists(): folder.remove_children() for name, content in ( ('html/foo_test.html', 'Test 123\n'), ('html/bar_test.html', 'Test 123\n'), ): folder.file(name).write(content)
def create_application(mimetype, Name, Exec, **param): '''Creates a desktop entry file for a new usercreated desktop entry which defines a custom command to handle a certain file type. Returns the DesktopEntryFile object with some sensible defaults for a user created application entry. To know the key to retrieve this application later look at the 'key' property of the entry object. ''' dir = XDG_DATA_HOME.subdir('applications') param['MimeType'] = mimetype file = _create_application(dir, Name, Exec, **param) set_default_application(mimetype, key) return file
def setUp(self): folder = LocalFolder(XDG_DATA_HOME.subdir('zim/templates').path) assert 'tests/tmp' in folder.path.replace('\\', '/') if folder.exists(): folder.remove_children() for name, content in ( ('html/foo_test.html', 'Test 123\n'), ('html/bar_test.html', 'Test 123\n'), ): folder.file(name).write(content) manager = ApplicationManager() entry = manager.create('text/plain', 'test', 'test') manager.set_default_application('text/plain', entry)
def testListTemplates(self): '''Assert list templates still works with resource folders present''' import shutil from zim.config import XDG_DATA_HOME from zim.templates import list_templates, get_template # Make sure our template with resources is first in line datahome = XDG_DATA_HOME.subdir('zim/templates/') assert not datahome.exists() shutil.copytree(self.data, datahome.path) for name, basename in list_templates('html'): if name == 'Default': self.assertEqual(basename, 'Default.html') template = get_template('html', 'Default') self.assertEqual(template.file, datahome.file('html/Default.html').path) self.assertEqual(template.resources_dir, datahome.subdir('html/Default')) self.assertTrue(template.resources_dir.exists())
def create(mimetype, Name, Exec, **param): '''Create a new usercreated desktop entry which defines a custom command to handle a certain file type. Note that the name under which this definition is stored is not the same as C{Name}. Check the 'C{key}' attribute of the returned object if you want the name to retrieve this application later. @param mimetype: the file mime-type to handle with this command @param Name: the name to show in e.g. the "Open With.." menu @param Exec: the command to run as string (will be split on whitespace, so quote arguments that may contain a space). @param param: any additional keys for the desktop entry @returns: the L{DesktopEntryFile} object with some sensible defaults for a user created application entry. ''' dir = XDG_DATA_HOME.subdir('applications') param['MimeType'] = mimetype file = _create_application(dir, Name, Exec, **param) return file
def on_browse(self, *a): dir = XDG_DATA_HOME.subdir(('zim', 'templates')) self.ui.open_dir(dir)
def on_browse(self, *a): dir = XDG_DATA_HOME.subdir(('zim', 'templates')) open_folder_prompt_create(self, dir)
def open_folder(args): got = LocalFolder(args[-1]) want = LocalFolder(XDG_DATA_HOME.subdir('zim/templates').path) self.assertEqual(got, want)
# # Originally this added to the C{__path__} folders based on C{sys.path} # however this leads to conflicts when multiple zim versions are # installed. By switching to XDG_DATA_HOME this conflict is removed # by separating custom plugins and default plugins from other versions. # Also this switch makes it easier to have a single instruction for # users where to put custom plugins. for dir in data_dirs('plugins'): __path__.append(dir.path) __path__.append(__path__.pop(0)) # reshuffle real module path to the end #~ print "PLUGIN PATH:", __path__ PLUGIN_FOLDER = XDG_DATA_HOME.subdir('zim/plugins') class PluginManager(ConnectorMixin, collections.Mapping): '''Manager that maintains a set of active plugins This class is the interface towards the rest of the application to load/unload plugins and to let plugins extend specific application objects. All object that want to instantiate new objects that are extendable need a reference to the plugin manager object that is instantiated when the application starts. When you instatiate a new object and want to present it for plugin extension, call the L{extend()} method. This object behaves as a dictionary with plugin object names as
RuntimeError: could not create GtkClipboard object """ class Dialog: pass from zim.formats import CHECKED_BOX, UNCHECKED_BOX from zim.main import NotebookCommand from zim.main.command import GtkCommand from zim.notebook import build_notebook, Path as ZimPath from zim.plugins import PluginClass from zim.gui.mainwindow import MainWindowExtension logger = logging.getLogger('zim.plugins.googletasks') CACHE_FILE = "googletasks.cache" WORKDIR = str(XDG_DATA_HOME.subdir(('zim', 'plugins'))) CLIENT_SECRET_FILE = os.path.join(WORKDIR, 'googletasks_client_id.json') APPLICATION_NAME = 'googletasks2zim' TASK_ANCHOR_SYMBOL = u"\u270b" taskAnchorTreeRe = re.compile(r'(\[.\]\s)?\[\[gtasks://([^|]*)\|' + TASK_ANCHOR_SYMBOL + r'\]\]\s?(.*)') start_date_in_title = re.compile(r'(.*)>(\d{4}-\d{2}(-\d{2})?)(.*)') # (_\{//)? (//})? INVALID_DAY = "N/A" class GoogletasksPlugin(PluginClass): plugin_info = { 'name': _('Google Tasks'), 'description': _('''\ Connects to your default Google Tasks lists. Append today's tasks to your Home file. At first run, it appends today's tasks; next, it'll append new tasks added since last synchronisation every Zim startup (and every day, when set in anacron). Every task should be imported only once, unless changed on the server.