Пример #1
0
 def __init__(self,
              default="",
              fixed_size=True,
              visible_width=False,
              threaded=False):
     ConfigText.__init__(self, default, fixed_size, visible_width)
     self.suggestions = GoogleSuggestions(self.propagateSuggestions,
                                          ds="yt",
                                          hl="en")
     self.suggestionsThread = None
     self.threaded = threaded
     self.suggestionsListActivated = False
	def __init__(self, default = "", fixed_size = True, visible_width = False, threaded = False):
		ConfigText.__init__(self, default, fixed_size, visible_width)
		self.suggestions = GoogleSuggestions(self.propagateSuggestions, ds = "yt", hl = "en")
		self.suggestionsThread = None
		self.threaded = threaded
		self.suggestionsListActivated = False
Пример #3
0
class ConfigTextWithSuggestions(ConfigText):
    class SuggestionsThread(Thread):
        def __init__(self, suggestionsService):
            Thread.__init__(self)
            self.suggestionsService = suggestionsService
            self.value = None
            self.running = True
            self.condition = Condition()

        def run(self):
            while self.running:
                self.condition.acquire()
                if self.value is None:
                    self.condition.wait()
                value = self.value
                self.value = None
                self.condition.release()
                if value is not None:
                    self.suggestionsService.getSuggestions(value)

        def stop(self):
            self.running = False
            self.condition.acquire()
            self.condition.notify()
            self.condition.release()
            self.join()

        def getSuggestions(self, value):
            self.condition.acquire()
            self.value = value
            self.condition.notify()
            self.condition.release()

    def __init__(self,
                 default="",
                 fixed_size=True,
                 visible_width=False,
                 threaded=False):
        ConfigText.__init__(self, default, fixed_size, visible_width)
        self.suggestions = GoogleSuggestions(self.propagateSuggestions,
                                             ds="yt",
                                             hl="en")
        self.suggestionsThread = None
        self.threaded = threaded
        self.suggestionsListActivated = False

    def propagateSuggestions(self, suggestionsList):
        if self.suggestionsWindow:
            self.suggestionsWindow.update(suggestionsList)

    def getSuggestions(self):
        if self.suggestionsThread is not None:
            self.suggestionsThread.getSuggestions(self.value)
        else:
            self.suggestions.getSuggestions(self.value)

    def handleKey(self, key):
        if not self.suggestionsListActivated:
            ConfigText.handleKey(self, key)
            if key in [KEY_DELETE, KEY_BACKSPACE, KEY_ASCII, KEY_TIMEOUT]:
                self.getSuggestions()

    def onSelect(self, session):
        if self.threaded:
            self.suggestionsThread = ConfigTextWithSuggestions.SuggestionsThread(
                self.suggestions)
            try:
                self.suggestionsThread.start()
            except:
                pass
        else:
            self.suggestionsThread = None
        ConfigText.onSelect(self, session)
        if session is not None:
            self.suggestionsWindow = session.instantiateDialog(
                SuggestionsListScreen, self)
            self.suggestionsWindow.deactivate()
            self.suggestionsWindow.hide()
        self.suggestions.getSuggestions(self.value)

    def onDeselect(self, session):
        if self.suggestionsThread is not None:
            self.suggestionsThread.stop()
        ConfigText.onDeselect(self, session)
        if self.suggestionsWindow:
            session.deleteDialog(self.suggestionsWindow)
            self.suggestionsWindow = None

    def suggestionListUp(self):
        self.value = self.suggestionsWindow.up()

    def suggestionListDown(self):
        self.value = self.suggestionsWindow.down()

    def suggestionListPageDown(self):
        self.value = self.suggestionsWindow.pageDown()

    def suggestionListPageUp(self):
        self.value = self.suggestionsWindow.pageUp()

    def activateSuggestionList(self):
        ret = False
        if self.suggestionsWindow is not None and self.suggestionsWindow.shown:
            self.tmpValue = self.value
            self.value = self.suggestionsWindow.activate()
            self.allmarked = False
            self.marked_pos = -1
            self.suggestionsListActivated = True
            ret = True
        return ret

    def deactivateSuggestionList(self):
        ret = False
        if self.suggestionsWindow is not None:
            self.suggestionsWindow.deactivate()
            self.getSuggestions()
            self.allmarked = True
            self.suggestionsListActivated = False
            ret = True
        return ret

    def cancelSuggestionList(self):
        self.value = self.tmpValue
        return self.deactivateSuggestionList()
class ConfigTextWithSuggestions(ConfigText):
	class SuggestionsThread(Thread):
		def __init__(self, suggestionsService):
			Thread.__init__(self)
			self.suggestionsService = suggestionsService
			self.value = None
			self.running = True
			self.condition = Condition()

		def run(self):
			while self.running:
				self.condition.acquire()
				if self.value is None:
					self.condition.wait()
				value = self.value
				self.value = None
				self.condition.release()
				if value is not None:
					self.suggestionsService.getSuggestions(value)

		def stop(self):
			self.running = False
			self.condition.acquire()
			self.condition.notify()
			self.condition.release()
			self.join()

		def getSuggestions(self, value):
			self.condition.acquire()
			self.value = value
			self.condition.notify()
			self.condition.release()

	def __init__(self, default = "", fixed_size = True, visible_width = False, threaded = False):
		ConfigText.__init__(self, default, fixed_size, visible_width)
		self.suggestions = GoogleSuggestions(self.propagateSuggestions, ds = "yt", hl = "en")
		self.suggestionsThread = None
		self.threaded = threaded
		self.suggestionsListActivated = False


	def propagateSuggestions(self, suggestionsList):
		if self.suggestionsWindow:
			self.suggestionsWindow.update(suggestionsList)


	def getSuggestions(self):
		if self.suggestionsThread is not None:
			self.suggestionsThread.getSuggestions(self.value)
		else:
			self.suggestions.getSuggestions(self.value)


	def handleKey(self, key):
		if not self.suggestionsListActivated:
			ConfigText.handleKey(self, key)
			if key in [KEY_DELETE, KEY_BACKSPACE, KEY_ASCII, KEY_TIMEOUT]:
				self.getSuggestions()


	def onSelect(self, session):
		if self.threaded:
			self.suggestionsThread = ConfigTextWithSuggestions.SuggestionsThread(self.suggestions)
			try:
				self.suggestionsThread.start()
			except:
				pass
		else:
			self.suggestionsThread = None
		ConfigText.onSelect(self, session)
		if session is not None:
			self.suggestionsWindow = session.instantiateDialog(SuggestionsListScreen, self)
			self.suggestionsWindow.deactivate()
			self.suggestionsWindow.hide()
		self.suggestions.getSuggestions(self.value)


	def onDeselect(self, session):
		if self.suggestionsThread is not None:
			self.suggestionsThread.stop()
		ConfigText.onDeselect(self, session)
		if self.suggestionsWindow:
			session.deleteDialog(self.suggestionsWindow)
			self.suggestionsWindow = None


	def suggestionListUp(self):
		self.value = self.suggestionsWindow.up()


	def suggestionListDown(self):
		self.value = self.suggestionsWindow.down()


	def suggestionListPageDown(self):
		self.value = self.suggestionsWindow.pageDown()


	def suggestionListPageUp(self):
		self.value = self.suggestionsWindow.pageUp()


	def activateSuggestionList(self):
		ret = False
		if self.suggestionsWindow is not None and self.suggestionsWindow.shown:
			self.tmpValue = self.value
			self.value = self.suggestionsWindow.activate()
			self.allmarked = False
			self.marked_pos = -1
			self.suggestionsListActivated = True
			ret = True
		return ret


	def deactivateSuggestionList(self):
		ret = False
		if self.suggestionsWindow is not None:
			self.suggestionsWindow.deactivate()
			self.getSuggestions()
			self.allmarked = True
			self.suggestionsListActivated = False
			ret = True
		return ret


	def cancelSuggestionList(self):
		self.value = self.tmpValue
		return self.deactivateSuggestionList()