def testRemoveTemplate(self): dialog = TemplateEditorDialog(None) select_by_name(dialog.view, 'foo_test') file = LocalFile(XDG_DATA_HOME.file('zim/templates/html/foo_test.html').path) self.assertTrue(file.exists()) dialog.on_delete() self.assertFalse(file.exists())
def set_default_application(mimetype, application): '''Set the default application to open a file with a specific mimetype. Updates the C{applications/defaults.list} file. As a special case when you set the default to C{None} it will remove the entry from C{defauts.list} allowing system defaults to be used again. @param mimetype: the mime-type of the file (e.g. "text/html") @param application: an L{Application} object or C{None} ''' ## Based on logic from xdg-mime make_default_generic() ## Obtained from http://portland.freedesktop.org/wiki/ (2012-05-31) ## ## See comment in get_default_application() if application is not None: if not isinstance(application, basestring): application = application.key if not application.endswith('.desktop'): application += '.desktop' default_file = XDG_DATA_HOME.file('applications/defaults.list') if default_file.exists(): lines = default_file.readlines() lines = [l for l in lines if not l.startswith(mimetype + '=')] else: lines = ['[Default Applications]\n'] if application: lines.append('%s=%s\n' % (mimetype, application)) default_file.writelines(lines)
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 refresh(self): model = self.get_model() model.clear() for category in list_template_categories(): parent = model.append(None, (category, None, None)) for name, basename in list_templates(category): base = XDG_DATA_HOME.file(('zim', 'templates', category, basename)) default = data_file(('templates', category, basename)) # None if not existing #~ print '>>>', name, base, default model.append(parent, (name, base, default)) self.expand_all()
def refresh(self): model = self.get_model() model.clear() for category in list_template_categories(): parent = model.append(None, (category, None, None)) for name, basename in list_templates(category): base = XDG_DATA_HOME.file(('zim', 'templates', category, basename)) default = data_file(('templates', category, basename)) # None if not existing #~ print('>>>', name, base, default) model.append(parent, (name, base, default)) self.expand_all()
def testCopyTemplate(self): dialog = TemplateEditorDialog(None) select_by_name(dialog.view, 'foo_test') def do_copy(dialog): dialog.set_input(name='new_foo_test') dialog.assert_response_ok() with tests.DialogContext(do_copy): dialog.on_copy() file = LocalFile(XDG_DATA_HOME.file('zim/templates/html/new_foo_test.html').path) self.assertTrue(file.exists())
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
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.folder(('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':
# # 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
def on_browse(self, *a): dir = XDG_DATA_HOME.subdir(('zim', 'templates')) self.ui.open_dir(dir)
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.
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)
def open_file(args): got = LocalFile(args[-1]) want = LocalFile(XDG_DATA_HOME.file('zim/templates/html/foo_test.html').path) self.assertEqual(got, want)