Exemplo n.º 1
0
def expand_keyword(parent=None, keyword=None, show_list=False):
	"""Expand keyword and replace inside it.

	Returns:
		None: aborted or no expansion available
		u'': empty expansion
		u'<text>' the expansion
	"""
	if keyword is None:
		return None

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	if show_list:
		candidates = gmKeywordExpansion.get_matching_textual_keywords(fragment = keyword)
		if len(candidates) == 0:
			return None
		if len(candidates) == 1:
			keyword = candidates[0]
		else:
			keyword = gmListWidgets.get_choices_from_list (
				parent = parent,
				msg = _(
					'Several macro keywords match the fragment [%s].\n'
					'\n'
					'Please select the expansion you want to happen.'
				) % keyword,
				caption = _('Selecting text macro'),
				choices = candidates,
				columns = [_('Keyword')],
				single_selection = True,
				can_return_empty = False
			)
			if keyword is None:
				return None

	expansion = gmKeywordExpansion.expand_keyword(keyword = keyword)

	# not found
	if expansion is None:
		return None

	# no replacement necessary:
	if expansion.strip() == u'':
		return expansion

	if regex.search(_text_expansion_fillin_regex, expansion) is not None:
		dlg = cTextExpansionFillInDlg(None, -1)
		dlg.keyword = keyword
		dlg.expansion = expansion
		button = dlg.ShowModal()
		if button == wx.ID_OK:
			expansion = dlg.filled_in_expansion
		dlg.Destroy()

	return expansion
Exemplo n.º 2
0
def expand_keyword(parent=None, keyword=None, show_list_if_needed=False):
	"""Expand keyword and replace inside it.

	Returns:
		None: aborted or no expansion available
		u'': empty expansion
		u'<text>' the expansion
	"""
	if keyword is None:
		return None
	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	if show_list_if_needed:
		candidates = gmKeywordExpansion.get_matching_textual_keywords(fragment = keyword)
		if len(candidates) == 0:
			return None
		if len(candidates) == 1:
			keyword = candidates[0]
		else:
			keyword = gmListWidgets.get_choices_from_list (
				parent = parent,
				msg = _(
					'Several macro keywords match the fragment [%s].\n'
					'\n'
					'Please select the expansion you want to happen.'
				) % keyword,
				caption = _('Selecting text macro'),
				choices = candidates,
				columns = [_('Keyword')],
				single_selection = True,
				can_return_empty = False
			)
			if keyword is None:
				return None

	expansion = gmKeywordExpansion.expand_keyword(keyword = keyword)

	# not found
	if expansion is None:
		return None

	# no replacement necessary:
	if expansion.strip() == '':
		return expansion

	if regex.search(_text_expansion_fillin_regex, expansion) is not None:
		dlg = cTextExpansionFillInDlg(None, -1)
		dlg.keyword = keyword
		dlg.expansion = expansion
		button = dlg.ShowModal()
		if button == wx.ID_OK:
			expansion = dlg.filled_in_expansion
		dlg.Destroy()

	return expansion
Exemplo n.º 3
0
    def replace_keyword_with_expansion(self, keyword=None, position=None):

        if keyword == '$$steffi':  # Easter Egg ;-)
            expansion = 'Hai, play! Versucht das!  (Keks dazu?)  :-)'
        else:
            expansion = gmKeywordExpansion.expand_keyword(keyword=keyword)

        if expansion is None:
            return

        if expansion == '':
            return

        self.replace_text(start=position,
                          end=position + len(keyword),
                          text=expansion)

        self.GotoPos(position + len(expansion) + 1)
        #wx.stc.StyledTextCtrl.SetFocus(self)
        cur = self.PointFromPosition(position + len(expansion) + 1)
        self.__parent.EnsureVisible(self, cur.x, cur.y)
Exemplo n.º 4
0
	def replace_keyword_with_expansion(self, keyword=None, position=None):

		if keyword == u'$$steffi':			# Easter Egg ;-)
			expansion = u'Hai, play! Versucht das!  (Keks dazu?)  :-)'
		else:
			expansion = gmKeywordExpansion.expand_keyword(keyword = keyword)

		if expansion is None:
			return

		if expansion == u'':
			return

		self.replace_text (
			start = position,
			end = position + len(keyword),
			text = expansion
		)

		self.GotoPos(position + len(expansion) + 1)
		#wx.stc.StyledTextCtrl.SetFocus(self)
		cur = self.PointFromPosition(position + len(expansion) + 1)
		self.__parent.EnsureVisible(self, cur.x, cur.y)