def run(self): Instance.record("view", JWebView(self.config)) if self.config['window']["transparent"]: from JAK.Utils import JavaScript JavaScript.css( "body, html {background-color:transparent !important;background-image:none !important;}", "JAK") if self.config['webview']["addCSS"]: from JAK.Utils import JavaScript JavaScript.css(self.config['webview']["addCSS"], "user") print("Custom CSS detected") if self.config['webview']["runJavaScript"]: from JAK.Utils import JavaScript JavaScript.send(self.config['webview']["runJavaScript"]) print("Custom JavaScript detected") win = Instance.auto("win", JWindow(self.config)) if self.config['window']["fullScreen"]: screen = getScreenGeometry() win.resize(screen.width(), screen.height()) else: win.resize(win.default_size("width"), win.default_size("height")) win.setFocusPolicy(Qt.WheelFocus) win.show() win.setFocus() win.window_original_position = win.frameGeometry() result = self.exec_() sys.exit(result)
def setBackground(): from JAK.Widgets import FileChooserDialog window = Instance.retrieve("win") image = FileChooserDialog( parent=window, file_type="*.jpeg, *.jpg", title="Chose a image").choose_file() if image and os.path.isfile(image): window = Instance.retrieve("win") window.setBackgroundImage(image) Desktop.saveSettings("background", image)
def _on_click(self, url: str, title=""): view = Instance.retrieve("view") if url.startswith("https"): return lambda: view.setUrl(QUrl(url)) else: msg = url return lambda: InfoDialog(self, title, msg)
def setBranch(branch): p = run(f'pkexec pacman-mirrors --api --set-branch {branch}') result = p.stdout.readline().decode("utf-8") from JAK.Widgets import InfoDialog window = Instance.retrieve("win") msg = f"You are now set on {Desktop.getBranch().capitalize()}, Please sync your new mirrors." InfoDialog(window, "Software Branch", msg)
def _applicationStateChanged_cb(self, event): view = Instance.retrieve("view") page = view.page() # TODO freeze view when inactive to save ram if event == Qt.ApplicationInactive: print("inactive") elif event == Qt.ApplicationActive: print("active")
def restoreDefaults(): home = os.path.expanduser("~") # TODO backup old files run(f"cp -r /etc/skel {home}") from JAK.Widgets import InfoDialog window = Instance.retrieve("win") msg = "Profile defaults have been set on your home directory." InfoDialog(window, "Set Defaults", msg)
def __init__(self, config): super().__init__() self.config = config if config["window"]["backgroundImage"]: # Transparency must be set to True self.label = QLabel(self) self.setObjectName("JAKWindow") self.setBackgroundImage(config["window"]["backgroundImage"]) self.video_corner = False self.center = getScreenGeometry().center() self.setWindowTitle(config['window']["title"]) self.setWindowFlags(config['window']["setFlags"]) self.setWAttribute(Qt.WA_DeleteOnClose) for attr in config['window']["setAttribute"]: self.setWAttribute(attr) if config['window']["state"]: self.setWindowState(config['window']["state"]) if config['window']["icon"] and os.path.isfile( config['window']["icon"]): self.icon = QIcon(config['window']["icon"]) else: print(f"icon not found: {config['window']['icon']}") print("loading default icon:") self.icon = QIcon.fromTheme("applications-internet") view = Instance.retrieve("view") if view: self.view = view self.setCentralWidget(self.view) self.view.iconChanged.connect(self._icon_changed) if config['webview']["online"]: self.view.page().titleChanged.connect(self.status_message) if config['window']["transparent"]: # Set Background Transparency self.setWAttribute(Qt.WA_TranslucentBackground) self.setAutoFillBackground(True) if config['webview']["online"]: # Do not display toolbar or system tray offline if config['window']["toolbar"]: self.toolbar = JToolbar(self, config['window']["toolbar"], self.icon, config['window']["title"]) self.addToolBar(self.toolbar) self.setMenuBar(Menu(self, config['window']["menus"])) else: if config['window']["showHelpMenu"]: self.setMenuBar(Menu(self, config['window']["menus"])) self.view.page().titleChanged.connect(self.status_message) if config['window']["SystemTrayIcon"]: self.system_tray = SystemTrayIcon(self.icon, self, config) if config["debug"]: self.showInspector() self._set_icons()
def full_screen(self): # TODO animate window resize self.win = Instance.retrieve("win") if self.win.isFullScreen(): self.win.showNormal() self.win.hide_show_bar() else: self.win.showFullScreen() self.win.hide_show_bar()
def package_sync_callback(*args): print(args) window = Instance.retrieve("win") msg = f"Would you like to update your software and operating system from {self.branch_lock['branch']} branch now?" Dialog.question(window, " ", msg, update) self.branch_lock["branch"] = "" JavaScript.send(f""" desktop.elem(`#{self.branch_lock["branch"]}-btn`).checked = true """)
def run(self): Instance.record("view", JWebView(self.config)) if self.config["add_CSS"]: from JAK.Utils import JavaScript JavaScript.css(self.config["add_CSS"]) print("Custom CSS detected") if self.config["run_JavaScript"]: from JAK.Utils import JavaScript JavaScript.send(self.config["run_JavaScript"]) print("Custom JavaScript detected") win = Instance.auto("win", JWindow(self.config)) win.resize(win.default_size("width"), win.default_size("height")) win.show() win.window_original_position = win.frameGeometry() result = self.exec_() sys.exit(result)
def _on_click(self, url: str, title=""): if url.startswith("https"): view = Instance.retrieve("view") return lambda: view.setUrl(QUrl(url)) elif url.endswith("()"): from JAK import IPC return lambda: IPC.Communication.send(url) else: msg = url return lambda: InfoDialog(self, title, msg)
def __init__(self, config): """ * :param title:str * :param icon:str * :param transparent:bool * :param toolbar:dict * :param parent: Parent widget """ QMainWindow.__init__(self) self.config = config self.video_corner = False self.center = QDesktopWidget().availableGeometry().center() self.setAttribute(Qt.WA_DeleteOnClose, True) self.setWindowTitle(config["title"]) if config["icon"] and os.path.isfile(config["icon"]): self.icon = QIcon(config["icon"]) else: # TODO detect active icon theme QIcon.setThemeName("Papirus-Maia") icon_paths = QIcon.themeSearchPaths() icon_paths.append("/usr/share/pixmaps") QIcon.setThemeSearchPaths(icon_paths) self.icon = QIcon.fromTheme("applications-internet") view = Instance.retrieve("view") if view: self.view = view self.setCentralWidget(self.view) self.view.iconChanged.connect(self._icon_changed) if config["online"]: self.view.page().titleChanged.connect(self.status_message) if config["transparent"]: # Set Background Transparency self.setAttribute(Qt.WA_TranslucentBackground, True) self.setAutoFillBackground(True) if config["online"]: # Do not display toolbar or system tray offline if config["toolbar"]: self.toolbar = JToolbar(self, config["toolbar"], self.icon, config["title"]) self.addToolBar(self.toolbar) self.system_tray = SystemTrayIcon(self.icon, self, config["title"]) self._set_icons() self.setMenuBar(Menu(self, config["menus"])) if config["debug"]: dock = Inspector("Dev Tools", self) self.addDockWidget(Qt.BottomDockWidgetArea, dock) from JAK.WebEngine import JWebView config["web_contents"] = "http://127.0.0.1:9000" inspector_view = JWebView(config) dock.setWidget(inspector_view)
def toggle(self): # wnck only works on xorg if not self.minimized_windows: self.minimize_windows() win = Instance.retrieve("win") win.activateWindow() elif self.minimized_windows and not self.panel_open: for window in self.minimized_windows: if window and window.is_minimized(): window.unminimize(int(time.time())) self.clearWindows()
def run(self): if "://" not in self.web_contents: self.web_contents = f"https://{self.web_contents}" Instance.record( "view", JWebView(self.title, self.icon, self.web_contents, self.debug, self.transparent, self.online, self.url_rules, self.cookies_path, self.user_agent, self.custom_css, self.custom_js)) win = Instance.auto( "win", JWindow(self.title, self.icon, self.transparent, self.toolbar)) win.resize(win.default_size("width"), win.default_size("height")) win.show() win.window_original_position = win.frameGeometry() if self.debug: print(Instance.get_instances()) result = self.exec_() sys.exit(result)
def callback(sucprocess: Gio.Subprocess, result: Gio.AsyncResult, data): proc.communicate_utf8_finish(result) current_branch = Desktop.getBranch() if current_branch != desired_branch: JavaScript.send(f""" desktop.elem(`#{current_branch}-btn`).checked = true """) notify("Something went wrong", "") else: from JAK.Widgets import JCancelConfirmDialog window = Instance.retrieve("win") msg = f"All Done, would you like to update your software and operating system from {current_branch.upper()} branch now?" JCancelConfirmDialog(window, " ", msg, update)
def __init__(self, title="Jade Application Kit", icon=False, transparent=False, toolbar="", parent=None): """ * :param title:str * :param icon:str * :param transparent:bool * :param toolbar:dict * :param parent: Parent widget """ QMainWindow.__init__(self) self.title = title self.video_corner = False self.center = QDesktopWidget().availableGeometry().center() self.setAttribute(Qt.WA_DeleteOnClose, True) self.setWindowTitle(title) if icon and os.path.isfile(icon): self.icon = QIcon(icon) else: # TODO detect active icon theme QIcon.setThemeName("Papirus-Maia") icon_paths = QIcon.themeSearchPaths() icon_paths.append("/usr/share/pixmaps") QIcon.setThemeSearchPaths(icon_paths) self.icon = QIcon.fromTheme("applications-internet") view = Instance.retrieve("view") if view: self.view = view self.setCentralWidget(self.view) self.view.page().titleChanged.connect(self.status_message) self.view.iconChanged.connect(self._icon_changed) if transparent: # Set Background Transparency self.setAttribute(Qt.WA_TranslucentBackground, True) self.setAutoFillBackground(True) self.toolbar = JToolbar(self, toolbar, self.icon, title) self.addToolBar(self.toolbar) # self.addToolBar(Qt.RightToolBarArea, self.bar) self.system_tray = SystemTrayIcon(self.icon, self, self.title) self._set_icons()
def __init__(self, event): # * self.win = QMainWindow Instance # * self.view = QTWebEngine Instance if event.type() == event.KeyPress: if event.key() == Qt.Key_F11: self.full_screen() elif event.key() == Qt.Key_F12: self.win = Instance.retrieve("win") self.win.corner_window() elif event.modifiers() == Qt.ControlModifier: if event.key() == Qt.Key_Minus: self._zoom_out() elif event.key() == Qt.Key_Equal: self._zoom_in()
def __init__(self, parent, title, msg, on_confirm): """ * :param parent: Parent window * :param window_title:str * :param msg:str * :param on_confirm: Function to execute use parenthesis () """ super().__init__(parent) reply = QMessageBox.question(self, title, msg, QMessageBox.Yes | QMessageBox.No, QMessageBox.No) self.setAttribute(Qt.WA_DeleteOnClose, True) self.setWindowTitle(title) view = Instance.retrieve("view") if view: self.setWindowIcon(view.icon()) if reply == QMessageBox.Yes: on_confirm() else: self.destroy() self.show()
def __init__(self, event, config): # * self.win = QMainWindow Instance # * self.view = QTWebEngine Instance if event.type() == event.KeyPress: if event.key() == Qt.Key_F11: if config['webview']["online"] is True or config['window']["showHelpMenu"] is True: self.full_screen() elif event.key() == Qt.Key_F10: if config['webview']["online"] is True or config['window']["showHelpMenu"] is True: self.win = Instance.retrieve("win") self.win.corner_window() elif event.modifiers() == Qt.ControlModifier: if event.key() == Qt.Key_Minus: self._zoom_out() elif event.key() == Qt.Key_Equal: self._zoom_in()
def _ajust_size_window_cb(self, gdk_screen): primary_screen = getScreenGeometry() win = Instance.retrieve("win") win.resize(primary_screen.width(), primary_screen.height())
def restoreDefaultsDialog(): from JAK.Widgets import JCancelConfirmDialog window = Instance.retrieve("win") msg = "Some of your manual configuration under your HOME folder will be lost, Would you like to proceed?" JCancelConfirmDialog(window, "Restore Defaults", msg, Desktop.restoreDefaults)
def screenToggle(): desktop = Instance.retrieve("desktop") desktop.setPanelVisible(False) desktop.toggle()
def _current_zoom(self): self.view = Instance.retrieve("view") return self.view.zoomFactor()
def showScreen(): win = Instance.retrieve("win") win.activateWindow() run('wmctrl -k on')
def restoreDefaultsDialog(): window = Instance.retrieve("win") msg = "Some of your manual configuration under your HOME folder will be lost, Would you like to proceed?" Dialog.question(window, " ", msg, Desktop.restoreDefaults)