class ExtensionMenu: """MDIArea menu for extensions.""" # ---------------------------------------------------------------------- def build_menu_visualization(self, visualization: bool, debugger: Optional[bool] = False) -> None: """Menu for visualizations.""" self.menubar = QMenuBar(self) self.menubar.clear() self.menubar.setMinimumWidth(1e4) self.accent_menubar = QMenuBar(self) # Title if debugger: menu_stimuli = QMenu(f"Debugging: {visualization}") else: if visualization: menu_stimuli = QMenu(f'{visualization } 🞃') else: menu_stimuli = QMenu('Data analysis 🞃') # Add visualizations for viz, path in self.extensions_list: if viz != visualization: menu_stimuli.addAction(QAction(viz, menu_stimuli, triggered=self.set_extension(path))) self.accent_menubar.addMenu(menu_stimuli) # Menu with accent color self.accent_menubar.setStyleSheet(f""" QMenuBar::item {{ background-color: {os.getenv('QTMATERIAL_PRIMARYCOLOR', '#ffffff')}; color: {os.getenv('QTMATERIAL_PRIMARYTEXTCOLOR', '#ffffff')}; }}""") # Set the menu in first position self.menubar.setCornerWidget( self.accent_menubar, corner=Qt.TopLeftCorner) # View menu_view = QMenu("View") if visualization: menu_view.addAction( QAction('Reload', menu_view, triggered=self.reload)) menu_view.addAction( QAction('Save capture', menu_view, triggered=self.save_img)) if not debugger: menu_view.addSeparator() menu_view.addAction( QAction('Close', menu_view, triggered=self.remove)) else: menu_view.setEnabled(False) self.menubar.addMenu(menu_view) # DPI menu_dpi = QMenu("DPI (60)") if visualization: for dpi in [60, 70, 80, 90, 100, 110, 120, 130]: menu_dpi.addAction(QAction( f'{dpi}', menu_dpi, checkable=True, triggered=self.set_dpi(menu_dpi, f'{dpi}', dpi))) if dpi == 60: self.set_dpi(menu_dpi, f'{dpi}', dpi)() else: menu_dpi.setEnabled(False) self.menubar.addMenu(menu_dpi) # ---------------------------------------------------------------------- def build_menu_stimuli(self, visualization: bool, debugger: Optional[bool] = False) -> None: """Menu for stimuli delivery.""" self.menubar = QMenuBar(self) self.menubar.clear() self.accent_menubar = QMenuBar(self) self.accent_menubar.clear() self.menubar.setMinimumWidth(1e4) # Title if debugger: menu_stimuli = QMenu(f"Debugging: {visualization}") else: if visualization: menu_stimuli = QMenu(visualization + ' 🞃') else: menu_stimuli = QMenu('Stimuli' + ' 🞃') for viz, path in self.extensions_list: if viz != visualization: menu_stimuli.addAction(QAction(viz, menu_stimuli, triggered=self.set_extension(path))) # self.menubar.addMenu(menu_stimuli) self.accent_menubar.addMenu(menu_stimuli) self.accent_menubar.setStyleSheet(f""" QMenuBar::item {{ background-color: {os.getenv('QTMATERIAL_PRIMARYCOLOR', '#ffffff')}; color: {os.getenv('QTMATERIAL_PRIMARYTEXTCOLOR', '#ffffff')}; }} """) # self.menubar.addMenu(menu_stimuli) self.menubar.setCornerWidget( self.accent_menubar, corner=Qt.TopLeftCorner) # View menu_view = QMenu("View") if visualization: menu_view.addAction( QAction('Reload', menu_view, triggered=self.reload)) if debugger: menu_view.addAction( QAction('Open subwindow delivery', menu_view, triggered=debugger.open_subwindow)) if not debugger: menu_view.addSeparator() menu_view.addAction( QAction('Close', menu_view, triggered=self.remove)) else: menu_view.setEnabled(False) self.menubar.addMenu(menu_view) # ---------------------------------------------------------------------- def set_dpi(self, menu_dpi, text: str, dpi: int) -> Callable: """Set the DPI value for matplotlib figures.""" def wrap(): [action.setChecked(False) for action in menu_dpi.actions()] [action.setChecked( True) for action in menu_dpi.actions() if action.text() == text] self.main.DPI = dpi menu_dpi.setTitle(f'DPI ({dpi})') return wrap # ---------------------------------------------------------------------- def set_extension(self, visualization: str) -> Callable: """Load extension from menu.""" def wrap(): self.load_extension(visualization) return wrap
class MainWidget(QWidget): data_directory_group_box: DataDirectoryBox error_message: QErrorMessage grid: QVBoxLayout network_grid: Tabs network_widget: NetworkWidget settings_tab: SettingsTabDialog def __init__(self): super().__init__() self.setWindowTitle('Node Launcher') self.error_message = QErrorMessage(self) try: self.network_widget = NetworkWidget() except ZmqPortsNotOpenError as e: self.error_message.showMessage(str(e)) self.error_message.exec_() sys.exit(0) self.network_grid = Tabs(self, self.network_widget) self.network_grid.currentChanged.connect(self.on_tab_change) self.grid = QVBoxLayout() self.settings_tab = SettingsTabDialog( node_set=self.network_widget.node_set) settings_action = QAction('&Settings', self) settings_action.setShortcut(QKeySequence.Preferences) settings_action.triggered.connect(self.settings_tab.show) self.menubar = QMenuBar() self.menubar.setMinimumWidth(self.menubar.sizeHint().width()) file_menu = self.menubar.addMenu('&File') file_menu.addAction(settings_action) self.grid.addWidget(self.menubar) self.grid.addStretch() self.grid.addWidget(self.network_grid) self.setLayout(self.grid) self.settings_tab.bitcoin_tab.change_network.connect( self.change_network) timer = QTimer() timer.singleShot(1000, self.check_version) def on_tab_change(self, index: int): log.info('on_tab_change', index=index) if index == 1: self.network_grid.lncli_widget.input.setFocus() elif index == 2: self.network_grid.bitcoin_cli_widget.input.setFocus() def check_version(self): latest_version = LauncherSoftware().get_latest_release_version() if latest_version is None: return latest_major, latest_minor, latest_bugfix = latest_version.split('.') major, minor, bugfix = NODE_LAUNCHER_RELEASE.split('.') major_upgrade = latest_major > major minor_upgrade = (latest_major == major and latest_minor > minor) bugfix_upgrade = (latest_major == major and latest_minor == minor and latest_bugfix > bugfix) if major_upgrade or minor_upgrade or bugfix_upgrade: message_box = QMessageBox(self) message_box.setTextFormat(Qt.RichText) message_box.setText(UPGRADE) message_box.setInformativeText( f'Your version: {NODE_LAUNCHER_RELEASE}\n' f'New version: {latest_version}') message_box.exec_() def change_network(self, network: Network): self.network_widget.nodes_layout.image_label.set_image( f'bitcoin-{network}.png') def mousePressEvent(self, event): focused_widget = QApplication.focusWidget() if isinstance(focused_widget, QLineEdit): focused_widget.clearFocus() QMainWindow.mousePressEvent(self, event)