def load_toolbar(self): ## toolbarBox = QToolBar(self) toolbarBox.setFixedWidth(self.AppWidth) self.addToolBar(Qt.TopToolBarArea, toolbarBox) l1_button = QRadioButton(self, text="पातळी१", checkable=True) l1_button.setChecked(True) l1_button.setShortcut('F1') l1_button.setToolTip('F1') l1_button.clicked.connect(self.level1) l2_button = QRadioButton(self, text="पातळी२", checkable=True) l2_button.clicked.connect(self.level2) l2_button.setShortcut('F2') l2_button.setToolTip('F2') l3_button = QRadioButton(self, text="पातळी३", checkable=True) l3_button.clicked.connect(self.level3) l3_button.setShortcut('F3') l3_button.setToolTip('F3') l4_button = QRadioButton(self, text="पातळी४", checkable=True) l4_button.clicked.connect(self.level4) l4_button.setShortcut('F4') l4_button.setToolTip('F4') l5_button = QRadioButton(self, text="पातळी५", checkable=True) l5_button.clicked.connect(self.level5) l5_button.setShortcut('F5') l5_button.setToolTip('F5') ab_button = QToolButton(self, text="About", checkable=True) ab_button.clicked.connect(self.about_app) q_button = QPushButton(self, text='&Quit') q_button.clicked.connect(self.close_application) q_button.setShortcut('Ctrl+Q') q_button.setToolTip('Ctrl+Q') k_button = QPushButton(self) k_button.setIcon(QIcon('Keyboard.png')) k_button.setToolTip('F8') k_button.clicked.connect(self.show_keyboard) self.dialog = KeyboardLayoutWindow(self) group = QButtonGroup(self, exclusive=True) for button in (l1_button, l2_button, l3_button, l4_button, l5_button, ab_button, q_button, k_button): toolbarBox.addWidget(button) button.setFont(button_font) group.addButton(button)
def __init__(self): super(MainWindow, self).__init__() # remove close & maximize window buttons #self.setWindowFlags(Qt.CustomizeWindowHint|Qt.WindowMinimizeButtonHint) self.setMinimumSize(500, 666) #self.setMaximumSize(1000,666) self.mdiArea = QMdiArea() self.mdiArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.mdiArea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.setCentralWidget(self.mdiArea) self.mdiArea.subWindowActivated.connect(self.updateMenus) self.mdiArea.setViewMode(QMdiArea.TabbedView) self.windowMapper = QSignalMapper(self) self.windowMapper.mapped[QWidget].connect(self.setActiveSubWindow) self.child = None self.createActions() self.createMenus() self.createStatusBar() self.updateMenus() self.readSettings() self.setWindowTitle("LEKTURE") mytoolbar = QToolBar() #self.toolbar = self.addToolBar() mytoolbar.addAction(self.newAct) mytoolbar.addAction(self.openAct) mytoolbar.addAction(self.saveAct) mytoolbar.addAction(self.saveAsAct) mytoolbar.addSeparator() mytoolbar.addAction(self.outputsAct) mytoolbar.addAction(self.scenarioAct) self.scenarioAct.setVisible(False) mytoolbar.setMovable(False) mytoolbar.setFixedWidth(60) self.addToolBar(Qt.LeftToolBarArea, mytoolbar)
def create_toolBar(self): """ create the toolbar of the app it contains debug toggle, ola_connection toggle and universes_list """ mytoolbar = QToolBar() # DMX values view mytoolbar.addAction(self.view_dmxList) self.view_dmxList.setVisible(False) # patch ports view mytoolbar.addAction(self.view_patch) self.view_patch.setVisible(True) self.view_patch.setEnabled(False) # new universe action mytoolbar.addAction(self.new_universe) # register universe action mytoolbar.addAction(self.record_universe) self.record_universe.setVisible(False) """ self.devices = QPushButton('Devices') self.devices.setCheckable(True) self.devices.toggled.connect(self.switch_view) self.devices.setEnabled(False) self.record_universe = QPushButton('Save this new universe') self.record_universe.hide() self.record_universe.released.connect(self.register_universe) # create a button to add a new universe self.new_universe = QPushButton('new universe') self.new_universe.released.connect(self.create_universe) mytoolbar.addSeparator() mytoolbar.addWidget(self.devices) mytoolbar.addWidget(self.new_universe) mytoolbar.addWidget(self.record_universe)""" mytoolbar.setMovable(False) mytoolbar.setFixedWidth(110) self.addToolBar(Qt.LeftToolBarArea, mytoolbar) self.toolbar = mytoolbar
class Pireal(QMainWindow): """ Main Window class This class is responsible for installing all application services. """ __SERVICES = {} __ACTIONS = {} # The name of items is the connection text TOOLBAR_ITEMS = [ 'create_database', 'open_database', 'save_database', '', # Is a separator! 'new_query', 'open_query', 'save_query', '', 'relation_menu', '', # 'create_new_relation', # 'remove_relation', # '', # 'add_tuple', # 'delete_tuple', # 'add_column', # 'delete_column', # '', 'execute_queries' ] def __init__(self): QMainWindow.__init__(self) self.setWindowTitle(self.tr("Pireal")) self.setMinimumSize(880, 600) # Load window geometry qsettings = QSettings(settings.SETTINGS_PATH, QSettings.IniFormat) window_maximized = qsettings.value('window_max', True, type=bool) if window_maximized: self.showMaximized() else: size = qsettings.value('window_size') self.resize(size) position = qsettings.value('window_pos') self.move(position) # Toolbar self.toolbar = QToolBar(self) self.toolbar.setFixedWidth(38) self.toolbar.setIconSize(QSize(38, 38)) self.toolbar.setMovable(False) self.addToolBar(Qt.RightToolBarArea, self.toolbar) # Menu bar menubar = self.menuBar() self.__load_menubar(menubar) # Load notification widget after toolbar actions notification_widget = Pireal.get_service("notification") self.toolbar.addWidget(notification_widget) # Message error # self._msg_error_widget = message_error.MessageError(self) # Central widget central_widget = Pireal.get_service("central") central_widget.databaseSaved.connect(notification_widget.show_text) central_widget.querySaved.connect(notification_widget.show_text) central_widget.databaseConected.connect(self.change_title) self.setCentralWidget(central_widget) central_widget.add_start_page() # Install service Pireal.load_service("pireal", self) @classmethod def get_service(cls, service): """ Return the instance of a loaded service """ return cls.__SERVICES.get(service, None) @classmethod def load_service(cls, name, instance): """ Load a service providing the service name and the instance """ cls.__SERVICES[name] = instance @classmethod def get_action(cls, name): """ Return the instance of a loaded QAction """ return cls.__ACTIONS.get(name, None) @classmethod def load_action(cls, name, action): """ Load a QAction """ cls.__ACTIONS[name] = action def __load_menubar(self, menubar): """ This method installs the menubar and toolbar, menus and QAction's, also connects to a slot each QAction. """ # Keymap kmap = keymap.KEYMAP central = Pireal.get_service("central") # Load menu bar rela_actions = [] for item in menu_actions.MENU: menubar_item = menu_actions.MENU[item] menu_name = menubar_item['name'] items = menubar_item['items'] menu = menubar.addMenu(menu_name) for menu_item in items: if isinstance(menu_item, str): # Is a separator menu.addSeparator() else: action = menu_item['name'] obj_name, connection = menu_item['slot'].split(':') obj = central if obj_name.startswith('pireal'): obj = self qaction = menu.addAction(action) # Icon name is connection icon = QIcon(":img/%s" % connection) qaction.setIcon(icon) # Install shortcuts shortcut = kmap.get(connection, None) if shortcut is not None: qaction.setShortcut(shortcut) # The name of QAction is the connection if item == "relation": if connection != "execute_queries": rela_actions.append(qaction) Pireal.load_action(connection, qaction) slot = getattr(obj, connection, None) if isinstance(slot, Callable): qaction.triggered.connect(slot) # Install toolbar # self.__install_toolbar(toolbar_items, rela_actions) self.__install_toolbar(rela_actions) # Disable some actions self.set_enabled_db_actions(False) self.set_enabled_relation_actions(False) self.set_enabled_query_actions(False) self.set_enabled_editor_actions(False) def __install_toolbar(self, rela_actions): menu = QMenu() tool_button = QToolButton() tool_button.setIcon(QIcon(":img/create_new_relation")) tool_button.setMenu(menu) tool_button.setPopupMode(QToolButton.InstantPopup) for item in self.TOOLBAR_ITEMS: if item: if item == "relation_menu": # Install menu for relation menu.addActions(rela_actions) self.toolbar.addWidget(tool_button) else: self.toolbar.addAction(self.__ACTIONS[item]) else: self.toolbar.addSeparator() def __show_status_message(self, msg): status = Pireal.get_service("status") status.show_message(msg) def __on_thread_update_finished(self): self._thread.quit() # Clear notificator notification_widget = Pireal.get_service("notification") notification_widget.clear() msg = QMessageBox(self) if not self._updater.error and self._updater.version: version = self._updater.version msg.setWindowTitle(self.tr("New version available!")) msg.setText( self.tr("Check the web site to " "download <b>Pireal {}</b>".format(version))) download_btn = msg.addButton(self.tr("Download!"), QMessageBox.YesRole) msg.addButton(self.tr("Cancel"), QMessageBox.RejectRole) msg.exec_() r = msg.clickedButton() if r == download_btn: webbrowser.open_new("http://centaurialpha.github.io/pireal") self._thread.deleteLater() self._updater.deleteLater() def change_title(self, title=''): if title: _title = title + " - Pireal " else: _title = "Pireal" self.setWindowTitle(_title) def set_enabled_db_actions(self, value): """ Public method. Enables or disables db QAction """ actions = [ 'new_query', 'open_query', 'close_database', 'save_database', 'save_database_as', 'load_relation' ] for action in actions: qaction = Pireal.get_action(action) qaction.setEnabled(value) def set_enabled_relation_actions(self, value): """ Public method. Enables or disables relation's QAction """ actions = [ 'create_new_relation', 'remove_relation', 'add_tuple', 'delete_tuple', # 'add_column', # 'delete_column' ] for action in actions: qaction = Pireal.get_action(action) qaction.setEnabled(value) def set_enabled_query_actions(self, value): """ Public method. Enables or disables queries QAction """ actions = ['execute_queries', 'save_query'] for action in actions: qaction = Pireal.get_action(action) qaction.setEnabled(value) def set_enabled_editor_actions(self, value): """ Public slot. Enables or disables editor actions """ actions = [ 'undo_action', 'redo_action', 'copy_action', 'cut_action', 'paste_action', 'zoom_in', 'zoom_out', 'comment', 'uncomment', 'search' ] for action in actions: qaction = Pireal.get_action(action) qaction.setEnabled(value) def about_qt(self): """ Show about qt dialog """ QMessageBox.aboutQt(self) def about_pireal(self): """ Show the bout Pireal dialog """ from src.gui.dialogs import about_dialog dialog = about_dialog.AboutDialog(self) dialog.exec_() def report_issue(self): """ Open in the browser the page to create new issue """ webbrowser.open("http://github.com/centaurialpha/pireal/issues/new") def show_hide_menubar(self): """ Change visibility of menu bar """ if self.menuBar().isVisible(): self.menuBar().hide() else: self.menuBar().show() def show_hide_toolbar(self): """ Change visibility of tool bar """ if self.toolbar.isVisible(): self.toolbar.hide() else: self.toolbar.show() def show_error_message(self, text, syntax_error=True): self._msg_error_widget.show_msg(text, syntax_error) self._msg_error_widget.show() def save_user_settings(self): central_widget = Pireal.get_service("central") CONFIG.set_value("lastOpenFolder", central_widget.last_open_folder) CONFIG.set_value("recentFiles", central_widget.recent_databases) # Write settings CONFIG.save_settings() def closeEvent(self, event): self.save_user_settings() # Qt settings qsettings = QSettings(settings.SETTINGS_PATH, QSettings.IniFormat) # # Save window geometry if self.isMaximized(): qsettings.setValue('window_max', True) else: qsettings.setValue('window_max', False) qsettings.setValue('window_pos', self.pos()) qsettings.setValue('window_size', self.size()) central_widget = Pireal.get_service("central") db = central_widget.get_active_db() if db is not None: # Save splitters size db.save_sizes() # Databases unsaved if db.modified: msg = QMessageBox(self) msg.setIcon(QMessageBox.Question) msg.setWindowTitle( self.tr("Algunos cambios no fueron guardados")) msg.setText( self.tr("Desea guardar los cambios en la base de datos?")) cancel_btn = msg.addButton(self.tr("Cancelar"), QMessageBox.RejectRole) msg.addButton(self.tr("No"), QMessageBox.NoRole) yes_btn = msg.addButton(self.tr("Si"), QMessageBox.YesRole) msg.exec_() r = msg.clickedButton() if r == yes_btn: central_widget.save_database() if r == cancel_btn: event.ignore() # Query files unsaved_editors = central_widget.get_unsaved_queries() if unsaved_editors: msg = QMessageBox(self) msg.setIcon(QMessageBox.Question) msg.setWindowTitle(self.tr("Consultas no guardadas")) text = '\n'.join([editor.name for editor in unsaved_editors]) msg.setText( self.tr( "{files}\n\nQuiere guardarlas?".format(files=text))) cancel_btn = msg.addButton(self.tr("Cancelar"), QMessageBox.RejectRole) msg.addButton(self.tr("No"), QMessageBox.NoRole) yes_btn = msg.addButton(self.tr("Si"), QMessageBox.YesRole) msg.exec_() if msg.clickedButton() == yes_btn: for editor in unsaved_editors: central_widget.save_query(editor) if msg.clickedButton() == cancel_btn: event.ignore()
def initUI(self): # windows title and geometry set self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.globalLayout = QVBoxLayout() menuLayout = QHBoxLayout() dataLayout = QHBoxLayout() labelLayout = QToolBar("Labels") self.label_buttons = [QAction(label, self) for label in self.labels] # button_action.setStatusTip("This is your button") for i, label_button in enumerate(self.label_buttons): label_button.triggered.connect(self.toolbarButtonClick(i)) labelLayout.addAction(label_button) label_button.setCheckable(True) # labelLayout.addAction(label_button) self.label_buttons[1].setChecked(True) optionLayout = QToolBar("Options") self.send_button = QAction(QIcon("images/icons8-email-60.png"), "Send Mail", self) self.reload_button = QAction(QIcon("images/icons8-reset-60.png"), "Reload Page", self) logout_button = QAction(QIcon("images/icons8-shutdown-60.png"), "Logout", self) self.send_button.triggered.connect(self.sendMenuToggleClick) self.reload_button.triggered.connect(self.reloadButtonClick) logout_button.triggered.connect(self.logoutButtonClick) optionLayout.addAction(self.send_button) optionLayout.addAction(self.reload_button) optionLayout.addAction(logout_button) self.send_button.setCheckable(True) self.reload_button.setCheckable(True) logout_button.setCheckable(True) # w1.setContentsMargins(0, 0, 0, 0) # w2.setContentsMargins(0, 0, 0, 0) # menuLayout.setSpacing(0) menuLayout.setContentsMargins(0, 0, 0, 0) optionLayout.setFixedWidth(106) menuLayout.addWidget(labelLayout, 10) menuLayout.addWidget(QLabel(self.my_mail), 1) menuLayout.addWidget(optionLayout) # dataview with non editable columns (from, date, subject etc) self.dataView = QTreeView() self.dataView.setRootIsDecorated(False) self.dataView.setAlternatingRowColors(True) self.dataView.setEditTriggers(QAbstractItemView.NoEditTriggers) # content view to display complete email message self.contentView = QPlainTextEdit() self.contentView.setReadOnly(True) self.sendLayout = QVBoxLayout() self.toBox = QLineEdit() self.subjectBox = QLineEdit() self.messageBox = QPlainTextEdit() self.sendButtonBox = QPushButton("Send") self.toBox.setPlaceholderText("To") self.subjectBox.setPlaceholderText("Subject") self.messageBox.setPlaceholderText("Message") self.sendLayout.addWidget(self.toBox) self.sendLayout.addWidget(self.subjectBox) self.sendLayout.addWidget(self.messageBox) self.sendLayout.addWidget(self.sendButtonBox) self.sendLayout.setSpacing(0) self.sendLayout.setContentsMargins(0, 0, 0, 0) # set layout of columns and content box horizontally dataLayout.addWidget(self.dataView, 3) dataLayout.addWidget(self.contentView, 2) dataLayout.addLayout(self.sendLayout) self.contentView.show() self.toBox.hide() self.subjectBox.hide() self.messageBox.hide() self.sendButtonBox.hide() self.sendButtonBox.clicked.connect(self.sendButtonClick) # create mail model to add to data view self.model = self.createMailModel(self) self.dataView.setModel(self.model) self.dataView.clicked.connect(self.rowSelectionClick) self.globalLayout.addLayout(menuLayout, 1) self.globalLayout.addLayout(dataLayout, 20) self.setLayout(self.globalLayout) self.addAllMails() self.autoColumnWidths() self.show() self.reloadButtonClick(True)
class Pireal(QMainWindow): """ Main Window class This class is responsible for installing all application services. """ __SERVICES = {} __ACTIONS = {} # The name of items is the connection text TOOLBAR_ITEMS = [ 'create_database', 'open_database', 'save_database', '', # Is a separator! 'new_query', 'open_query', 'save_query', '', 'relation_menu', '', # 'create_new_relation', # 'remove_relation', # '', # 'add_tuple', # 'delete_tuple', # 'add_column', # 'delete_column', # '', 'execute_queries' ] def __init__(self): QMainWindow.__init__(self) self.setWindowTitle(self.tr("Pireal")) self.setMinimumSize(880, 600) # Load window geometry qsettings = QSettings(settings.SETTINGS_PATH, QSettings.IniFormat) window_maximized = qsettings.value('window_max', True, type=bool) if window_maximized: self.showMaximized() else: size = qsettings.value('window_size') self.resize(size) position = qsettings.value('window_pos') self.move(position) # Toolbar self.toolbar = QToolBar(self) self.toolbar.setFixedWidth(38) self.toolbar.setIconSize(QSize(38, 38)) self.toolbar.setMovable(False) self.addToolBar(Qt.RightToolBarArea, self.toolbar) # Menu bar menubar = self.menuBar() self.__load_menubar(menubar) # Load notification widget after toolbar actions notification_widget = Pireal.get_service("notification") self.toolbar.addWidget(notification_widget) # Message error # self._msg_error_widget = message_error.MessageError(self) # Central widget central_widget = Pireal.get_service("central") central_widget.databaseSaved.connect(notification_widget.show_text) central_widget.querySaved.connect(notification_widget.show_text) central_widget.databaseConected.connect(self.change_title) self.setCentralWidget(central_widget) central_widget.add_start_page() # Install service Pireal.load_service("pireal", self) @classmethod def get_service(cls, service): """ Return the instance of a loaded service """ return cls.__SERVICES.get(service, None) @classmethod def load_service(cls, name, instance): """ Load a service providing the service name and the instance """ cls.__SERVICES[name] = instance @classmethod def get_action(cls, name): """ Return the instance of a loaded QAction """ return cls.__ACTIONS.get(name, None) @classmethod def load_action(cls, name, action): """ Load a QAction """ cls.__ACTIONS[name] = action def __load_menubar(self, menubar): """ This method installs the menubar and toolbar, menus and QAction's, also connects to a slot each QAction. """ # Keymap kmap = keymap.KEYMAP central = Pireal.get_service("central") # Load menu bar rela_actions = [] for item in menu_actions.MENU: menubar_item = menu_actions.MENU[item] menu_name = menubar_item['name'] items = menubar_item['items'] menu = menubar.addMenu(menu_name) for menu_item in items: if isinstance(menu_item, str): # Is a separator menu.addSeparator() else: action = menu_item['name'] obj_name, connection = menu_item['slot'].split(':') obj = central if obj_name.startswith('pireal'): obj = self qaction = menu.addAction(action) # Icon name is connection icon = QIcon(":img/%s" % connection) qaction.setIcon(icon) # Install shortcuts shortcut = kmap.get(connection, None) if shortcut is not None: qaction.setShortcut(shortcut) # The name of QAction is the connection if item == "relation": if connection != "execute_queries": rela_actions.append(qaction) Pireal.load_action(connection, qaction) slot = getattr(obj, connection, None) if isinstance(slot, Callable): qaction.triggered.connect(slot) # Install toolbar # self.__install_toolbar(toolbar_items, rela_actions) self.__install_toolbar(rela_actions) # Disable some actions self.set_enabled_db_actions(False) self.set_enabled_relation_actions(False) self.set_enabled_query_actions(False) self.set_enabled_editor_actions(False) def __install_toolbar(self, rela_actions): menu = QMenu() tool_button = QToolButton() tool_button.setIcon(QIcon(":img/create_new_relation")) tool_button.setMenu(menu) tool_button.setPopupMode(QToolButton.InstantPopup) for item in self.TOOLBAR_ITEMS: if item: if item == "relation_menu": # Install menu for relation menu.addActions(rela_actions) self.toolbar.addWidget(tool_button) else: self.toolbar.addAction(self.__ACTIONS[item]) else: self.toolbar.addSeparator() def __show_status_message(self, msg): status = Pireal.get_service("status") status.show_message(msg) def __on_thread_update_finished(self): self._thread.quit() # Clear notificator notification_widget = Pireal.get_service("notification") notification_widget.clear() msg = QMessageBox(self) if not self._updater.error and self._updater.version: version = self._updater.version msg.setWindowTitle(self.tr("New version available!")) msg.setText(self.tr("Check the web site to " "download <b>Pireal {}</b>".format( version))) download_btn = msg.addButton(self.tr("Download!"), QMessageBox.YesRole) msg.addButton(self.tr("Cancel"), QMessageBox.RejectRole) msg.exec_() r = msg.clickedButton() if r == download_btn: webbrowser.open_new("http://centaurialpha.github.io/pireal") self._thread.deleteLater() self._updater.deleteLater() def change_title(self, title=''): if title: _title = title + " - Pireal " else: _title = "Pireal" self.setWindowTitle(_title) def set_enabled_db_actions(self, value): """ Public method. Enables or disables db QAction """ actions = [ 'new_query', 'open_query', 'close_database', 'save_database', 'save_database_as', 'load_relation' ] for action in actions: qaction = Pireal.get_action(action) qaction.setEnabled(value) def set_enabled_relation_actions(self, value): """ Public method. Enables or disables relation's QAction """ actions = [ 'create_new_relation', 'remove_relation', 'add_tuple', 'delete_tuple', # 'add_column', # 'delete_column' ] for action in actions: qaction = Pireal.get_action(action) qaction.setEnabled(value) def set_enabled_query_actions(self, value): """ Public method. Enables or disables queries QAction """ actions = [ 'execute_queries', 'save_query' ] for action in actions: qaction = Pireal.get_action(action) qaction.setEnabled(value) def set_enabled_editor_actions(self, value): """ Public slot. Enables or disables editor actions """ actions = [ 'undo_action', 'redo_action', 'copy_action', 'cut_action', 'paste_action', 'zoom_in', 'zoom_out', 'comment', 'uncomment', 'search' ] for action in actions: qaction = Pireal.get_action(action) qaction.setEnabled(value) def about_qt(self): """ Show about qt dialog """ QMessageBox.aboutQt(self) def about_pireal(self): """ Show the bout Pireal dialog """ from src.gui.dialogs import about_dialog dialog = about_dialog.AboutDialog(self) dialog.exec_() def report_issue(self): """ Open in the browser the page to create new issue """ webbrowser.open("http://github.com/centaurialpha/pireal/issues/new") def show_hide_menubar(self): """ Change visibility of menu bar """ if self.menuBar().isVisible(): self.menuBar().hide() else: self.menuBar().show() def show_hide_toolbar(self): """ Change visibility of tool bar """ if self.toolbar.isVisible(): self.toolbar.hide() else: self.toolbar.show() def show_error_message(self, text, syntax_error=True): self._msg_error_widget.show_msg(text, syntax_error) self._msg_error_widget.show() def save_user_settings(self): central_widget = Pireal.get_service("central") CONFIG.set_value("lastOpenFolder", central_widget.last_open_folder) CONFIG.set_value("recentFiles", central_widget.recent_databases) # Write settings CONFIG.save_settings() def closeEvent(self, event): self.save_user_settings() # Qt settings qsettings = QSettings(settings.SETTINGS_PATH, QSettings.IniFormat) # # Save window geometry if self.isMaximized(): qsettings.setValue('window_max', True) else: qsettings.setValue('window_max', False) qsettings.setValue('window_pos', self.pos()) qsettings.setValue('window_size', self.size()) central_widget = Pireal.get_service("central") db = central_widget.get_active_db() if db is not None: # Save splitters size db.save_sizes() # Databases unsaved if db.modified: msg = QMessageBox(self) msg.setIcon(QMessageBox.Question) msg.setWindowTitle(self.tr("Algunos cambios no fueron guardados")) msg.setText( self.tr("Desea guardar los cambios en la base de datos?")) cancel_btn = msg.addButton(self.tr("Cancelar"), QMessageBox.RejectRole) msg.addButton(self.tr("No"), QMessageBox.NoRole) yes_btn = msg.addButton(self.tr("Si"), QMessageBox.YesRole) msg.exec_() r = msg.clickedButton() if r == yes_btn: central_widget.save_database() if r == cancel_btn: event.ignore() # Query files unsaved_editors = central_widget.get_unsaved_queries() if unsaved_editors: msg = QMessageBox(self) msg.setIcon(QMessageBox.Question) msg.setWindowTitle(self.tr("Consultas no guardadas")) text = '\n'.join([editor.name for editor in unsaved_editors]) msg.setText(self.tr("{files}\n\nQuiere guardarlas?".format( files=text))) cancel_btn = msg.addButton(self.tr("Cancelar"), QMessageBox.RejectRole) msg.addButton(self.tr("No"), QMessageBox.NoRole) yes_btn = msg.addButton(self.tr("Si"), QMessageBox.YesRole) msg.exec_() if msg.clickedButton() == yes_btn: for editor in unsaved_editors: central_widget.save_query(editor) if msg.clickedButton() == cancel_btn: event.ignore()