def event(self, ev): if ev.type() == QEvent.ToolTip: if self._showToolTips: c = self.charcodeAt(ev.pos()) if c: text = self.getToolTipText(c) if text: rect = self.charcodeRect(c) QToolTip.showText(ev.globalPos(), text, self, rect) ev.accept() return True elif ev.type() == QEvent.QueryWhatsThis: if self._showWhatsThis: ev.accept() return True elif ev.type() == QEvent.WhatsThis: ev.accept() if self._showWhatsThis: c = self.charcodeAt(ev.pos()) text = self.getWhatsThisText(c) if c else None if text: QWhatsThis.showText(ev.globalPos(), text, self) else: QWhatsThis.leaveWhatsThisMode() return True return super(CharMap, self).event(ev)
def event(self, event): """ Overridden to show shortcuts on `?` button of dialog. """ if event.type() == QEvent.EnterWhatsThisMode: from PyQt5.QtWidgets import QWhatsThis QWhatsThis.leaveWhatsThisMode() self.widget.onHelp() return True return QDialog.event(self, event)
def _create_menus(self): """ Create the menus. """ menu_bar = self.menuBar() file_menu = menu_bar.addMenu("&File") file_menu.addAction("&New", self._new_project, QKeySequence.New) file_menu.addAction("&Open...", self._open_project, QKeySequence.Open) self._save_action = file_menu.addAction("&Save", self._save_project, QKeySequence.Save) file_menu.addAction("Save &As...", self._save_as_project, QKeySequence.SaveAs) file_menu.addSeparator() file_menu.addAction("E&xit", self.close, QKeySequence.Quit) menu_bar.addSeparator() help_menu = menu_bar.addMenu("&Help") help_menu.addAction("About pyqtdeploy...", self._about) help_menu.addAction(QWhatsThis.createAction(help_menu))
def enter_whatsthis_mode(self): QWhatsThis.enterWhatsThisMode()
def __whatsThis(self): """ Private slot called in to enter Whats This mode. """ QWhatsThis.enterWhatsThisMode()
def __init__(self, parent, *args, **kwargs): """ Create and fill menu bar widget :param parent: :param args: :param kwargs: """ super(MyMenuBar, self).__init__(*args, **kwargs) self.parent = parent #create action to plot measurement data plot_measurement_data_action = QAction("Plot &measurement data", self) plot_measurement_data_action.setStatusTip( "Select a file containing measurements to plot them") plot_measurement_data_action.setWhatsThis( "Plot measurement data from file into the plotting area.") plot_measurement_data_action.triggered.connect( self.parent.plot_measurement_data) # create action to load input file for inversion and do inversion with errors load_dat_file_action_with_errors = QAction("&Inversion with Errors", self) load_dat_file_action_with_errors.setStatusTip( "Select a file containing measurements with errors for inversion") load_dat_file_action_with_errors.setWhatsThis( "Select a .dat file to invert the measurement results into a density model. Results will be shown in the plotting area. Toolbar at the top of the plotting area is used to manipulate the plot." ) load_dat_file_action_with_errors.triggered.connect( lambda: self.parent.do_inversion(True)) load_dat_file_action_with_errors.showStatusText(self) # create action to load input file for inversion and do inversion without errors load_dat_file_action_no_errors = QAction("&Inversion No Errors", self) load_dat_file_action_no_errors.setStatusTip( "Select a file containing measurements without errors for inversion" ) load_dat_file_action_no_errors.setWhatsThis( "Select a .dat file to invert the measurement results into a density model. Results will be shown in the plotting area. Toolbar at the top of the plotting area is used to manipulate the plot." ) load_dat_file_action_no_errors.triggered.connect( self.parent.do_inversion) load_dat_file_action_no_errors.showStatusText(self) # create action to load input file for interpolation and do interpolation load_interpolation_input_action = QAction("Interpolate data", self) load_interpolation_input_action.setStatusTip( "Select a file containing data for interpolation") load_interpolation_input_action.setWhatsThis( "Select a .dat file to interpolate between the given points. Results will be shown in the plotting area. " ) load_interpolation_input_action.triggered.connect( self.parent.do_interpolation) # create action to plot density model plot_inversion_results_action = QAction( "Plot &inversion result from file", self) plot_inversion_results_action.setStatusTip( "Select a file containing density inversion to plot the model") plot_inversion_results_action.setWhatsThis( "Select a .dens file to plot the density model from a previous inversion" ) plot_inversion_results_action.triggered.connect( functools.partial(self.parent.plot_inversion_results, None)) # create quit action, closes application quit_action = QAction("&Quit", self) quit_action.setStatusTip("Leave application") quit_action.setWhatsThis("Goodbye") quit_action.triggered.connect(qApp.quit) # resolution single asks user for parameters to a density model, which is used to create synthetic # measurement data. The density model is made with a constant background density and a single spike. # This data is inverted and the original density model and the inversion model is plotted resolution_single_action = QAction("Resolution Analysis Single", self) resolution_single_action.setStatusTip("Enter parameters") resolution_single_action.setWhatsThis( "asks user for parameters to a density model, which is used to create " + "synthetic measurement data. This data is inverted and the original density model and the inversion model is plotted" ) resolution_single_action.triggered.connect( self.parent.resolution_analysis_single) # resolution multiple will ask for parameters for a density model, which is used to generate synthetic data. # The density model has a constant background density and a spike at a certain depth. The depth of the spike # will be varied, and the resulting multiple models (after inversion) will be plottet over the spike depth. resolution_multiple_action = QAction("Resolution Analysis Multi", self) resolution_multiple_action.setStatusTip("Enter parameters") resolution_multiple_action.setWhatsThis( "resolution multiple will ask for parameters for a density model, " + "which is used to generate synthetic data. The density model has a constant background density and a spike " + "at a certain depth. The depth of the spike will be varied, and the resulting multiple models " + "(after inversion) will be plottet over the spike depth") resolution_multiple_action.triggered.connect( self.parent.resolution_analysis_multiple) # simple settings action asks user for number of discretization steps get_steps_action = QAction("&Discretization steps", self) get_steps_action.setStatusTip( "Enter number of points to use for discretization") get_steps_action.setWhatsThis( "Set the number of points used to discretize the density function." ) get_steps_action.triggered.connect(self.parent.get_steps_from_user) # settings action that asks the user which norm to use get_norm_action = QAction("&Select norm", self) get_norm_action.setStatusTip("Select a norm to use for the inversion") get_norm_action.setWhatsThis( "Select a norm that is used for the inversion. Different norms influence the resulting model differently." ) get_norm_action.triggered.connect(self.parent.get_norm_from_user) # create help action that explains user interface elements help_action = QWhatsThis.createAction(self) help_action.setStatusTip("Get info about components of this program") help_action.triggered.connect(QWhatsThis.enterWhatsThisMode) # attach actions to menubar file_menu = self.menuBar().addMenu("&File") file_menu.addAction(plot_measurement_data_action) file_menu.addAction(load_dat_file_action_no_errors) file_menu.addAction(load_dat_file_action_with_errors) file_menu.addAction(load_interpolation_input_action) file_menu.addAction(plot_inversion_results_action) file_menu.addAction(quit_action) resolution_menu = self.menuBar().addMenu("&Resolution") resolution_menu.addAction(resolution_single_action) resolution_menu.addAction(resolution_multiple_action) settings_menu = self.menuBar().addMenu("&Settings") settings_menu.addAction(get_steps_action) settings_menu.addAction(get_norm_action) help_menu = self.menuBar().addMenu("&Help") help_menu.addAction(help_action)
def createActions(self, parent=None): self.file_new = QAction(parent) self.file_open = QAction(parent) self.file_open_recent = QAction(parent) self.file_insert_file = QAction(parent) self.file_open_current_directory = QAction(parent) self.file_open_command_prompt = QAction(parent) self.file_save = QAction(parent) self.file_save_as = QAction(parent) self.file_save_copy_as = QAction(parent) self.file_save_all = QAction(parent) self.file_reload = QAction(parent) self.file_reload_all = QAction(parent) self.file_external_changes = QAction(parent) self.file_print_source = QAction(parent) self.file_close = QAction(parent) self.file_close_other = QAction(parent) self.file_close_all = QAction(parent) self.file_quit = QAction(parent) self.file_restart = QAction(parent) self.export_colored_html = QAction(parent) self.edit_undo = QAction(parent) self.edit_redo = QAction(parent) self.edit_cut = QAction(parent) self.edit_copy = QAction(parent) self.edit_copy_colored_html = QAction(parent) self.edit_paste = QAction(parent) self.edit_select_all = QAction(parent) self.edit_select_current_toplevel = QAction(parent) self.edit_select_none = QAction(parent) self.edit_select_full_lines_up = QAction(parent) self.edit_select_full_lines_down = QAction(parent) self.edit_find = QAction(parent) self.edit_find_next = QAction(parent) self.edit_find_previous = QAction(parent) self.edit_replace = QAction(parent) self.edit_preferences = QAction(parent) self.view_next_document = QAction(parent) self.view_previous_document = QAction(parent) self.view_wrap_lines = QAction(parent, checkable=True) self.view_scroll_up = QAction(parent) self.view_scroll_down = QAction(parent) self.window_new = QAction(parent) self.window_fullscreen = QAction(parent) self.window_fullscreen.setCheckable(True) self.help_manual = QAction(parent) self.help_whatsthis = QWhatsThis.createAction(parent) self.help_about = QAction(parent) self.help_bugreport = QAction(parent) # icons self.file_new.setIcon(icons.get('document-new')) self.file_open.setIcon(icons.get('document-open')) self.file_open_recent.setIcon(icons.get('document-open-recent')) self.file_open_current_directory.setIcon(icons.get('folder-open')) self.file_open_command_prompt.setIcon(icons.get('utilities-terminal')) self.file_save.setIcon(icons.get('document-save')) self.file_save_as.setIcon(icons.get('document-save-as')) self.file_save_copy_as.setIcon(icons.get('document-save-as')) self.file_save_all.setIcon(icons.get('document-save-all')) self.file_reload.setIcon(icons.get('reload')) self.file_reload_all.setIcon(icons.get('reload-all')) self.file_print_source.setIcon(icons.get('document-print')) self.file_close.setIcon(icons.get('document-close')) self.file_quit.setIcon(icons.get('application-exit')) self.edit_undo.setIcon(icons.get('edit-undo')) self.edit_redo.setIcon(icons.get('edit-redo')) self.edit_cut.setIcon(icons.get('edit-cut')) self.edit_copy.setIcon(icons.get('edit-copy')) self.edit_paste.setIcon(icons.get('edit-paste')) self.edit_select_all.setIcon(icons.get('edit-select-all')) self.edit_select_current_toplevel.setIcon(icons.get('edit-select')) self.edit_find.setIcon(icons.get('edit-find')) self.edit_find_next.setIcon(icons.get('go-down-search')) self.edit_find_previous.setIcon(icons.get('go-up-search')) self.edit_replace.setIcon(icons.get('edit-find-replace')) self.edit_preferences.setIcon(icons.get('preferences-system')) self.view_next_document.setIcon(icons.get('go-next')) self.view_previous_document.setIcon(icons.get('go-previous')) self.window_new.setIcon(icons.get('window-new')) self.window_fullscreen.setIcon(icons.get('view-fullscreen')) self.help_manual.setIcon(icons.get('help-contents')) self.help_whatsthis.setIcon(icons.get('help-contextual')) self.help_bugreport.setIcon(icons.get('tools-report-bug')) self.help_about.setIcon(icons.get('help-about')) # shortcuts self.file_new.setShortcuts(QKeySequence.New) self.file_open.setShortcuts(QKeySequence.Open) self.file_save.setShortcuts(QKeySequence.Save) self.file_save_as.setShortcuts(QKeySequence.SaveAs) self.file_close.setShortcuts(QKeySequence.Close) self.file_quit.setShortcuts(QKeySequence.Quit) self.edit_undo.setShortcuts(QKeySequence.Undo) self.edit_redo.setShortcuts(QKeySequence.Redo) self.edit_cut.setShortcuts(QKeySequence.Cut) self.edit_copy.setShortcuts(QKeySequence.Copy) self.edit_paste.setShortcuts(QKeySequence.Paste) self.edit_select_all.setShortcuts(QKeySequence.SelectAll) self.edit_select_current_toplevel.setShortcut(QKeySequence(Qt.SHIFT+Qt.CTRL+Qt.Key_B)) self.edit_select_none.setShortcut(QKeySequence(Qt.SHIFT + Qt.CTRL + Qt.Key_A)) self.edit_select_full_lines_up.setShortcut(QKeySequence(Qt.SHIFT + Qt.CTRL + Qt.Key_Up)) self.edit_select_full_lines_down.setShortcut(QKeySequence(Qt.SHIFT + Qt.CTRL + Qt.Key_Down)) self.edit_find.setShortcuts(QKeySequence.Find) self.edit_find_next.setShortcuts(QKeySequence.FindNext) self.edit_find_previous.setShortcuts(QKeySequence.FindPrevious) self.edit_replace.setShortcuts(QKeySequence.Replace) self.edit_preferences.setShortcuts(QKeySequence.Preferences) self.view_next_document.setShortcuts(QKeySequence.Forward) self.view_previous_document.setShortcuts(QKeySequence.Back) self.view_scroll_up.setShortcut(Qt.CTRL + Qt.Key_Up) self.view_scroll_down.setShortcut(Qt.CTRL + Qt.Key_Down) self.window_fullscreen.setShortcuts([QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_F), QKeySequence(Qt.Key_F11)]) self.help_manual.setShortcuts(QKeySequence.HelpContents) # Mac OS X-specific roles? if sys.platform.startswith('darwin'): import macosx if macosx.use_osx_menu_roles(): self.file_quit.setMenuRole(QAction.QuitRole) self.edit_preferences.setMenuRole(QAction.PreferencesRole) self.help_about.setMenuRole(QAction.AboutRole) else: self.file_quit.setMenuRole(QAction.NoRole) self.edit_preferences.setMenuRole(QAction.NoRole) self.help_about.setMenuRole(QAction.NoRole)
def MenuEvents(self, event): if event.text() == _('新建'): self.add_editor_window() elif event.text() == _('打开'): self.open_file() elif event.text() == _('关闭所有窗口'): self.windows_mdi.closeAllSubWindows() elif event.text() == _('排列子窗口'): self.windows_mdi.tileSubWindows() elif event.text() == _('设置'): self.open_config_dialog_window() elif event.text() == _('退出TkPy3'): res = QMessageBox.question(self, _('TkPy3 - 问题'), _('是否退出TkPy3?'), QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if res == QMessageBox.Yes: self.close() elif event.text() == _('格式化代码'): if self.window_mdi_activate_is_pyshell(): return self.windows_mdi.activeSubWindow().widget().autopep8_fix_code() elif event.text() in [_('保存'), _('另存为')]: if self.window_mdi_activate_is_pyshell(): return window = self.windows_mdi.activeSubWindow() widget = window.widget() if widget.file_name and event.text() != _('另存为'): file_name, ok = widget.file_name, True else: file_name, ok = QFileDialog.getSaveFileName( self, event.text(), '', all_file_types) if ok: widget.save_file(file_name) elif event.text() == _('关于TkPy3'): QMessageBox.information( self, _('关于TkPy3'), f"""TkPy3一个使用PyQt5制作的TkPy IDE TkPy3: {__version__} PyQt5: {PYQT_VERSION_STR} TkPy3官网: https://github.com/chenmy1903/TkPy3 TkPy3激活: 激活到期时间: {get_configs()['end_activate_day'] if not isinstance(get_configs()['end_activate_day'], bool) else _("永久激活")} ----------------------------------- {__author__} ©2020 All Rights Reserved. """) elif event.text() == _('TkPy3的依赖'): dialog = RelyDialog() dialog.exec_() elif event.text() == _('打开TkPy3的官方网站'): open_tkpy3_web_page() elif event.text() == _('安装TkPy3的所有依赖'): dialog = InstallDialog() dialog.exec_() elif event.text() == _('运行'): if self.window_mdi_activate_is_pyshell(): return window = self.windows_mdi.activeSubWindow() widget = window.widget() self.MenuEvents(TkPyEventType(_('保存'))) if widget.file_name: widget.run() elif event.text() == _('运行模块'): res, ok = QInputDialog.getText(self, '运行模块', '请输入模块名:') if ok: run_module(res) elif event.text() == _('粘贴'): window = self.windows_mdi.activeSubWindow() widget = window.widget() text = widget.text text.paste() elif event.text() == _('复制'): window = self.windows_mdi.activeSubWindow() widget = window.widget() text = widget.text text.copy() elif event.text() == _('剪切'): window = self.windows_mdi.activeSubWindow() widget = window.widget() text = widget.text text.cut() elif event.text() == _('撤销'): window = self.windows_mdi.activeSubWindow() widget = window.widget() text = widget.text text.undo() elif event.text() == _('撤回'): window = self.windows_mdi.activeSubWindow() widget = window.widget() text = widget.text text.redo() elif event.text() == _('选择全部'): window = self.windows_mdi.activeSubWindow() widget = window.widget() text = widget.text text.selectAll() elif event.text() == _('关于PyQt5'): QApplication.aboutQt() elif event.text() == _('Markdown转Html'): dialog = PyQt5MarkdownDialog() dialog.exec_() elif event.text() == _('重启TkPy3'): self.restart_window() elif event.text() == _('报告Bug'): bug_report_window = BugReportWindow() bug_report_window.exec_() elif event.text() == _('打开Python Shell'): self.open_python_shell() elif event.text() == _('报告TkPy3的功能改进'): NewFunctionReportWindow().exec_() elif event.text() == _('关闭所有子窗口'): self.windows_mdi.closeAllSubWindows() self.not_save_list = [] elif event.text() == _('重新激活TkPy3'): self.assert_activate(True) elif event.text() == _('重置TkPy3的设置'): res = QMessageBox.question(self, _('问题'), _('是否重置所有设置')) if res == QMessageBox.Yes: reset_configs() QMessageBox.information(self, _('提示'), _('重置完成。')) elif event.text() == _('打开终端'): os.system('start cmd /C' + os.path.join(sys.exec_prefix, "python.exe") + ' -m IPython "' + os.path.join( BASE_DIR, 'SystemTemplates/run_terminal_script.py') + '"') elif event.text() == _('保存所有文件'): self.save_files() elif event.text() == _('帮助'): TkPyHelpWidget().exec_() elif event.text() == _('转到行'): if self.window_mdi_activate_is_pyshell(): return text = self.windows_mdi.activeSubWindow().widget().text max_line = len(text.text().split('\n')) at_line = text.getCursorPosition()[0] + 1 line, ok = QInputDialog.getInt(self, _('转到行'), _('请输入行号: '), at_line, 1, max_line) if ok: text.goto_line(line) elif event.text() == _('给TkPy3点个Star'): dialog = StarDialog() dialog.exec_() elif event.text() == _('TkPy3的Github官网'): webbrowser.open(tkpy3_github_url) elif event.text() == _('重新打开文件'): if self.window_mdi_activate_is_pyshell(): return widget = self.windows_mdi.activeSubWindow().widget() if widget.file_name: if widget.file_name in self.not_save_list: res = QMessageBox.question( self, _('问题'), _('文件未保存,是否保存后重新打开文件?'), QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel) if res == QMessageBox.Yes: widget.save_file(widget.file_name) elif res == QMessageBox.Cancel: return widget.save.emit() widget.open(widget.file_name) elif event.text() == _('打开Python包帮助'): PythonPackageHelpDialog().exec() elif event.text() == _('排列Import 语句'): if self.window_mdi_activate_is_pyshell(): return widget = self.windows_mdi.activeSubWindow().widget() widget.sort_imports() elif event.text() == _('Qt文件预览'): dialog = QtUiFileView() dialog.exec_() elif event.text() == _('这是什么'): QWhatsThis.enterWhatsThisMode()
def event(self, event): if event.type() == QEvent.EnterWhatsThisMode: QWhatsThis.leaveWhatsThisMode() QDesktopServices.openUrl(QUrl("https://github.com/ReaJason")) return QDialog.event(self, event)