예제 #1
0
    def create(self, Name, **properties):
        '''Create a new custom tool

		@param Name: the name to show in the Tools menu
		@param properties: properties for the custom tool, e.g.:
		  - Comment
		  - Icon
		  - X-Zim-ExecTool
		  - X-Zim-ReadOnly
		  - X-Zim-ShowInToolBar

		@returns: a new L{CustomTool} object.
		'''
        properties['Type'] = 'X-Zim-CustomTool'
        dir = XDG_CONFIG_HOME.subdir('zim/customtools')
        tool = _create_application(dir,
                                   Name,
                                   '',
                                   klass=CustomTool,
                                   NoDisplay=False,
                                   **properties)

        # XXX - hack to ensure we link to configmanager
        file = ConfigManager.get_config_file('customtools/' +
                                             tool.file.basename)
        tool.file = file
        file.connect('changed', partial(self._on_tool_changed, tool))

        self._tools[tool.key] = tool
        self._names.append(tool.key)
        self._write_list()

        return tool
예제 #2
0
    def set_default_application(klass, 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 https://specifications.freedesktop.org/mime-apps-spec/latest/
        ## Version 1.0 dated 2 April 2014

        klass._defaults_app_cache[mimetype] = application

        if application is not None:
            if not isinstance(application, str):
                application = application.key

            if not application.endswith('.desktop'):
                application += '.desktop'

        file = XDG_CONFIG_HOME.file('mimeapps.list')
        _update_mimeapps_file(file,
                              '[Default Applications]',
                              mimetype,
                              application,
                              replace=True)
예제 #3
0
    def setUp(self):
        self.tmpdir = Dir(self.get_tmp_name())
        self.notebookdir = self.tmpdir.subdir('notebook')

        script = self.tmpdir.file('mount.py')
        script.write('''\
import os
import sys
notebook = sys.argv[1]
os.mkdir(notebook)
os.mkdir(notebook + '/foo')
for path in (
	notebook + "/notebook.zim",
	notebook + "/foo/bar.txt"
):
	fh = open(path, 'w')
	fh.write("")
	fh.close()
''')

        automount = XDG_CONFIG_HOME.file('zim/automount.conf')
        assert not automount.exists(), "Exists: %s" % automount
        automount.write('''\
[Path %s]
mount=%s %s
''' % (self.notebookdir.path, script.path, self.notebookdir.path))
예제 #4
0
	def setUp(self):
		folder = self.setUpFolder(mock=tests.MOCK_ALWAYS_REAL)
		self.notebookdir = folder.folder('notebook')

		script = folder.file('mount.py')
		script.write('''\
import os
import sys
notebook = sys.argv[1]
os.mkdir(notebook)
os.mkdir(notebook + '/foo')
for path in (
	notebook + "/notebook.zim",
	notebook + "/foo/bar.txt"
):
	fh = open(path, 'w')
	fh.write("")
	fh.close()
''')

		automount = XDG_CONFIG_HOME.file('zim/automount.conf')
		assert not automount.exists(), "Exists: %s" % automount
		automount.write('''\
[Path %s]
mount=%s %s
''' % (self.notebookdir.path, script.path, self.notebookdir.path))
예제 #5
0
	def setUp(self):
		self.tmpdir = Dir(self.get_tmp_name())
		self.notebookdir = self.tmpdir.subdir('notebook')

		script = self.tmpdir.file('mount.py')
		script.write('''\
import os
import sys
notebook = sys.argv[1]
os.mkdir(notebook)
os.mkdir(notebook + '/foo')
for path in (
	notebook + "/notebook.zim",
	notebook + "/foo/bar.txt"
):
	fh = open(path, 'w')
	fh.write("")
	fh.close()
''')

		automount = XDG_CONFIG_HOME.file('zim/automount.conf')
		assert not automount.exists()
		automount.write('''\
[Path %s]
mount=%s %s
''' % (self.notebookdir.path, script.path, self.notebookdir.path))
예제 #6
0
    def create(self, Name, **properties):
        '''Create a new custom tool

		@param Name: the name to show in the Tools menu
		@param properties: properties for the custom tool, e.g.:
		  - Comment
		  - Icon
		  - X-Zim-ExecTool
		  - X-Zim-ReadOnly
		  - X-Zim-ShowInToolBar

		@returns: a new L{CustomTool} object.
		'''
        properties['Type'] = 'X-Zim-CustomTool'
        dir = XDG_CONFIG_HOME.subdir('zim/customtools')
        tool = _create_application(dir,
                                   Name,
                                   '',
                                   klass=CustomTool,
                                   NoDisplay=False,
                                   **properties)
        self.tools[tool.key] = tool
        self.names.append(tool.key)
        self._write_list()

        return tool
예제 #7
0
    def create(self, Name, **properties):
        '''Create a new custom tool

        @param Name: the name to show in the Tools menu
        @param properties: properties for the custom tool, e.g.:
          - Comment
          - Icon
          - X-Zim-ExecTool
          - X-Zim-ReadOnly
          - X-Zim-ShowInToolBar

        @returns: a new L{CustomTool} object.
        '''
        properties['Type'] = 'X-Zim-CustomTool'
        dir = XDG_CONFIG_HOME.subdir('zim/customtools')
        tool = _create_application(dir, Name, '', klass=CustomTool, NoDisplay=False, **properties)
        self.tools[tool.key] = tool
        self.names.append(tool.key)
        self._write_list()

        return tool
예제 #8
0
def _create_application(dir, basename, Name, Exec, NoDisplay=True, **param):
    file = dir.file(basename)
    i = 0
    while file.exists():
        assert i < 1000, 'BUG: Infinite loop ?'
        i += 1
        basename = basename[:-8] + '-' + str(i) + '.desktop'
        file = dir.file(basename)

    entry = DesktopEntryFile(file)
    entry.update(Type='Application',
                 Version=1.0,
                 NoDisplay=NoDisplay,
                 Name=Name,
                 Exec=Exec,
                 **param)

    assert entry.isvalid(), 'BUG: created invalid desktop entry'
    entry.write()

    if param.get('MimeType'):
        mimetype = param.get('MimeType')

        # Update mimeapps
        defaults = XDG_CONFIG_HOME.file('mimeapps.list')
        _update_mimeapps_file(defaults,
                              '[Added Associations]',
                              mimetype,
                              basename,
                              replace=False)

        # Update mimetype cache
        cache = dir.file('mimeinfo.cache')
        _update_mimeapps_file(cache,
                              '[MIME Cache]',
                              mimetype,
                              basename,
                              replace=False)

    return entry
예제 #9
0
파일: main.py 프로젝트: Jam71/Zim-QDA
 def profile_file(self, name):
     return XDG_CONFIG_HOME.file("zim/profiles/%s.conf" % name.lower())