Example #1
0
    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)
Example #2
0
    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()
Example #3
0
 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()
Example #4
0
    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)
Example #5
0
    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()
Example #6
0
    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()
Example #7
0
    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)
Example #8
0
    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)
Example #9
0
    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.'))
Example #10
0
    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)