예제 #1
0
    def __init__(self):
        settings = setandgetsettings.Settings()
        settings.initialization_config()
        if config.isFirstStart:
            PreconfiguringController()
        publisher = pub.Publisher()
        self.mainFrame = MainFrameController()
        self.popUpFrame = PopUpController()
        if os.name =="posix": self.mainFrame.view.Show()
        self.mainFrame.view.Hide()
        self.mainFrame.view.Bind( wx.EVT_MENU,self.event_exit, self.mainFrame.view.m_menuItemExit  )
        self.mainFrame.tbicon.Bind(wx.EVT_MENU, self.event_exit, id=wx.ID_EXIT)
        self.globalEvents=HandlerGlobalEvents()

        publisher.subscribe(self.get_clipboard_data, "TranslateText")
        publisher.subscribe(self.hide_frames, "HideFrames")

        if os.name =="nt":
            publisher.subscribe(self.version_result, "VERSION")
            getnewversion.NewVersionThread(False)
예제 #2
0
class ControllerMain():

    def __init__(self):
        settings = setandgetsettings.Settings()
        settings.initialization_config()
        if config.isFirstStart:
            PreconfiguringController()
        publisher = pub.Publisher()
        self.mainFrame = MainFrameController()
        self.popUpFrame = PopUpController()
        if os.name =="posix": self.mainFrame.view.Show()
        self.mainFrame.view.Hide()
        self.mainFrame.view.Bind( wx.EVT_MENU,self.event_exit, self.mainFrame.view.m_menuItemExit  )
        self.mainFrame.tbicon.Bind(wx.EVT_MENU, self.event_exit, id=wx.ID_EXIT)
        self.globalEvents=HandlerGlobalEvents()

        publisher.subscribe(self.get_clipboard_data, "TranslateText")
        publisher.subscribe(self.hide_frames, "HideFrames")

        if os.name =="nt":
            publisher.subscribe(self.version_result, "VERSION")
            getnewversion.NewVersionThread(False)

    def event_exit( self, event ):
        """
        close application and remove taskbar icon, save options
        """
        self.globalEvents.cancel()
        self.mainFrame.settings.set_global_params()
        self.mainFrame.tbicon.RemoveIcon()
        self.mainFrame.tbicon.Destroy()
        self.mainFrame.view.Destroy()
        sys.exit()

    def hide_frames(self,event):

        # Hide PopUpFrame
        event=event.data
        if self.popUpFrame.view.IsShown():
            popUpFrameSize = self.popUpFrame.view.GetSizeTuple()
            popUpFramePos = self.popUpFrame.view.GetPositionTuple()
            if event.Position[0] > popUpFramePos[0]+popUpFrameSize[0] or popUpFramePos[0]>event.Position[0] or \
                popUpFramePos[1]>event.Position[1] or event.Position[1]> popUpFramePos[1]+popUpFrameSize[1]:
                self.popUpFrame.view.Hide()
                config.isRunTranslate=False

        if config.countClickUp!=2:
            # Hide ResultFrame
            if self.popUpFrame.resultController.view.IsShown():
                if not self.popUpFrame.resultController.view.selectLang:
                    textFrameSize = self.popUpFrame.resultController.view.GetSizeTuple()
                    textFramePos = self.popUpFrame.resultController.view.GetPositionTuple()
                    if event.Position[0] > textFramePos[0]+textFrameSize[0] or textFramePos[0]>event.Position[0] or \
                        textFramePos[1]>event.Position[1] or event.Position[1]> textFramePos[1]+textFrameSize[1]:
                        self.popUpFrame.resultController.view.Hide()
                        config.isRunTranslate=False


    def get_clipboard_data(self,isTranslateNow):
        """
        get selection text use clipboard
        """
        isTranslateNow=isTranslateNow.data
        self.popUpFrame.view.Hide()
        if not isTranslateNow:
            self.popUpFrame.showFrame=False
        config.countClickUp=0
        if os.name=="posix":
            try:
                time.sleep(0.1)
                text = popen('xsel').read()
                config.isRunTranslate=True
                self.popUpFrame.dataText = text
                if self.popUpFrame.dataText!="":
                    if isTranslateNow:
                        config.countClickUp=1
                        self.popUpFrame.translate()
                    else:
                        self.popUpFrame.view.Show()
                    self.dblCtrl=0
            except Exception, ex:
                self.popUpFrame.dataText=ex.message.encode('utf-8')
                self.popUpFrame.view.Show()

        elif os.name =="nt":
            self.globalEvents.hookKeyboard(False)
            run_clipboard(self)
            success = False
            data = wx.TextDataObject()
            try:
                if wx.TheClipboard.Open():
                    success = wx.TheClipboard.GetData(data)
                    wx.TheClipboard.Close()
                    if success:
                        self.popUpFrame.dataText = data.GetText().strip()
                        if self.popUpFrame.dataText!="":
                            config.isRunTranslate=True
                            if isTranslateNow:
                                config.countClickUp=1
                                self.popUpFrame.translate()
                            else:
                                self.popUpFrame.view.Show()
            except Exception, ex:
                self.popUpFrame.dataText=ex.message.encode('utf-8')
                self.popUpFrame.view.Show()