コード例 #1
0
ファイル: window.py プロジェクト: tongsong91/GouYong
    def _on_check_clip(self, time):
        if not self.owner_change:
            return
        else:
            self.owner_change = False
        text = self.primary.wait_for_text()
        if text:
            logger.info(text)
        else:
            logger.info("No text on the clipboard.")
            return False
        #self.primary.set_text('',0)
        s, x, y, m = self.main_win.display.get_pointer()
        logger.debug("x= %f,y=%f" % (x, y))
        import socket
        if self.isNet:
            for i in range(RETRY_TIME):
                try:
                    results = youdaoQuery.gettext(text)
                except urllib2.URLError:
                    logger.debug("disconnect...Try again,the %d times" %
                                 (i + 1, ))
                except socket.timeout:
                    logger.debug("timeout,Try again,the %d times" % (i + 1, ))

                else:
                    fileName = youdaoQuery.creat_file(text, results)
                    uri = 'file://' + fileName
                    self.popup.load_uri(uri)
                    break
            else:
                logger.debug("You are disconnected.")
                self.dictind.toggled(self.dictind.use_web_item, isNet=False)
                return

        else:
            text = utils.tidy_text(text)
            results = self.dm.dict[text]
            logger.info(results)
            self.popup.textbuffer.set_text(results, len(results))

        self._placement(x, y)
        if self.check_mouse_thread_id and GLib.source_remove(
                self.check_mouse_thread_id):
            logger.debug("check mouse not finish.now kill it.")
            #self.popup.popup.hide()
        else:
            logger.debug("There is no check mouse thread.")
        self.popup.popup.show_all()
        logger.info("show===================")
        center = {'x': x, 'y': y}
        self.check_mouse_thread_id = Gdk.threads_add_timeout(
            GLib.PRIORITY_DEFAULT_IDLE, MOUSE_DETECT_INTERVAL,
            self._check_mouse, center)
コード例 #2
0
ファイル: window.py プロジェクト: jiffies/GouYong
    def _on_check_clip(self, time):
        if not self.owner_change:
            return
        else:
            self.owner_change = False
        text = self.primary.wait_for_text()
        if text:
            logger.info(text)
        else:
            logger.info("No text on the clipboard.")
            return False
        # self.primary.set_text('',0)
        s, x, y, m = self.main_win.display.get_pointer()
        logger.debug("x= %f,y=%f" % (x, y))
        import socket

        if self.isNet:
            for i in range(RETRY_TIME):
                try:
                    results = youdaoQuery.gettext(text)
                except urllib2.URLError:
                    logger.debug("disconnect...Try again,the %d times" % (i + 1,))
                except socket.timeout:
                    logger.debug("timeout,Try again,the %d times" % (i + 1,))

                else:
                    fileName = youdaoQuery.creat_file(text, results)
                    uri = "file://" + fileName
                    self.popup.load_uri(uri)
                    break
            else:
                logger.debug("You are disconnected.")
                self.dictind.toggled(self.dictind.use_web_item, isNet=False)
                return

        else:
            text = utils.tidy_text(text)
            results = self.dm.dict[text]
            logger.info(results)
            self.popup.textbuffer.set_text(results, len(results))

        self._placement(x, y)
        if self.check_mouse_thread_id and GLib.source_remove(self.check_mouse_thread_id):
            logger.debug("check mouse not finish.now kill it.")
            # self.popup.popup.hide()
        else:
            logger.debug("There is no check mouse thread.")
        self.popup.popup.show_all()
        logger.info("show===================")
        center = {"x": x, "y": y}
        self.check_mouse_thread_id = Gdk.threads_add_timeout(
            GLib.PRIORITY_DEFAULT_IDLE, MOUSE_DETECT_INTERVAL, self._check_mouse, center
        )
コード例 #3
0
ファイル: window.py プロジェクト: justzx2011/GouYong
    def _on_check_clip(self,time):
        if not self.owner_change:
            return
        else:
            self.owner_change = False
        text = self.primary.wait_for_text()
        if text:
            print text
        else:
            print("No text on the clipboard.")
            return False
        #self.primary.set_text('',0)
        s,x,y,m=self.main_win.display.get_pointer()
        print "x= %f,y=%f" % (x,y)
        if self.isNet:
            try:
                results=youdaoQuery.gettext(text)
                fileName=youdaoQuery.creat_file(text,results)
                uri = 'file://'+fileName
                self.popup.load_uri(uri)
            except urllib2.URLError:
                print "You are disconnected."
                self.dictind.toggled(self.dictind.use_web_item,isNet=False)
                return
        else:
            text=utils.tidy_text(text)
            results=self.dm.dict[text]
            print results
            self.popup.textbuffer.set_text(results,len(results))

        self._placement(x,y)
        if self.check_mouse_thread_id and GLib.source_remove(self.check_mouse_thread_id):
            print "check mouse not finish.now kill it."
            #self.popup.popup.hide()
        else:
            print "There is no check mouse thread."
        self.popup.popup.show_all()
        print "show==================="
        center={'x':x,'y':y}
        self.check_mouse_thread_id=Gdk.threads_add_timeout(GLib.PRIORITY_DEFAULT_IDLE,MOUSE_DETECT_INTERVAL,self._check_mouse,center)