def attempt_expansion(self, show_list_if_needed=False):

        caret_pos_in_line, line_no = self.PositionToXY(self.InsertionPoint)
        line = self.GetLineText(line_no)
        keyword_candidate = self.__keyword_separators.split(
            line[:caret_pos_in_line])[-1]

        if ((show_list_if_needed is False)
                and (keyword_candidate != u'$$steffi')  # Easter Egg ;-)
                and
            (keyword_candidate not in [
                r[0]
                for r in gmKeywordExpansion.get_textual_expansion_keywords()
            ])):
            return

        # why does this work despite the wx.TextCtrl docs saying that
        # InsertionPoint values cannot be used as indices into strings ?
        # because we never cross an EOL which is the only documented
        # reason for insertion point to be off the string index
        start = self.InsertionPoint - len(keyword_candidate)
        wx.CallAfter(self.__replace_keyword_with_expansion,
                     keyword=keyword_candidate,
                     position=start,
                     show_list_if_needed=show_list_if_needed)
        return
Example #2
0
	def __on_char_in_keyword_expansion_mixin(self, evt):
		evt.Skip()

		# empty ?
		if self.LastPosition == 1:
			return

		char = unichr(evt.GetUnicodeKey())

		explicit_expansion = False
		if evt.GetModifiers() == (wx.MOD_CMD | wx.MOD_ALT): # portable CTRL-ALT-...
			if evt.GetKeyCode() == wx.WXK_RETURN:		# CTRL-ALT-ENTER
				explicit_expansion = True
			elif evt.GetKeyCode() == 20:				# CTRL-ALT-T
				explicit_expansion = True
			else:
				return

		if not explicit_expansion:
			# user did not press CTRL-ALT-ENTER,
			# however, did they last enter a
			# "keyword separator", active character ?
			if self.__keyword_separators.match(char) is None:
				return

		caret_pos_in_document = self.InsertionPoint
		if isinstance(self, wx.stc.StyledTextCtrl):
			caret_pos_in_line = self.GetCurrentPos()
			line_no = self.GetCurrentLine()
			# reimplement PositionToXY() as LineFromPos()/GetColumn(GetCurrentPos)
		else:
			caret_pos_in_line, line_no = self.PositionToXY(caret_pos_in_document)
		line = self.GetLineText(line_no)
		keyword = self.__keyword_separators.split(line[:caret_pos_in_line])[-1]

		if (
			(not explicit_expansion)
				and
			(keyword != u'$$steffi')			# Easter Egg ;-)
				and
			(keyword not in [ r[0] for r in gmKeywordExpansion.get_textual_expansion_keywords() ])
		):
			return

		# why does this work despite the wx.TextCtrl docs saying that
		# InsertionPoint values cannot be used as indices into strings ?
		# because we never cross an EOL which is the only documented
		# reason for insertion point to be off the string index
		start = self.InsertionPoint - len(keyword)
		wx.CallAfter(self.__replace_keyword_with_expansion, keyword, start, explicit_expansion)

		return
Example #3
0
	def __on_char(self, evt):

		char = chr(evt.GetUnicodeKey())

		if self.__keyword_separators.match(char) is not None:
			if self.GetLength() == 1:
				evt.Skip()
				return

			line, caret_pos = self.GetCurLine()
			word = self.__keyword_separators.split(line[:caret_pos])[-1]
			if (word not in [ r[0] for r in gmKeywordExpansion.get_textual_expansion_keywords() ]) and (word != '$$steffi'):		# Easter Egg ;-)
				evt.Skip()
				return

			start = self.GetCurrentPos() - len(word)
			wx.CallAfter(self.replace_keyword_with_expansion, word, start)
			evt.Skip()
			return

		evt.Skip()
Example #4
0
	def __on_char(self, evt):

		char = unichr(evt.GetUnicodeKey())

		if self.__keyword_separators.match(char) is not None:
			if self.GetLength() == 1:
				evt.Skip()
				return

			line, caret_pos = self.GetCurLine()
			word = self.__keyword_separators.split(line[:caret_pos])[-1]
			if (word not in [ r[0] for r in gmKeywordExpansion.get_textual_expansion_keywords() ]) and (word != u'$$steffi'):		# Easter Egg ;-)
				evt.Skip()
				return

			start = self.GetCurrentPos() - len(word)
			wx.CallAfter(self.replace_keyword_with_expansion, word, start)
			evt.Skip()
			return

		evt.Skip()
	def attempt_expansion(self, show_list_if_needed=False):

		visible, caret_pos_in_line, line_no = self.PositionToXY(self.InsertionPoint)
		line = self.GetLineText(line_no)
		keyword_candidate = self.__keyword_separators.split(line[:caret_pos_in_line])[-1]

		if (
			(show_list_if_needed is False)
				and
			(keyword_candidate != '$$steffi')			# Easter Egg ;-)
				and
			(keyword_candidate not in [ r[0] for r in gmKeywordExpansion.get_textual_expansion_keywords() ])
		):
			return

		# why does this work despite the wx.TextCtrl docs saying that
		# InsertionPoint values cannot be used as indices into strings ?
		# because we never cross an EOL which is the only documented
		# reason for insertion point to be off the string index
		start = self.InsertionPoint - len(keyword_candidate)
		wx.CallAfter(self.__replace_keyword_with_expansion, keyword = keyword_candidate, position = start, show_list_if_needed = show_list_if_needed)
		return