コード例 #1
0
	def do_populate(self, context):
		"""
		An automated function called by GtkSource.Completion, when
		:py:meth:`.do_match` returns True. This function is used to provide
		suggested completion words (referred to as proposals) for the context
		based on the match. This is done by creating a list of suggestions and
		adding them with :py:meth:`GtkSource.CompletionContext.add_proposals`.
		If :py:meth:`.extract` returns None, then
		:py:meth:`~.CustomCompletionProviderBase.populate` will not be called.

		:param context: The context for the completion.
		:type context: :py:class:`GtkSource.CompletionContext`
		"""
		match = self.extract(context)
		if match is None:
			# if extract returns none, return here without calling self.populate
			return

		proposals = []
		try:
			matching_suggestions = self.populate(context, match)
		except Exception:
			self.logger.warning('encountered an exception in the completion populate routine', exc_info=True)
			return
		matching_suggestions.sort()
		for suggestion in matching_suggestions:
			if not suggestion:
				continue
			if isinstance(suggestion, str):
				item = GtkSource.CompletionItem(label=suggestion, text=suggestion)
			else:
				item = GtkSource.CompletionItem(label=suggestion[0], text=suggestion[1])
			proposals.append(item)
		context.add_proposals(self, proposals, True)
コード例 #2
0
	def do_populate(self, context):
		proposals = []
			#GtkSource.CompletionItem(label='Hello World!', text='Hello World!', icon=None, info=None),  # always proposed
			#GtkSource.CompletionItem(label='[Paketci]', text='[Paketci]', icon=None, info=None)  # always proposed

		# found difference in Gtk Versions
		end_iter = context.get_iter()
		if not isinstance(end_iter, Gtk.TextIter):
			_, end_iter = context.get_iter()

		if end_iter:
			mps_list ={
				"[paket]":["tanim\t\t=","paketci\t\t=","grup\t\t\t=","url\t\t\t\t="],
				"[kaynak]":["gz\t\t\t\t=","xz\t\t\t\t=","dosya\t\t\t=","bz2\t\t\t\t=","github\t\t=","1\t\t\t\t\t=","2\t\t\t\t\t=","3\t\t\t\t\t="],
				"[sha256]":["1\t\t\t\t\t=","2\t\t\t\t\t=","3\t\t\t\t\t=","4\t\t\t\t\t=","5\t\t\t\t\t=","6\t\t\t\t\t="],
				"[derle]":["betik\t\t\t=","dosya\t\t\t=","yama\t\t\t=","tip\t\t\t\t=","ekconf\t\t="],
				"[pakur]":["tip\t\t\t\t=","dosya\t\t\t=","betik\t\t\t=","strip\t\t\t="]}


			buf = end_iter.get_buffer()
			mov_iter = end_iter.copy()
			if mov_iter.backward_search('[', Gtk.TextSearchFlags.VISIBLE_ONLY):
				mov_iter, _ = mov_iter.backward_search('[', Gtk.TextSearchFlags.VISIBLE_ONLY)
				left_text = buf.get_text(mov_iter, end_iter, True)
				text = left_text.split("\n")
				if len(text) == 1:
					for key in mps_list.keys():
						proposals.append(GtkSource.CompletionItem(label=key, text=key[1:], icon=None, info=None))
				elif text[0] == "[paket]" and "=" not in text[-1]:
					for key in mps_list["[paket]"]:
						proposals.append(GtkSource.CompletionItem(label=key, text=key, icon=None, info=None))
				elif text[0] == "[kaynak]" and "=" not in text[-1]:
					for key in mps_list["[kaynak]"]:
						proposals.append(GtkSource.CompletionItem(label=key, text=key, icon=None, info=None))
				elif text[0] == "[sha256]" and "=" not in text[-1]:
					for key in mps_list["[sha256]"]:
						proposals.append(GtkSource.CompletionItem(label=key, text=key, icon=None, info=None))
				elif text[0] == "[derle]" and "=" not in text[-1]:
					for key in mps_list["[derle]"]:
						proposals.append(GtkSource.CompletionItem(label=key, text=key, icon=None, info=None))
				elif text[0] == "[pakur]" and "=" not in text[-1]:
					for key in mps_list["[pakur]"]:
						proposals.append(GtkSource.CompletionItem(label=key, text=key, icon=None, info=None))
			else:
				left_text = ''

			if re.match(r'.*\{\{\s*custom\.$', left_text):
				proposals.append(
					GtkSource.CompletionItem(label='foo', text='foo }}')  # optionally proposed based on left search via regex
				)
				proposals.append(
					GtkSource.CompletionItem(label='bar', text='bar }}')  # optionally proposed based on left search via regex
				)

		context.add_proposals(self, proposals, True)
		return
コード例 #3
0
    def do_populate(self, context):
        proposals = [
            GtkSource.CompletionItem(label='Hello World!',
                                     text='Hello World!',
                                     icon=None,
                                     info=None)  # always proposed
        ]

        # found difference in Gtk Versions
        end_iter = context.get_iter()
        if not isinstance(end_iter, Gtk.TextIter):
            _, end_iter = context.get_iter()

        if end_iter:
            buf = end_iter.get_buffer()
            mov_iter = end_iter.copy()
            if mov_iter.backward_search('{{',
                                        Gtk.TextSearchFlags.VISIBLE_ONLY):
                mov_iter, _ = mov_iter.backward_search(
                    '{{', Gtk.TextSearchFlags.VISIBLE_ONLY)
                left_text = buf.get_text(mov_iter, end_iter, True)
            else:
                left_text = ''

            if re.match(r'.*\{\{\s*custom\.$', left_text):
                proposals.append(
                    GtkSource.CompletionItem(
                        label='foo', text='foo }}'
                    )  # optionally proposed based on left search via regex
                )
                proposals.append(
                    GtkSource.CompletionItem(
                        label='bar', text='bar }}'
                    )  # optionally proposed based on left search via regex
                )

        context.add_proposals(self, proposals, True)
        return
コード例 #4
0
 def createProposal(self, text, info):
     prop = GtkSource.CompletionItem(label=text, text=text, info=info)
     return prop