示例#1
0
    def __init__(self):
        icon_path = os.path.join(os.path.dirname(__file__), "icon", "favicon.ico")
        self.systray = SysTrayIcon(icon_path, "XX-Net", self.make_menu(), self.on_quit, left_click=self.on_show,
                                   right_click=self.on_right_click)

        reg_path = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
        self.INTERNET_SETTINGS = winreg.OpenKey(winreg.HKEY_CURRENT_USER, reg_path, 0, winreg.KEY_ALL_ACCESS)
示例#2
0
    def __init__(self):
        icon_path = os.path.join(os.path.dirname(__file__), "web_ui",
                                 "favicon.ico")
        self.systray = SysTrayIcon(icon_path,
                                   "XX-Net",
                                   self.make_menu(),
                                   self.on_quit,
                                   left_click=self.on_show,
                                   right_click=self.on_right_click)

        reg_path = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
        self.INTERNET_SETTINGS = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
                                                reg_path, 0,
                                                winreg.KEY_ALL_ACCESS)

        proxy_setting = config.get(["modules", "launcher", "proxy"], "pac")
        if proxy_setting == "pac":
            self.on_enable_pac()
        elif proxy_setting == "gae":
            self.on_enable_gae_proxy()
        elif proxy_setting == "disable":
            # Don't disable proxy setting, just do nothing.
            pass
        else:
            xlog.warn("proxy_setting:%r", proxy_setting)
示例#3
0
 def __init__(self):
     icon_path = os.path.join(os.path.dirname(__file__), "python.ico")
     self.systray = SysTrayIcon(icon_path,
                                "XX-Net",
                                self.make_menu(),
                                self.on_quit,
                                left_click=self.on_show)
示例#4
0
    def __init__(self):
        self.image_dir = os.path.join(plexpy.PROG_DIR, 'data/interfaces/',
                                      plexpy.CONFIG.INTERFACE, 'images')
        self.icon = os.path.join(self.image_dir, 'logo-circle.ico')

        if plexpy.UPDATE_AVAILABLE:
            self.hover_text = common.PRODUCT + ' - Update Available!'
            self.update_title = 'Check for Updates - Update Available!'
        else:
            self.hover_text = common.PRODUCT
            self.update_title = 'Check for Updates'

        if plexpy.CONFIG.LAUNCH_STARTUP:
            launch_start_icon = os.path.join(self.image_dir, 'check-solid.ico')
        else:
            launch_start_icon = None
        if plexpy.CONFIG.LAUNCH_BROWSER:
            launch_browser_icon = os.path.join(self.image_dir,
                                               'check-solid.ico')
        else:
            launch_browser_icon = None

        self.menu = [['Open Tautulli', None, self.tray_open, 'default'],
                     ['', None, 'separator', None],
                     [
                         'Start Tautulli at Login', launch_start_icon,
                         self.tray_startup, None
                     ],
                     [
                         'Open Browser when Tautulli Starts',
                         launch_browser_icon, self.tray_browser, None
                     ], ['', None, 'separator', None],
                     [self.update_title, None, self.tray_check_update, None],
                     ['Restart', None, self.tray_restart, None]]
        if not plexpy.FROZEN:
            self.menu.insert(6, ['Update', None, self.tray_update, None])

        self.tray_icon = SysTrayIcon(self.icon,
                                     self.hover_text,
                                     self.menu,
                                     on_quit=self.tray_quit)
示例#5
0
 def __init__(self):
     self.menu_options = (("Open window", None, restore), )
     self.tray_instance = SysTrayIcon(resource_path("ghost.ico"),
                                      "Ready!",
                                      self.menu_options,
                                      on_quit=ask_quit)
示例#6
0
    def __init__(self):
        '''GUI的初始化
        '''
        self.logger = logging.getLogger(__name__)
        self.logger.info("开始记录日志")
        try:
            self.logger.info("开始检查网络连接")
            # requests.get("https://www.baidu.com", verify=False) # 访问百度以验证网络是否通畅
            # self.logger.info("网络连接成功")
            self.logger.info("开始加载配置文件")
            self.cf = Config()
            self.APP_ID = self.cf.APP_ID
            self.API_KEY = self.cf.API_KEY
            self.SECRET_KEY = self.cf.SECRET_KEY
            self.MK_APIKEY = self.cf.MK_APIKEY

            self.logger.info("开始加载窗体")
            self.window = tk.Tk()
            self.window.title('截图翻译工具(V4.5)')
            self.window.attributes("-alpha", 0.9)
            self.window['background'] = 'PowderBlue'

            self.filename = resource_path(os.path.join("res", "bitbug_favicon.ico"))

            self.window.iconbitmap(self.filename)

            self.window.resizable(0, 0)

            self.menubar = tk.Menu(self.window)

            self.filemenu = tk.Menu(self.menubar, tearoff=0)
            self.menubar.add_cascade(label='导入文件', menu=self.filemenu)
            self.filemenu.add_command(label='从文本文件导入', command=self.getFromTXT)
            self.filemenu.add_command(label='从图像文件导入', command=self.getFromImage)

            self.setmenu = tk.Menu(self.menubar, tearoff=0)
            self.menubar.add_cascade(label='设置', menu=self.setmenu)
            self.setmenu.add_command(label='查看APP_ID', command=self.getAppId)
            self.setmenu.add_command(label='生成配置文件', command=self.useConfig)
            self.picButton = tk.IntVar()
            self.picButton.set(0)
            self.setmenu.add_checkbutton(label='只监听图片', variable=self.picButton)
            

            self.helpmenu = tk.Menu(self.menubar, tearoff=0)
            self.menubar.add_cascade(label='帮助', menu=self.helpmenu)
            self.helpmenu.add_command(label='关于', command=self.aboutClick)
            self.helpmenu.add_command(label='更新与反馈', command=self.upClick)

            self.window.config(menu=self.menubar)

            tk.Label(self.window, text="原文:", background='PowderBlue').grid(
                row=0, column=0, sticky=tk.W)

            self.comboxlist0 = ttk.Combobox(self.window)
            self.comboxlist0["values"] = ("使用百度翻译","使用谷歌翻译", "C/C++代码美化")
            self.comboxlist0.bind("<<ComboboxSelected>>", self.comboxlist0_msg)

            self.comboxlist0["state"] = "readonly"
            self.comboxlist0.current(0)
            self.comboxlist0.grid(row=0, column=0, columnspan=2, padx=38, sticky=tk.W)

            self.comboxlist = ttk.Combobox(self.window)
            self.comboxlist["values"] = ("翻译为中文(简体)", "翻译为中文(繁体)",
                                         "翻译为英文", "翻译为日文", "翻译为韩文")
            self.comboxlist["state"] = "readonly"
            self.comboxlist.current(0)
            self.comboxlist.grid(row=0, column=1, sticky=tk.E)

            self.inputText = tk.Text(self.window, height=12, width=50)
            self.inputText.grid(row=1, column=0, columnspan=2, padx=8, pady=8)

            self.inputTextsection = section()
            self.inputTextsection.s = self.inputText
            self.inputTextmenu = tk.Menu(self.window, tearoff=0)
            self.inputTextmenu.add_command(label="复制", command=self.inputTextsection.onCopy)
            self.inputTextmenu.add_separator()
            self.inputTextmenu.add_command(label="粘贴", command=self.inputTextsection.onPaste)
            self.inputTextmenu.add_separator()
            self.inputTextmenu.add_command(label="剪切", command=self.inputTextsection.onCut)
            self.inputText.bind("<Button-3>", lambda event: self.inputTextmenu.post(event.x_root, event.y_root))


            tk.Label(self.window, text="译文:", background='PowderBlue').grid(
                row=2, column=0, sticky=tk.W)

            self.translateBtn = tk.Button(
                self.window, text="翻译", bg='Lavender', command=self.translateBtnClick)
            self.translateBtn.grid(row=2, column=0, padx=40, sticky=tk.W)

            self.OCRLANGUAGE = 'eng'
            self.comboxlist1 = ttk.Combobox(self.window)
            self.comboxlist1["values"] = ("使用百度OCR")
            self.comboxlist1.bind("<<ComboboxSelected>>", self.comboxlist1_OCR)
            self.comboxlist1["state"] = "readonly"
            self.comboxlist1.current(0)
            self.comboxlist1.grid(row=2, column=0, padx=80, columnspan=2, sticky=tk.W)

            self.clearBtn = tk.Button(
                self.window, text="清屏", bg='Lavender', command=self.clearBtnClick)
            self.clearBtn.grid(row=2, column=1, padx=90, sticky=tk.E)

            self.cb1var = tk.IntVar()
            self.cb1var.set(1)
            self.cb1 = tkinter.Checkbutton(
                self.window, text='监听剪切板', background='PowderBlue', variable=self.cb1var)
            self.cb1.grid(row=2, column=0, columnspan=2, sticky=tk.E)

            self.outText = tk.Text(self.window, height=12, width=50)
            self.outText.grid(row=3, column=0, columnspan=2, padx=8, pady=8)

            self.outTextsection = section()
            self.outTextsection.s = self.outText
            self.outTextmenu = tk.Menu(self.window, tearoff=0)
            self.outTextmenu.add_command(label="复制", command=self.outTextsection.onCopy)
            self.outTextmenu.add_separator()
            self.outTextmenu.add_command(label="粘贴", command=self.outTextsection.onPaste)
            self.outTextmenu.add_separator()
            self.outTextmenu.add_command(label="剪切", command=self.outTextsection.onCut)
            self.outText.bind("<Button-3>", lambda event: self.outTextmenu.post(event.x_root, event.y_root))
            # self.window.bind(sequence="<Key>", func=self.outTexeP)

            self.window.state('normal')
            self.window.wm_attributes('-topmost', 1)

            self.window.protocol("WM_DELETE_WINDOW", self.on_closing)
            self.menu_options = (("显示", None, self.showwin),)
            systray = SysTrayIcon(self.filename, "截图翻译工具", self.menu_options, on_quit=self.on_quit_callback)
            systray.start()
            self.logger.info("窗体加载成功")

            self.logger.info("开始加载插件模块")
            self.maindll = WinDLL(resource_path(os.path.join("res", "pymain.dll")))
            dlllist = [i for i in glob.glob(r"*.dll") if i[0]=='p' and i[1] == 'y']
            self.logger.info("搜寻到如下插件{0}" .format(str(dlllist)))
            self.logger.info("开始载入dll")
            self.dlllist = []
            s = create_string_buffer(''.encode(), 8192) #in dll is 8192
            for i in dlllist:
                self.logger.info("正在载入{0}".format(i))
                dll = WinDLL(os.path.join(os.getcwd(), i))
                self.dlllist.append(dll)
                self.logger.info("载入{0}成功".format(i))
                self.logger.info("正在获取{0}的名字".format(i))
                s = create_string_buffer(''.encode(), 9000) #in dll is 8192
                dll.name(s)
                s = string_at(s).decode('utf-8')
                self.logger.info("{0}的名字为:{1}".format(i,s))
                self.comboxlist0["values"] = self.comboxlist0["values"] + (s,)

            self.logger.info("开始启动插件事件监听线程")
            _thread.start_new_thread(self.apiloop, ("",))  # 用于插件的监听
            self.logger.info("插件事件监听线程启动成功")
            self.logger.info("开始启动剪切板事件监听线程")
            _thread.start_new_thread(self.thread_fun, (self.window, self.inputText, self.outText))
            self.logger.info("剪切板事件监听线程启动成功")
            self.logger.info("进入窗体消息循环")
            self.window.mainloop()
        except Exception as e:
            self.logger.error(str(e))
            tk.messagebox.showerror(
                title="致命错误",
                message="请将具体信息发送给开发者:\n网页:https://github.com/super1207/translate\n错误信息:" + str(e))