Ejemplo n.º 1
0
	def __replace_keyword_with_expansion(self, keyword=None, position=None, show_list=False):

		expansion = expand_keyword(parent = self, keyword = keyword, show_list = show_list)

		if expansion is None:
			return

		if expansion == u'':
			return

		if not self.IsMultiLine():
			expansion_lines = gmTools.strip_leading_empty_lines (
				lines = gmTools.strip_trailing_empty_lines (
					text = expansion,
					return_list = True
				),
				return_list = True
			)
			if len(expansion_lines) == 0:
				return
			if len(expansion_lines) == 1:
				expansion = expansion_lines[0]
			else:
				msg = _(
					'The fragment <%s> expands to multiple lines !\n'
					'\n'
					'This text field can hold one line only, hwoever.\n'
					'\n'
					'Please select the line you want to insert:'
				) % keyword
				expansion = gmListWidgets.get_choices_from_list (
					parent = self,
					msg = msg,
					caption = _('Adapting multi-line expansion to single-line text field'),
					choices = expansion_lines,
					selections = [0],
					columns = [_('Keyword expansion lines')],
					single_selection = True,
					can_return_empty = False
				)
				if expansion is None:
					return

		self.Replace (
			position,
			position + len(keyword),
			expansion
		)

		self.SetInsertionPoint(position + len(expansion) + 1)
		self.ShowPosition(position + len(expansion) + 1)

		return
Ejemplo n.º 2
0
	def __replace_keyword_with_expansion(self, keyword=None, position=None, show_list_if_needed=False):

		expansion = expand_keyword(parent = self, keyword = keyword, show_list_if_needed = show_list_if_needed)
		if expansion is None:
			return
		if expansion == '':
			return

		if not self.IsMultiLine():
			expansion_lines = gmTools.strip_leading_empty_lines (
				lines = gmTools.strip_trailing_empty_lines (
					text = expansion,
					return_list = True
				),
				return_list = True
			)
			if len(expansion_lines) == 0:
				return
			if len(expansion_lines) == 1:
				expansion = expansion_lines[0]
			else:
				msg = _(
					'The fragment <%s> expands to multiple lines !\n'
					'\n'
					'This text field can hold one line only, hwoever.\n'
					'\n'
					'Please select the line you want to insert:'
				) % keyword
				expansion = gmListWidgets.get_choices_from_list (
					parent = self,
					msg = msg,
					caption = _('Adapting multi-line expansion to single-line text field'),
					choices = expansion_lines,
					selections = [0],
					columns = [_('Keyword expansion lines')],
					single_selection = True,
					can_return_empty = False
				)
				if expansion is None:
					return

		self.Replace (
			position,
			position + len(keyword),
			expansion
		)

		self.SetInsertionPoint(position + len(expansion) + 1)
		self.ShowPosition(position + len(expansion) + 1)

		return
Ejemplo n.º 3
0
    def format(self,
               left_margin=0,
               eol=u'\n',
               width=None,
               with_formula=False,
               with_warnings=True,
               with_variables=False,
               with_sub_results=False,
               with_hints=True,
               return_list=False):
        lines = []
        lines.append(self.message)

        if with_formula:
            txt = gmTools.wrap(text=u'%s %s' %
                               (_('Algorithm:'), self.formula_name),
                               width=width,
                               initial_indent=u' ',
                               subsequent_indent=u' ' * 2,
                               eol=eol)
            lines.append(txt)
            txt = gmTools.wrap(text=u'%s %s' %
                               (_('Source:'), self.formula_source),
                               width=width,
                               initial_indent=u' ',
                               subsequent_indent=u' ' * 2,
                               eol=eol)
            lines.append(txt)

        if with_warnings:
            if len(self.warnings) > 0:
                lines.append(u' Caveat:')
            for w in self.warnings:
                txt = gmTools.wrap(text=w,
                                   width=width,
                                   initial_indent=u'  %s ' %
                                   gmTools.u_arrow2right,
                                   subsequent_indent=u'    ',
                                   eol=eol)
                lines.append(txt)

        if with_hints:
            if len(self.hints) > 0:
                lines.append(u' Hints:')
            for h in self.hints:
                txt = gmTools.wrap(text=h,
                                   width=width,
                                   initial_indent=u'  %s ' %
                                   gmTools.u_arrow2right,
                                   subsequent_indent=u'    ',
                                   eol=eol)
                lines.append(txt)

        if with_variables:
            if len(self.variables) > 0:
                lines.append(u' %s' % _('Variables:'))
            for key in self.variables.keys():
                txt = u'  %s %s: %s' % (gmTools.u_arrow2right, key,
                                        self.variables[key])
                lines.append(txt)

        if with_sub_results:
            if len(self.sub_results) > 0:
                lines.append(u' %s' % _('Intermediate results:'))
            for r in self.sub_results:
                lines.extend(
                    r.format(
                        left_margin=left_margin + 1,
                        width=width,
                        eol=eol,
                        with_formula=with_formula,
                        with_warnings=with_warnings,
                        with_variables=with_variables,
                        with_sub_results=False,  # break cycles
                        return_list=True))

        lines = gmTools.strip_trailing_empty_lines(lines=lines, eol=eol)
        if return_list:
            return lines

        left_margin = u' ' * left_margin
        return left_margin + (eol + left_margin).join(lines) + eol
Ejemplo n.º 4
0
	def format(self, left_margin=0, eol='\n', width=None, with_formula=False, with_warnings=True, with_variables=False, with_sub_results=False, with_hints=True, return_list=False):
		lines = []
		lines.append(self.message)

		if with_formula:
			txt = gmTools.wrap (
				text = '%s %s' % (
					_('Algorithm:'),
					self.formula_name
				),
				width = width,
				initial_indent = ' ',
				subsequent_indent = ' ' * 2,
				eol = eol
			)
			lines.append(txt)
			txt = gmTools.wrap (
				text = '%s %s' % (
					_('Source:'),
					self.formula_source
				),
				width = width,
				initial_indent = ' ',
				subsequent_indent = ' ' * 2,
				eol = eol
			)
			lines.append(txt)

		if with_warnings:
			if len(self.warnings) > 0:
				lines.append(' Caveat:')
			for w in self.warnings:
				txt = gmTools.wrap(text = w, width = width, initial_indent = '  %s ' % gmTools.u_arrow2right, subsequent_indent = '    ', eol = eol)
				lines.append(txt)

		if with_hints:
			if len(self.hints) > 0:
				lines.append(' Hints:')
			for h in self.hints:
				txt = gmTools.wrap(text = h, width = width, initial_indent = '  %s ' % gmTools.u_arrow2right, subsequent_indent = '    ', eol = eol)
				lines.append(txt)

		if with_variables:
			if len(self.variables) > 0:
				lines.append(' %s' % _('Variables:'))
			for key in self.variables.keys():
				txt = '  %s %s: %s' % (
					gmTools.u_arrow2right,
					key,
					self.variables[key]
				)
				lines.append(txt)

		if with_sub_results:
			if len(self.sub_results) > 0:
				lines.append(' %s' % _('Intermediate results:'))
			for r in self.sub_results:
				lines.extend(r.format (
					left_margin = left_margin + 1,
					width = width,
					eol = eol,
					with_formula = with_formula,
					with_warnings = with_warnings,
					with_variables = with_variables,
					with_sub_results = False,			# break cycles
					return_list = True
				))

		lines = gmTools.strip_trailing_empty_lines(lines = lines, eol = eol)
		if return_list:
			return lines

		left_margin = ' ' * left_margin
		return left_margin + (eol + left_margin).join(lines) + eol