def addSystemTray(self): self.tray = QSystemTrayIcon() self.icon = Icon.getLogoIcon() self.tray.setIcon(self.icon) self.tray.activated.connect(self.clickTray) #self.tray.messageClicked.connect(self.clickTray) self.tray_menu = QMenu(QApplication.desktop()) self.ShowAction = QAction(Util.lang('show_window', 'Window'), self, triggered=self.showWindow) self.SettingAction = QAction(Util.lang('setting', 'Setting'), self, triggered=self.on_moreMenu_setting) self.QuitAction = QAction(Util.lang('exit', 'Exit'), self, triggered=self.on_moreMenu_exit) self.tray_menu.addAction(self.ShowAction) self.tray_menu.addAction(self.SettingAction) self.tray_menu.addAction(self.QuitAction) self.tray.setContextMenu(self.tray_menu) self.tray.show()
def __init__(self, isMain=True, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.isMain = isMain self.showWindowTitle = Util.getConfigValue('showTitle') self.showWindowIcon = Util.getConfigValue('showWindowIcon') self.defaultStyle = Util.getConfigValue('style') self.closeConfirm = Util.getConfigValue('closeConfirm') self.closeToTray = Util.getConfigValue('closeToTray') if not self.isMain: self.titleBar.buttonMore.hide() if not self.showWindowIcon: self.titleBar.iconLabel.hide() if not self.showWindowTitle: self.titleBar.titleLabel.hide() self.titleBar.settionAction.triggered.disconnect() self.titleBar.settionAction.triggered.connect(self.on_moreMenu_setting) self.titleBar.exitAction.triggered.disconnect() self.titleBar.exitAction.triggered.connect(self.on_moreMenu_exit) self.titleBar.settingLabel.setText(Util.lang('setting', 'Setting')) self.titleBar.exitLabel.setText(Util.lang('exit', 'Exit')) #updater self.updater = Updater() self.updater.signal.connect(self.log) self.updater.init()
def on_moreMenu_exit(self): if self.closeConfirm and self.isMain: reply = MessageBox.question( self.parentWidget(), Util.lang('msg_title', 'Information'), Util.lang('exit_confirm', 'Are you sure to exit?'), QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.Yes: self.exitAll() else: self.exitAll()
def log(self, o): if o['extra']: if o['extra'][0] == 'check-end' and o['extra'][1]['allowUpgrade']: reply = MessageBox.question( self.parentWidget(), Util.lang('msg_title', 'Information'), Util.lang( 'allow_upgrade', 'There is a newer version, do you want to download it?' ), QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) if reply == QMessageBox.Yes: mainScript = Util.getScriptName() self.updater.runScriptFile(self.updater.updaterFilePath, ' -s' + mainScript) sys.exit()
def loadUrl(self, url): c = Util.getTicker() if self.windowType == 'tab': self.webview = WebView(self) self.webview.load(QUrl(url)) #tab tab = QWidget() tab.index = c self.tabWidget.addTab( tab, Util.getTabTitle(Util.lang('loading', 'Loading...'))) #self.tabWidget.setCurrentWidget(tab) layout = QHBoxLayout(tab) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.webview) else: self.webview = WebView(self) self.webview.load(QUrl(url)) self.layout.addWidget(self.webview) self.index = c self.spinner = Loading(self) self.spinner.start()
def closeEvent(self, event): if self.closeToTray and self.isMain: self.hide() event.ignore() elif self.closeConfirm and self.isMain: reply = MessageBox.question( self.parentWidget(), Util.lang('msg_title', 'Information'), Util.lang('exit_confirm', 'Are you sure to exit?'), QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.Yes: self.exitAll() else: event.ignore() elif self.isMain: self.exitAll() else: event.accept()
def on_btn_ok_clicked(self): #default default = self.getDefaultSetting() printer = self.getPrinterSetting() if not Util.saveConfig('Default', default): QMessageBox.critical(self, 'Message', Util.lang('save_config_error', 'Save config.ini file failure.'), QMessageBox.Ok, QMessageBox.Ok) return if not Util.saveConfig('Printer', printer): QMessageBox.critical(self, 'Message', Util.lang('save_config_error', 'Save config.ini file failure.'), QMessageBox.Ok, QMessageBox.Ok) return if self.mainWindow: self.mainWindow.on_settingOK() self.parentWidget().close()
def on_btn_apply_clicked(self): #default default = self.getDefaultSetting() printer = self.getPrinterSetting() if not Util.saveConfig('Default', default): QMessageBox.critical(self, 'Message', Util.lang('save_config_error', 'Save config.ini file failure.'), QMessageBox.Ok, QMessageBox.Ok) return if not Util.saveConfig('Printer', printer): QMessageBox.critical(self, 'Message', Util.lang('save_config_error', 'Save config.ini file failure.'), QMessageBox.Ok, QMessageBox.Ok) return if self.mainWindow: self.mainWindow.on_settingOK() else: Util.reloadConfig() Util.loadTheme()
def on_moreMenu_setting(self): from setting import DlgSetting self.settingDialog = DlgSetting(self) self.settingWindow = Window() self.settingWindow.setWindowTitle(Util.lang('setting', 'Setting')) self.settingWindow.setWindowIcon(Icon.getLogoIcon()) self.settingWindow.setWidget(self.settingDialog) self.settingWindow.titleBar.buttonMinimum.hide() self.settingWindow.titleBar.buttonMaximum.hide() self.settingWindow.titleBar.buttonMore.hide() self.settingWindow.resizeCenter(500, 420) self.settingWindow.showPopupWindow()
def on_downloadFinished(self): self.mainWindow.spinner.stop() js_string = 'alert("%s")' % Util.lang('download_success', 'Download successfully.') self.mainWindow.webview.page().runJavaScript(js_string)
def createWindow(self, QWebEnginePage_WebWindowType): if self.windowType == 'window': #print('createWindow=>%d' % QWebEnginePage_WebWindowType) mainWnd = MainWindow(isMain=False) mainWnd.setWindowTitle( Util.getWindowTitle(Util.lang('loading', 'Loading...'))) mainWnd.setWindowIcon(Icon.getLogoIcon()) mainWnd.resizeCenter(Util.getConfigValue('width'), Util.getConfigValue('height')) #webview webview = WebView(mainWnd) webview.page().profile().setHttpUserAgent(Util.getUserAgent(True)) mainWnd.setWidget(webview) mainWnd.webview = webview mainWnd.show() #loading mainWnd.spinner = Loading(mainWnd) mainWnd.spinner.start() mainWnd.index = Util.getTicker() return webview elif self.windowType == 'tab': #tab tab = QWidget() self.mainWindow.tabWidget.addTab( tab, Util.getTabTitle(Util.lang('loading', 'Loading...'))) self.mainWindow.tabWidget.setCurrentWidget(tab) layout = QHBoxLayout(tab) layout.setContentsMargins(0, 0, 0, 0) #webview mainWnd = tab mainWnd.tabWidget = self.mainWindow.tabWidget #webview new_webview = WebView(mainWnd) new_webview.page().profile().setHttpUserAgent( Util.getUserAgent(True)) layout.addWidget(new_webview) mainWnd.webview = new_webview mainWnd.show() mainWnd.spinner = self.mainWindow.spinner mainWnd.spinner.start() if mainWnd.tabWidget.count() > 1: mainWnd.tabWidget.tabBar().show() mainWnd.index = Util.getTicker() return new_webview else: MessageBox.alert( Util.lang('invalid_window_type', 'Opening a new window is not supported.'))
QApplication.setAttribute(Qt.AA_UseSoftwareOpenGL) QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) app = QApplication(sys.argv) app.setQuitOnLastWindowClosed(False) #single instance #startupTime = Util.timestamp() if Util.getConfigValue('singleInstance'): try: socket = QLocalSocket() serverName = 'CristBrowser-Application' socket.connectToServer(serverName) if socket.waitForConnected(500): QMessageBox.critical( None, Util.lang('alert', 'Alert'), Util.lang( 'run_once', 'This program has been running, you can find it in the system tray.' ), QMessageBox.Ok, QMessageBox.Ok) sys.exit() else: localServer = QLocalServer() localServer.listen(serverName) except Exception as e: QMessageBox.critical(None, Util.lang('alert', 'Alert'), e.__str__(), QMessageBox.Ok, QMessageBox.Ok) sys.exit() #print(Util.timestamp() - startupTime) #splash
def translateUi(self): self.tab_other.setTabText(0, Util.lang('common', 'Common')) self.tab_other.setTabText(1, Util.lang('printer', 'Printer')) self.tab_other.setTabText(2, Util.lang('others', 'Others')) self.group_theme.setTitle(Util.lang('theme', 'Theme')) self.group_ui.setTitle(Util.lang('ui', 'User interface')) self.group_printer.setTitle(Util.lang('default_printer', 'Default printer')) self.group_document.setTitle(Util.lang('document', 'Document')) self.group_other.setTitle(Util.lang('others', 'Others')) self.group_savepath.setTitle(Util.lang('save_path', 'Default file save directory')) self.rdo_portrait.setText(Util.lang('portrait', 'Portrait')) self.rdo_landscape.setText(Util.lang('landscape', 'Landscape')) self.chk_close_to_tray.setText(Util.lang('close_to_tray', 'Close to system tray')) self.chk_close_confirm.setText(Util.lang('close_confirm', 'Closing confirmation')) self.chk_fullpage.setText(Util.lang('fullpage', 'Fullpage printing')) self.lbl_font.setText(Util.lang('font', 'Font')) self.lbl_margin.setText(Util.lang('margin', 'Margin')) self.lbl_font.setText(Util.lang('font', 'Font')) self.btn_test.setText(Util.lang('test', 'Test')) self.btn_ok.setText(Util.lang('ok', 'OK')) self.btn_apply.setText(Util.lang('apply', 'Apply')) self.btn_cancel.setText(Util.lang('cancel', 'Cancel')) self.btn_font.setText(Util.lang('select', 'Select')) self.btn_browse_savepath.setText(Util.lang('select', 'Select')) self.btn_clear.setText(Util.lang('clear', 'Clear'))
self.btn_clear.setText(Util.lang('clear', 'Clear')) #main if __name__ == '__main__': app = QApplication(sys.argv) Util.loadTheme() settingWindow = DlgSetting() #testing #settingWindow.showTestWindow() #sys.exit(app.exec_()) mainWnd = Window() mainWnd.setWindowTitle(Util.lang('setting', 'Setting')) mainWnd.setWindowIcon(Icon.getLogoIcon()) mainWnd.center() mainWnd.setWidget(settingWindow) mainWnd.titleBar.buttonMinimum.hide() mainWnd.titleBar.buttonMaximum.hide() mainWnd.titleBar.buttonMore.hide() mainWnd.resizeCenter(500,420) mainWnd.show() sys.exit(app.exec_())