Exemplo n.º 1
0
    def _run_main_loop(self, cmd):
        # Run for the 1st gtk command in a primary process,
        # but can still be standalone process
        import gtk, gobject
        gobject.threads_init()

        from zim.gui.widgets import gtk_window_set_default_icon
        gtk_window_set_default_icon()

        zim.errors.set_use_gtk(True)
        self._setup_signal_handling()

        if self._standalone:
            logger.debug('Starting standalone process')
        else:
            logger.debug('Starting primary process')
            self._daemonize()
            _ipc_start_listening(self.run)

        w = cmd.run()
        if w is not None:
            self.add_window(w)

        while self._windows:
            gtk.main()

            for toplevel in list(self._windows):
                try:
                    toplevel.destroy()
                    while gtk.events_pending():
                        gtk.main_iteration(block=False)
                except:
                    logger.exception('Exception while destroying window')
                    self.remove_window(toplevel)  # force removal
Exemplo n.º 2
0
def main(notebook=None, port=8080, public=True, **opts):
	import zim.notebook
	if notebook:
		notebook, path = zim.notebook.resolve_notebook(notebook)

	gtk_window_set_default_icon()

	window = ServerWindow(notebook, port, public, **opts)
	window.show_all()
	gtk.main()
Exemplo n.º 3
0
    def _run_main_loop(self, cmd):
        # Run for the 1st gtk command in a primary process,
        # but can still be standalone process
        import gtk
        import gobject

        #######################################################################
        # WARNING: commented out "gobject.threads_init()" because it leads to
        # various segfaults on linux. See github issue #7
        # However without this init, gobject does not properly release the
        # python GIL during C calls, so threads may block while main loop is
        # waiting. Thus threads become very slow and unpredictable unless we
        # actively monitor them from the mainloop, causing python to run
        # frequently. So be very carefull relying on threads.
        # Re-evaluate when we are above PyGObject 3.10.2 - threading should
        # wotk bettter there even without this statement. (But even then,
        # no Gtk calls from threads, just "gobject.idle_add()". )
        # Kept for windows, because we need thread to run ipc listener, and no
        # crashes observed there.
        if os.name == 'nt':
            gobject.threads_init()
        #######################################################################

        from zim.gui.widgets import gtk_window_set_default_icon
        gtk_window_set_default_icon()

        zim.errors.set_use_gtk(True)
        self._setup_signal_handling()

        if self._standalone:
            logger.debug('Starting standalone process')
        else:
            logger.debug('Starting primary process')
            self._daemonize()
            if not _ipc_start_listening(self._handle_incoming):
                logger.warn(
                    'Failure to setup socket, falling back to "--standalone" mode'
                )
                self._standalone = True

        w = cmd.run()
        if w is not None:
            self.add_window(w)

        while self._windows:
            gtk.main()

            for toplevel in list(self._windows):
                try:
                    toplevel.destroy()
                except:
                    logger.exception('Exception while destroying window')
                    self.remove_window(toplevel)  # force removal
Exemplo n.º 4
0
    def run(self):
        if self.opts.get('help'):
            print usagehelp  # TODO handle this in Command base class
        else:
            gtk_window_set_default_icon()

            if 'notebook' in self.opts:
                notebook = resolve_notebook(self.opts['notebook'])
            else:
                notebook = None

            dialog = QuickNoteDialog(None,
                                     notebook=notebook,
                                     namespace=self.opts.get('namespace'),
                                     basename=self.opts.get('basename'),
                                     append=self.opts.get('append'),
                                     text=self.get_text(),
                                     template_options=self.template_options,
                                     attachments=self.opts.get('attachments'))
            dialog.run()
Exemplo n.º 5
0
	def run(self):
		if self.opts.get('help'):
			print usagehelp # TODO handle this in Command base class
		else:
			gtk_window_set_default_icon()

			if 'notebook' in self.opts:
				notebook = resolve_notebook(self.opts['notebook'])
			else:
				notebook = None

			dialog = QuickNoteDialog(None,
				notebook=notebook,
				namespace=self.opts.get('namespace'),
				basename=self.opts.get('basename'),
				append=self.opts.get('append'),
				text=self.get_text(),
				template_options=self.template_options,
				attachments=self.opts.get('attachments')
			)
			dialog.run()
Exemplo n.º 6
0
def main(notebookinfo=None, port=8080, public=True, **opts):
    gtk_window_set_default_icon()
    window = ServerWindow(notebookinfo, port, public, **opts)
    window.show_all()
    gtk.main()
Exemplo n.º 7
0
Arquivo: server.py Projeto: gdw2/zim
def main(notebookinfo=None, port=8080, public=True, **opts):
	gtk_window_set_default_icon()
	window = ServerWindow(notebookinfo, port, public, **opts)
	window.show_all()
	gtk.main()
Exemplo n.º 8
0
 def main(self):
     # Set window icon in case we open the notebook dialog
     gtk_window_set_default_icon()
     gtk.main()
Exemplo n.º 9
0
def main(*args):
	options = {}
	template_options = {}
	for arg in args:
		if arg.startswith('option:'):
			arg = arg[7:]
			dict = template_options
		else:
			dict = options

		if '=' in arg:
			key, value = arg.split('=', 1)
			dict[key] = value
		else:
			dict[arg] = True
	#~ print 'OPTIONS:', options, template_options

	if 'help' in options:
		print usagehelp
		return

	if 'notebook' in options:
		notebook, page = resolve_notebook(options['notebook'])
	else:
		notebook = None

	if 'append' in options:
		if options['append'].lower() == 'true':
			options['append'] = True
		else:
			options['append'] = False

	if 'input' in options:
		if options['input'] == 'stdin':
			import sys
			text = sys.stdin.read()
		elif options['input'] == 'clipboard':
			text = \
				SelectionClipboard.get_text() \
				or Clipboard.get_text()
	else:
		text = options.get('text')

	if text and options.get('encoding'):
		if options['encoding'] == 'base64':
			import base64
			text = base64.b64decode(text)
		elif options['encoding'] == 'url':
			from zim.parsing import url_decode, URL_ENCODE_DATA
			text = url_decode(text, mode=URL_ENCODE_DATA)
		else:
			raise AssertionError, 'Unknown encoding: %s' % options['encoding']

	if text and not isinstance(text, unicode):
		text = text.decode('utf-8')

	icon = data_file('zim.png').path
	gtk_window_set_default_icon()

	dialog = QuickNoteDialog(None,
		notebook,
		options.get('namespace'), options.get('basename'),
		options.get('append'),
		text,
		template_options,
		options.get('attachments')
	)
	dialog.run()
Exemplo n.º 10
0
def main(*args):
    options = {}
    template_options = {}
    for arg in args:
        if arg.startswith("option:"):
            arg = arg[7:]
            dict = template_options
        else:
            dict = options

        if "=" in arg:
            key, value = arg.split("=", 1)
            dict[key] = value
        else:
            dict[arg] = True
    # ~ print 'OPTIONS:', options, template_options

    if "help" in options:
        print usagehelp
        return

    if "notebook" in options:
        notebook, page = resolve_notebook(options["notebook"])
    else:
        notebook = None

    if "append" in options:
        if options["append"].lower() == "true":
            options["append"] = True
        else:
            options["append"] = False

    if "input" in options:
        if options["input"] == "stdin":
            import sys

            text = sys.stdin.read()
        elif options["input"] == "clipboard":
            text = SelectionClipboard.get_text() or Clipboard.get_text()
    else:
        text = options.get("text")

    if text and options.get("encoding"):
        if options["encoding"] == "base64":
            import base64

            text = base64.b64decode(text)
        elif options["encoding"] == "url":
            from zim.parsing import url_decode, URL_ENCODE_DATA

            text = url_decode(text, mode=URL_ENCODE_DATA)
        else:
            raise AssertionError, "Unknown encoding: %s" % options["encoding"]

    if text and not isinstance(text, unicode):
        text = text.decode("utf-8")

    icon = data_file("zim.png").path
    gtk_window_set_default_icon()

    dialog = QuickNoteDialog(
        None,
        notebook,
        options.get("namespace"),
        options.get("basename"),
        options.get("append"),
        text,
        template_options,
        options.get("attachments"),
    )
    dialog.run()
Exemplo n.º 11
0
 def main(self):
     # Set window icon in case we open the notebook dialog
     gtk_window_set_default_icon()
     gtk.main()