Beispiel #1
0
    def __init__(self, parent, logging_context, output):
        self.logging_context = logging_context
        self.output = output

        n_error = logging_context.handler.n_error
        n_warning = logging_context.handler.n_warning
        if n_error and n_warning:
            text = _(
                '%(n_error)i errors and %(n_warning)i warnings occurred, see log'
            ) % {
                'n_error': n_error,
                'n_warning': n_warning
            }
            # T: label in export dialog
        elif n_error:
            text = _('%i errors occurred, see log') % n_error
            # T: label in export dialog
        elif n_warning:
            text = _('%i warnings occurred, see log') % n_warning
            # T: label in export dialog
        else:
            text = None

        MessageDialog.__init__(self, parent, (_('Export completed'), text))
        # T: label in export dialog

        log_button = Button(_('View _Log'), stock='gtk-file')
        # T: button in export dialog
        log_button.set_sensitive(logging_context.file.exists())
        log_button.connect_object('clicked', self.__class__.on_show_log, self)

        #~ open_button =

        #~ self.add_extra_button(open_button)
        self.add_extra_button(log_button)
	def __init__(self, parent, logging_context, output):
		self.logging_context = logging_context
		self.output = output

		n_error = logging_context.handler.n_error
		n_warning = logging_context.handler.n_warning
		if n_error and n_warning:
			text = _('%(n_error)i errors and %(n_warning)i warnings occurred, see log') % {'n_error': n_error, 'n_warning': n_warning}
				# T: label in export dialog
		elif n_error:
			text = _('%i errors occurred, see log') % n_error
				# T: label in export dialog
		elif n_warning:
			text = _('%i warnings occurred, see log') % n_warning
				# T: label in export dialog
		else:
			text = None

		MessageDialog.__init__(self, parent, (_('Export completed'), text))
			# T: label in export dialog

		log_button = Button(_('View _Log'), stock='gtk-file')
			# T: button in export dialog
		log_button.set_sensitive(logging_context.file.exists())
		log_button.connect_object(
			'clicked', self.__class__.on_show_log, self)

		#~ open_button =

		#~ self.add_extra_button(open_button)
		self.add_extra_button(log_button)
Beispiel #3
0
def edit_file(widget, file, istextfile=None):
	'''Edit a file with and external application.

	This method will show a dialog to block the interface while the
	external application is running. The dialog is closed
	automatically when the application exits _after_ modifying the
	file. If the file is unmodified the user needs to click the
	"Done" button in the dialog because we can not know if the
	application was really done or just forked to another process.

	@param widget: a C{gtk} widget to use as parent for dialogs or C{None}
	@param file: a L{File} object
	@param istextfile: if C{True} the text editor is used, otherwise
	we ask the file browser for the correct application. When
	C{None} we check the mimetype of the file to determine if it
	is text or not.
	'''
	## FIXME force using real text editor, even when file has not
	## text mimetype. This now goes wrong when editing e.g. a html
	## template when the editor is "xdg-open" on linux or default
	## os.startfile() on windows...

	if not file.exists():
		raise FileNotFoundError(file)

	oldmtime = file.mtime()

	dialog = MessageDialog(widget, (
		_('Editing file: %s') % file.basename,
			# T: main text for dialog for editing external files
		_('You are editing a file in an external application. You can close this dialog when you are done')
			# T: description for dialog for editing external files
	))

	def check_close_dialog(status):
		if status != 0:
			dialog.destroy()
			ErrorDialog(widget, _('Could not open: %s') % file.basename).run()
				# T: error when external application fails
		else:
			newmtime = file.mtime()
			if newmtime != oldmtime:
				dialog.destroy()

	if istextfile:
		try:
			open_file(widget, file, mimetype='text/plain', callback=check_close_dialog)
		except NoApplicationFoundError:
			app = AddApplicationDialog(widget, 'text/plain').run()
			if app:
				# Try again
				open_file(widget, file, mimetype='text/plain', callback=check_close_dialog)
			else:
				return # Dialog was cancelled, no default set, ...
	else:
		open_file(widget, file, callback=check_close_dialog)

	dialog.run()
    def crypt_selection(self):
        buffer = self.window.pageview.view.get_buffer()
        try:
            sel_start, sel_end = buffer.get_selection_bounds()
        except ValueError:
            MessageDialog(
                self.window.ui,
                _('Please select the text to be encrypted, first.')).run()
            # T: Error message in "crypt selection" dialog, %s will be replaced
            # by application name
            return

        first_lineno = sel_start.get_line()
        last_lineno = sel_end.get_line()

        with buffer.user_action:
            assert buffer.get_has_selection(), 'No Selection present'
            sel_text = self.window.pageview.get_selection(format='wiki')
            self_bounds = (sel_start.get_offset(), sel_end.get_offset())
            if ((re.match(r'[\n\s]*\-{5}BEGIN PGP MESSAGE\-{5}', sel_text) is
                 None) or re.search(r'\s*\-{5}END PGP MESSAGE\-{5}[\n\s]*$',
                                    sel_text) is None):
                # default is encryption:
                encrypt = True
                cryptcmd = self.preferences['encryption_command'].split(" ")
            else:
                # on-the-fly decryption if selection is a full PGP encrypted block
                encrypt = False
                cryptcmd = self.preferences['decryption_command'].split(" ")
            newtext = None
            p = Popen(cryptcmd, stdin=PIPE, stdout=PIPE)
            newtext, err = p.communicate(input=sel_text)
            if p.returncode == 0:
                # replace selection only if crypt command was successful
                # (incidated by returncode 0)
                if encrypt is True:
                    bounds = map(buffer.get_iter_at_offset, self_bounds)
                    buffer.delete(*bounds)
                    buffer.insert_at_cursor("\n%s\n" % newtext)
                else:
                    # just show decrypted text in popup
                    MessageDialog(self.window.ui,
                                  _("Decrypted Text: \n" + newtext)).run()
            else:
                logger.warn("crypt command '%s' returned code %d." %
                            (cryptcmd, p.returncode))
Beispiel #5
0
    def sort_selected_lines(self):
        buffer = self.window.pageview.view.get_buffer()
        try:
            sel_start, sel_end = buffer.get_selection_bounds()
        except ValueError:
            MessageDialog(
                self.ui,
                _('Please select more than one line of text, first.')).run()
            # T: Error message in "" dialog, %s will be replaced by application name
            return

        first_lineno = sel_start.get_line()
        last_lineno = sel_end.get_line()

        with buffer.user_action:
            # Get iters for full selection
            iter_end_line = buffer.get_iter_at_line(last_lineno)
            iter_end_line.forward_line()  # include \n at end of line
            if iter_end_line.is_end() and not iter_end_line.starts_line():
                # no \n at end of buffer, insert it
                buffer.insert(iter_end_line, '\n')
                iter_end_line = buffer.get_end_iter()
            iter_begin_line = buffer.get_iter_at_line(first_lineno)

            # 1/ build a list of formatted lines with get_parsetree()
            # 2/ make a list of tuples, first element of each tuple is
            #    text only (white space stripped etc.), second element
            #    is parsetree per line from step 1
            lines = []
            for line_nr in range(first_lineno, last_lineno + 1):
                start, end = buffer.get_line_bounds(line_nr)
                text = buffer.get_text(start, end).lower().strip()
                tree = buffer.get_parsetree(bounds=(start, end))
                lines.append((text, tree))
            #logger.debug("Content of selected lines (text, tree): %s", lines)

            # 3/ sort this list of tuples, sort will look at first element of the tuple
            sorted_lines = sorted(lines, key=lambda lines: lines[0])
            # checks whether the list is sorted "a -> z", if so reverses its order
            if lines == sorted_lines:
                sorted_lines.reverse()
            # logger.debug("Sorted lines: %s",  sorted_lines)

            # 4/ for the replacement insert the parsetrees of the lines one by one
            buffer.delete(iter_begin_line, iter_end_line)
            for line in sorted_lines:
                buffer.insert_parsetree_at_cursor(line[1])
Beispiel #6
0
    def sort_selected_lines(self):
        buffer = self.window.pageview.view.get_buffer()
        try:
            sel_start, sel_end = buffer.get_selection_bounds()
        except ValueError:
            MessageDialog(
                self.window,
                _('Please select more than one line of text, first.')).run()
            # T: Error message in "" dialog, %s will be replaced by application name
            return

        first_lineno = sel_start.get_line()
        last_lineno = sel_end.get_line()

        with buffer.user_action:
            # Get iters for full selection
            iter_end_line = buffer.get_iter_at_line(last_lineno)
            iter_end_line.forward_line()  # include \n at end of line
            if iter_end_line.is_end() and not iter_end_line.starts_line():
                # no \n at end of buffer, insert it
                buffer.insert(iter_end_line, '\n')
                iter_end_line = buffer.get_end_iter()
            iter_begin_line = buffer.get_iter_at_line(first_lineno)

            # Make a list of tuples, first element of each tuple is
            # text only sort key (no formatting), second element
            # is parsetree per line
            lines = []
            for line_nr in range(first_lineno, last_lineno + 1):
                start, end = buffer.get_line_bounds(line_nr)
                text = buffer.get_text(start, end)
                tree = buffer.get_parsetree(bounds=(start, end))
                lines.append((natural_sort_key(text), tree))
            #~ logger.debug("Content of selected lines (text, tree): %s", lines)

            # Sort the list of tuples
            sorted_lines = sorted(lines)
            if lines == sorted_lines:  # reverse if already sorted
                sorted_lines.reverse()
            #~ logger.debug("Sorted lines: %s",  sorted_lines)

            # Replace selection
            buffer.delete(iter_begin_line, iter_end_line)
            for line in sorted_lines:
                buffer.insert_parsetree_at_cursor(line[1])
Beispiel #7
0
    def initialize_db(self):
        if not self.index_ext.db_initialized:
            self.index_ext.connect_signals()  # enable signals to update
            header_message = _('IconTags: Need to index the notebook')
            text_message = _('Icon shortcodes are enabled.\n'
                             'To find them the index needs to be rebuild.\n'
                             'It can take up some time. You can stop it \n'
                             'by pressing cancel in the updating window.')
            MessageDialog(self.window, (header_message, text_message)).run()
            logger.info(
                'Database for Icons is not initialized, need to rebuild the index.'
            )

            finished = self.window.ui.reload_index(flush=True)  # XXX
            # Flush + Reload will also initialize iconlist
            if not finished:
                self.index_ext.db_initialized = False
                return False
        return True
Beispiel #8
0
    def show_task_list(self):
        if not self.index_ext.db_initialized:
            MessageDialog(
                self.window,
                (
                    _('Need to index the notebook'),
                    # T: Short message text on first time use of task list plugin
                    _('This is the first time the task list is opened.\n'
                      'Therefore the index needs to be rebuild.\n'
                      'Depending on the size of the notebook this can\n'
                      'take up to several minutes. Next time you use the\n'
                      'task list this will not be needed again.')
                    # T: Long message text on first time use of task list plugin
                )).run()
            logger.info('Tasklist not initialized, need to rebuild index')
            finished = self.window.ui.reload_index(flush=True)  # XXX
            # Flush + Reload will also initialize task list
            if not finished:
                self.index_ext.db_initialized = False
                return

        dialog = TaskListDialog.unique(self, self.window, self.index_ext,
                                       self.plugin.preferences)
        dialog.present()