def on_downloadRequested(self, downloadItem): #download if downloadItem.isFinished() == False and downloadItem.state() == 0: #print('on_downloadRequested=>%d' % self.mainWindow.index) #filename #the_filename = downloadItem.url().fileName() the_filename = os.path.basename(downloadItem.path()) if len(the_filename) == 0 or "." not in the_filename: cur_time = datetime.datetime.now().strftime('%Y%m%d%H%M%S') the_filename = cur_time + '.' + downloadItem.mimeType().split( '/')[1] if Util.getConfigValue('defaultSavePath'): the_sourceFile = Util.getConfigValue( 'defaultSavePath') + '/' + Util.getRandomFileName( the_filename) else: f = QFileDialog.getSaveFileName(None, "Save File", the_filename, "All files(*.*)") if not f[0]: downloadItem.cancel() return False the_sourceFile = f[0] #the_sourceFile = os.path.join(os.getcwd(), the_filename) # downloadItem.setSavePageFormat(QWebEngineDownloadItem.CompleteHtmlSaveFormat) downloadItem.setPath(the_sourceFile) downloadItem.accept() downloadItem.finished.connect(self.on_downloadFinished) downloadItem.downloadProgress.connect(self.on_downloadProgress)
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 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 start_video_stream(self): server_caps = Util.get_server_config(self.host) core_clock = Util.get_core_clock(self.host) pipeline = self.get_pipeline() self.coreStreamer = GSTInstance(pipeline, core_clock) self.coreStreamer.pipeline.bus.add_signal_watch() self.coreStreamer.pipeline.bus.connect("message::eos",self.on_eos) self.coreStreamer.pipeline.bus.connect("message::error",self.on_eos)
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 setup_core_listener(self): NS_TO_MS = 1000000 offset = 0 server_caps = Util.get_server_config('127.0.0.1') virt_cam_angles, virt_audio_mixes, virt_muxes = self.get_virtual_camera_angles( ) virt_cam_angles = virt_cam_angles.format( video_caps=server_caps['videocaps']) pipelineText = """ tcpserversrc host=0.0.0.0 port={video_port} ! matroskademux name=d ! {decode} ! videoconvert ! videorate ! videoscale ! {video_caps} ! identity name=videosrc ! {server_custom_pipe} {virt_cam_angles} mainmux. audiotestsrc ! audiorate ! {audio_caps} ! tee name=audiosrc ! queue ! mainmux. {virt_audio_mixes} {virt_muxes} matroskamux name=mainmux ! queue max-size-time=4000000000 ! tcpclientsink host=127.0.0.1 port={core_port} """.format(video_port=self.cam_config.get(self.cam_id, "video_port"), video_caps=server_caps['videocaps'], audio_caps=server_caps['audiocaps'], core_port=self.cam_config.get(self.cam_id, "core_port"), server_custom_pipe=self.cam_config.get( self.cam_id, "server_custom_pipe").strip(), virt_cam_angles=virt_cam_angles, virt_audio_mixes=virt_audio_mixes, virt_muxes=virt_muxes, decode=self.cam_config.get(self.cam_id, "decode")) print(pipelineText) pipeline = Gst.parse_launch(pipelineText) offset = int(self.cam_config.get(self.cam_id, "offset")) * NS_TO_MS if offset: print("Using offset: {offset}".format(offset=offset)) pipeline.get_by_name("videosrc").get_static_pad("src").set_offset( offset) core_clock = Util.get_core_clock("127.0.0.1") self.coreStreamer = GSTInstance(pipeline, core_clock) self.coreStreamer.pipeline.bus.add_signal_watch() self.coreStreamer.pipeline.bus.connect("message::eos", self.on_eos) self.coreStreamer.pipeline.bus.connect("message::error", self.on_eos)
def reloadConfig(self): Util.reloadConfig() 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') Util.loadTheme()
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 __init__(self, mainWindow=None): super(DlgSetting, self).__init__() self.setupUi(self) #self.setSizeGripEnabled(False) #self.setFixedSize() self.mainWindow = mainWindow self.config = Util.getConfig() #common cfg = self.config['Default'] index = 0 for k,v in cfg['styleList'].items(): self.combo_theme.addItem(v) if k == cfg['style']: self.combo_theme.setCurrentIndex(index) index += 1 self.chk_close_to_tray.setChecked(cfg['closeToTray']) self.chk_close_confirm.setChecked(cfg['closeConfirm']) #printer printer = Printer() cfg = self.config['Printer'] #defaut index = 0 for i in printer.getPrinterList(): name = i.printerName() self.combo_printer_list.addItem(name) if cfg['defaultPrinter'] and name == cfg['defaultPrinter']: self.combo_printer_list.setCurrentIndex(index) elif not cfg['defaultPrinter'] and i.isDefault(): self.combo_printer_list.setCurrentIndex(index) index += 1 #page size & page margin self.txt_margin.setValue(cfg['margin']) self.chk_fullpage.setChecked(cfg['fullPage']) self.rdo_portrait.setChecked(not cfg['orientation']) self.rdo_landscape.setChecked(cfg['orientation']) self.txt_font.setText(cfg['font']) self.txt_savepath.setText(Util.getConfigValue('defaultSavePath')) self.translateUi()
def run(self): try: self.log.clear() while True: read = self.server.select() for socket in read: if self.server.accept(socket): try: client, ip, packet = self.server.recv() client = ClientProxy(client) self.server.attach(client) host = Util.hostname(ip) d = {'host': host} self.send(d) pkt = self.recv() self.sms(host, pkt['allow'], packet) except MyException: pass else: client = ClientProxy(socket) self.server.dettach(client) except KeyboardInterrupt: pass
def formatSetting(self, setting): t = setting for (k, v) in t.items(): if v in ['true','false']: t[k] = Util.strToBool(v) return t
def log(self, o): if o['str']: msg = '[' + time.strftime("%H:%M:%S", time.localtime()) + ']' + o['str'] self.txt_log.appendPlainText(msg) #auto clear if self.txt_log.toPlainText().count('\n') > 10000: self.txt_log.clear() if o['extra']: if o['extra'][0] == 'test-end': self.btn_test.setDisabled(False) if o['extra'][0] in ['task-end', 'task-stop']: self.btn_start.setDisabled(False) self.btn_resume.setDisabled(False) self.btn_stop.setDisabled(True) if o['extra'][0] == 'loaded': self.txt_email_list.setPlainText(o['extra'][1]) if o['extra'][0] == 'update': self.lbl_result.setText( '成功 %s 条,失败 %s 条' % (format(o['extra'][1], '0,'), format(o['extra'][2], '0,'))) if o['extra'][0] == 'exit': QMessageBox.critical(self, 'Message', o['str'], QMessageBox.Ok, QMessageBox.Ok) sys.exit() elif o['extra'][0] == 'check-end' and o['extra'][1]['allowUpgrade']: reply = QMessageBox.question(self, '提示', "发现新版本,您确认要更新吗?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.Yes: mainScript = os.path.basename( sys.argv[0])[0:os.path.basename(sys.argv[0]).rfind('.' )] Util.runScriptFile(self.mailer.updaterFilePath, ' -s' + mainScript) self.exitAll() #progress if o['extra'][0] in ['progress']: #o['extra'][1]>self.pb_export.value() and self.pb_export.setValue(o['extra'][1]) self.pb_send.setValue(o['extra'][1])
def __init__(self): self.conf = ConfUtil.zen(__file__) daemon = Util.filename(__file__) self.log = Log(daemon) Client.__init__(self, daemon, self.log)
def keyPressEvent(self, event): if event.key() == Qt.Key_A and QApplication.keyboardModifiers() == ( Qt.ControlModifier | Qt.ShiftModifier): print('Ctrl+Shift+A') if Util.isWindows(): from lib.Screenshot import capture capture()
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 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 __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 loadData(self, splash=None): self._widget.loadUrl(Util.getConfigValue('url')) if Util.isWindows(): self.addSystemTray() #check upgrade mainScript = Util.getScriptName() t1 = threading.Thread(target=self.updater.checkUpgrade, args=(False, mainScript)) t1.setDaemon(True) t1.start() #splash if splash: splash.showMessage("Loading... 100%", Qt.AlignHCenter | Qt.AlignBottom, Qt.white) qApp.processEvents()
def on_loadFinished(self, finished): #print('sub finished=>%d,%r' % (self.mainWindow.index, finished)) self.mainWindow.spinner.stop() if not finished: return title = Util.getWindowTitle(self.mainWindow.webview.title()) if self.mainWindow.parentWidget(): self.mainWindow.parentWidget().setWindowTitle(title) else: self.mainWindow.setWindowTitle(title) if self.windowType == 'tab': self.mainWindow.tabWidget.setTabText( Util.getTabIndex(self.mainWindow.tabWidget, self.mainWindow.index), Util.getTabTitle(self.mainWindow.webview.title()))
def run(self): try: self.log.clear() packet = self.recv() self.hosts, self.udp = packet['hosts'], UDP() Thread(target=self.loop).start() while True: if len(self.queue) == 0: continue packet, targets = self.queue.pop(0), [] for host in sorted(self.hosts): d = {'host': host} self.send(d) _packet = self.recv() if not _packet['allow']: continue if 'mac' not in self.hosts[host]: try: mac = ZenTrap.mac(self.hosts[host]['ip']) self.hosts[host]['mac'] = mac except MacException: continue packet['dst_mac'] = self.hosts[host]['mac'] packet['dst_ip'] = self.hosts[host]['ip'] self.udp.send(packet) targets.append(host) if len(targets) == 0: self.log.info('Trap dropped') else: to = ', '.join(map(Util.repr, targets)) if len(targets) > 1: to = '(%s)' % to self.log.info('Trap sent (%s: %s)' % (Util.repr('To'), to)) except KeyboardInterrupt: pass
def __init__(self): self.conf = ConfUtil.zen(__file__) daemon = Util.filename(__file__) self.log = Log(daemon) Client.__init__(self, daemon, self.log) self.server = Server( self.conf['snpp']['host'], self.conf['snpp']['port'] )
def __init__(self, mainWindow): super(WebView, self).__init__() self.mainWindow = mainWindow self.windowType = Util.getConfigValue('newWindowType') #mypage page = WebPage(self) self.setPage(page) #webchannel self.webPrinter = Printer(self, mainWindow) self.channel = QWebChannel() self.channel.registerObject('printer', self.webPrinter) self.page().setWebChannel(self.channel) #event self.loadStarted.connect(self.on_loadStarted) self.loadFinished.connect(self.on_loadFinished) self.urlChanged.connect(self.on_urlChanged) self.page().profile().setHttpUserAgent(Util.getUserAgent()) self.page().profile().downloadRequested.connect( self.on_downloadRequested) self.page().printRequested.connect(self.webPrinter.on_printRequested) self.page().pdfPrintingFinished.connect( self.webPrinter.on_pdfPrintingFinished) self.page().windowCloseRequested.connect( self.webPrinter.on_windowCloseRequested) self.loadProgress.connect(self.on_loadProgress) #self.setZoomFactor(1) if Util.getConfigValue('closeByEscape'): esc_action = QAction(self) esc_action.setShortcut(QKeySequence(Qt.Key_Escape)) self.addAction(esc_action) esc_action.triggered.connect(self.esc)
def __init__(self): zen = ConfUtil.zen() conf = ConfUtil.zen(__file__) conf['localhost'] = zen['localhost'] self.conf = conf daemon = Util.filename(__file__) self.log = Log(daemon) Client.__init__(self, daemon, self.log)
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 changeEvent(self, e): if e.type() == QEvent.WindowStateChange: if self.isMinimized() and Util.isWindows(): if self.settings["chkMinToTray"]: self.hide() elif self.isMaximized(): pass elif self.isFullScreen(): pass elif self.isActiveWindow(): pass elif e.type() == QEvent.ActivationChange: #self.repaint() pass
def start(self, ip): up = False host = Util.hostname(ip) for _ in range(self.conf['start']['retries']): if 'backup' in self.hosts[host] and self.hosts[host]['backup']: up = True break cmd = ['ssh', ip, 'service', 'serviced', 'start'] check_call(cmd, stderr=PIPE) cmd = ['ssh', ip, 'service', 'serviced', 'status'] output = check_output(cmd, stderr=PIPE) if 'running' not in output: sleep(self.conf['start']['timeout']) continue cmd = ['ssh', ip, 'serviced', 'service', 'start', 'Zenoss.core'] output = check_output(cmd) if 'started' not in output: sleep(self.conf['start']['timeout']) continue up = True break if host in self.down: if up: self.mail(host, True) self.down.remove(host) else: if not up: self.mail(host, False) self.down.append(host) return up
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 showTestWindow(self): from main import WebView, WebWindow self.mainWnd = Window() self.mainWnd.setWindowTitle('Test') self.mainWnd.setWindowIcon(Icon.getLogoIcon()) self.testWindow = WebWindow() self.testWindow.loadUrl(Util.getTestPage()) self.mainWnd.setWidget(self.testWindow) #self.mainWnd.titleBar.buttonMinimum.hide() #self.mainWnd.titleBar.buttonMaximum.hide() self.mainWnd.titleBar.buttonMore.hide() self.mainWnd.titleBar.titleLabel.show() self.mainWnd.resizeCenter(670, 500) self.mainWnd.showPopupWindow()
def on_settingOK(self): old_style = self.defaultStyle self.reloadConfig() if self.showWindowIcon: self.titleBar.iconLabel.show() else: self.titleBar.iconLabel.hide() if self.showWindowTitle: self.titleBar.titleLabel.show() else: self.titleBar.titleLabel.hide() #change theme new_style = Util.getConfigValue('style') if old_style != new_style: self._widget.webview.page().runJavaScript( "changeBrowserTheme('%s')" % new_style)
def __init__(self, *args, **kwargs): super(WebWindow, self).__init__(*args, **kwargs) self.windowType = Util.getConfigValue('newWindowType') self.layout = QVBoxLayout(self, spacing=0) self.layout.setContentsMargins(0, 0, 0, 0) #tab if self.windowType == 'tab': self.tabWidget = QTabWidget(self) self.tabWidget.setTabShape(QTabWidget.Triangular) self.tabWidget.setDocumentMode(True) self.tabWidget.setMovable(True) self.tabWidget.setTabsClosable(True) self.tabWidget.tabBar().hide() self.tabWidget.tabCloseRequested.connect(self.on_closeTab) self.layout.addWidget(self.tabWidget) self.setLayout(self.layout)
def process_message(self, peer, mailfrom, rcpttos, data): ip, _ = peer host = Util.hostname(ip) fr = '(%s, %s)' % (Util.repr(host), Util.repr(mailfrom)) fr = '%s: %s' % (Util.repr('From'), fr) to = ', '.join(map(Util.repr, rcpttos)) if len(rcpttos) > 1: to = '(%s)' % to to = '%s: %s' % (Util.repr('To'), to) msg = message_from_string(data) subject = Util.repr(msg['Subject']) subject = '%s: %s' % (Util.repr('Subject'), subject) debug = '(%s, %s, %s)' % (fr, to, subject) d = {'host': host} self.send(d) packet = self.recv() if packet['allow']: if Mail.send(mailfrom, rcpttos, data): self.log.info('Mail sent %s' % debug) else: self.log.critical('Mail not sent %s' % debug) else: self.log.info('Mail dropped %s' % debug)
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'))
import logging from multiprocessing import Queue, Pool import time import sys def thread(p_obj): obj = uTree(p_obj) obj.exec_hash() conn_db.add(obj) conn_db.commit() if __name__ == "__main__": parse = Util.create_parser() param = parse.parse_args(sys.argv[1:]) queue = Queue() start_time = time.time() logging.basicConfig(level=logging.INFO) #format=u'%(filename)s[LINE:%(lineno)d]# %(levelname)-8s [%(asctime)s] %(message)s', #filename="dublicator.log") logging.info("Запущен {0}".format(__name__)) conn_db = CustomSqlAlchemy() conn_db.start_transaction() logging.info(conn_db.get_list_tables()) uTree = conn_db.mapping_exists_table(Tree, 'tree')
tmpPath = os.path.dirname(os.path.realpath(sys.argv[0])) + '/tmp' splashPath = os.path.dirname(os.path.realpath( sys.argv[0])) + '/misc/splash.png' if not os.path.exists(tmpPath): os.mkdir(tmpPath) #scale 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)
def errorHandler(type, value, trace): v = 'Main Error: \n%s' % (''.join( traceback.format_exception(type, value, trace))) print(v) saveError(v) sys.__excepthook__(type, value, trace) sys.excepthook = errorHandler #main if __name__ == '__main__': #scale if Util.isNewSystem(): QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) app = QApplication(sys.argv) if Util.isNewSystem(): app.setAttribute(Qt.AA_EnableHighDpiScaling) app.setQuitOnLastWindowClosed(False) dlg = MainWindow() #single instance if Util.isWindows() and Util.isNewSystem(): import win32con, win32file, pywintypes LOCK_EX = win32con.LOCKFILE_EXCLUSIVE_LOCK LOCK_SH = 0 LOCK_NB = win32con.LOCKFILE_FAIL_IMMEDIATELY __overlapped = pywintypes.OVERLAPPED()
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.'))