class PMGWebBrowser(QWidget): def __init__(self, parent=None, toolbar='standard'): """ :param parent: :param toolbar:多种选项:‘no’,‘standard’,'no_url_input','refresh_only' """ super().__init__(parent) self.webview = PMGWebEngineView() self.setLayout(QVBoxLayout()) self.toolbar = QToolBar() self.url_input = QLineEdit() self.toolbar.addWidget(self.url_input) self.toolbar.addAction('go').triggered.connect( lambda b: self.load_url()) back_action = self.toolbar.addAction('back') back_action.triggered.connect(self.webview.back) forward_action = self.toolbar.addAction('forward') forward_action.triggered.connect(self.webview.forward) self.layout().addWidget(self.toolbar) if toolbar == 'no': self.toolbar.hide() elif toolbar == 'no_url_input': self.url_input.hide() elif toolbar == 'refresh_only': self.url_input.hide() back_action.setEnabled(False) forward_action.setEnabled(True) self.layout().addWidget(self.webview) self.setWindowTitle('My Browser') self.showMaximized() # command:> # jupyter notebook --port 5000 --no-browser --ip='*' --NotebookApp.token='' # --NotebookApp.password='' c:\users\12957\ # self.webview.load(QUrl("http://127.0.0.1:5000/notebooks/desktop/Untitled.ipynb")) # 直接请求页面。 # self.webview.load(QUrl("E:\Python\pyminer_bin\PyMiner\bin\pmgwidgets\display\browser\show_formula.html")) # 直接请求页面。 # self.setCentralWidget(self.webview) def load_url(self, url: str = ''): if url == '': url = self.url_input.text().strip() else: self.url_input.setText(url) self.webview.load(QUrl(url))
class CurveWidgetMixin(PlotManager): def __init__( self, wintitle="guiqwt plot", icon="guiqwt.svg", toolbar=False, options=None, panels=None, ): PlotManager.__init__(self, main=self) self.plot_layout = QGridLayout() if options is None: options = {} self.plot_widget = None self.create_plot(options) if panels is not None: for panel in panels: self.add_panel(panel) self.toolbar = QToolBar(_("Tools")) if not toolbar: self.toolbar.hide() # Configuring widget layout self.setup_widget_properties(wintitle=wintitle, icon=icon) self.setup_widget_layout() # Configuring plot manager self.add_toolbar(self.toolbar, "default") self.register_tools() def setup_widget_layout(self): raise NotImplementedError def setup_widget_properties(self, wintitle, icon): self.setWindowTitle(wintitle) if isinstance(icon, str): icon = get_icon(icon) if icon is not None: self.setWindowIcon(icon) self.setMinimumSize(320, 240) self.resize(640, 480) def register_tools(self): """ Register the plotting dialog box tools: the base implementation provides standard, curve-related and other tools - i.e. calling this method is exactly the same as calling :py:meth:`guiqwt.plot.CurveDialog.register_all_curve_tools` This method may be overriden to provide a fully customized set of tools """ self.register_all_curve_tools() def create_plot(self, options, row=0, column=0, rowspan=1, columnspan=1): """ Create the plotting widget (which is an instance of class :py:class:`guiqwt.plot.BaseCurveWidget`), add it to the dialog box main layout (:py:attr:`guiqwt.plot.CurveDialog.plot_layout`) and then add the `item list` panel May be overriden to customize the plot layout (:py:attr:`guiqwt.plot.CurveDialog.plot_layout`) """ self.plot_widget = BaseCurveWidget(self, **options) self.plot_layout.addWidget(self.plot_widget, row, column, rowspan, columnspan) # Configuring plot manager self.add_plot(self.plot_widget.plot) self.add_panel(self.plot_widget.itemlist)