Exemplo n.º 1
0
	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())
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
	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)
Exemplo n.º 5
0
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')
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
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 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()
Exemplo n.º 10
0
	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())
Exemplo n.º 11
0
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
Exemplo n.º 12
0
	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)
Exemplo n.º 13
0
	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())
Exemplo n.º 14
0
    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())
Exemplo n.º 15
0
	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
Exemplo n.º 16
0
    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
Exemplo n.º 17
0
     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':
Exemplo n.º 18
0
#
# 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
Exemplo n.º 19
0
	def on_browse(self, *a):
		dir = XDG_DATA_HOME.subdir(('zim', 'templates'))
		self.ui.open_dir(dir)
Exemplo n.º 20
0
 def on_browse(self, *a):
     dir = XDG_DATA_HOME.subdir(('zim', 'templates'))
     self.ui.open_dir(dir)
Exemplo n.º 21
0
     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.
Exemplo n.º 22
0
 def on_browse(self, *a):
     dir = XDG_DATA_HOME.subdir(('zim', 'templates'))
     open_folder_prompt_create(self, dir)
Exemplo n.º 23
0
		def open_folder(args):
			got = LocalFolder(args[-1])
			want = LocalFolder(XDG_DATA_HOME.subdir('zim/templates').path)
			self.assertEqual(got, want)
Exemplo n.º 24
0
		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)