def test_change_url(self): if not QtWidgets.qApp: QtWidgets.QApplication([]) w = Browser() initial_url = w.url() self.assertGreater(len(initial_url), 0) new_url = "https://www.google.com/" w.change_url(new_url) self.assertEqual(new_url, w.url())
def test_type_url(self): if not QtWidgets.qApp: QtWidgets.QApplication([]) w = Browser() initial_url = w.url() new_url = "https://www.google.com/" QtTest.QTest.keyClick(w.address_line_edit, QtCore.Qt.Key_Enter) # remove current characters for _ in initial_url: QtTest.QTest.keyClick(w.address_line_edit, QtCore.Qt.Key_Backspace) QtTest.QTest.keyClicks(w.address_line_edit, new_url, 0, 1) QtTest.QTest.keyClick(w.address_line_edit, QtCore.Qt.Key_Enter) self.assertEqual(new_url, w.url())
import sys import logging from PySide2 import QtWidgets from hyo2.abc.app.widgets.browser.browser import Browser from hyo2.abc.lib.logging import set_logging logger = logging.getLogger(__name__) set_logging(ns_list=["hyo2.abc"]) app = QtWidgets.QApplication([]) w = Browser() w.show() # w.change_url("https://www.google.com") # logger.debug("current url: %s" % w.url()) sys.exit(app.exec_())
def __init__(self, main_win: QtWidgets.QMainWindow, lib_info: LibInfo, app_info: AppInfo, tab_name: str = "App Info Tab", start_url: Optional[str] = None, default_url: str = "http://www.hydroffice.org", with_online_manual: bool = False, with_offline_manual: bool = False, with_bug_report: bool = False, with_hydroffice_link: bool = False, with_ccom_link: bool = False, with_noaa_link: bool = False, with_unh_link: bool = False, with_license: bool = False, with_noaa_57: bool = False, with_ausseabed_link: bool = False): super().__init__(main_win) self._li = lib_info self._ai = app_info self.defaul_url = default_url self.settings = QtCore.QSettings() self.setWindowTitle(tab_name) self.setContentsMargins(0, 0, 0, 0) # add main frame and layout self.frame = QtWidgets.QFrame(parent=self) self.setCentralWidget(self.frame) self.frame_layout = QtWidgets.QVBoxLayout() self.frame.setLayout(self.frame_layout) if start_url is None: start_url = Helper(lib_info=self._li).web_url() self.start_url = start_url # add browser self.browser = Browser(url=self.start_url) self.frame_layout.addWidget(self.browser) # add about dialog self.about_dlg = AboutDialog(lib_info=self._li, app_info=self._ai, parent=self, with_locale_tab=True, with_gdal_tab=True) self.about_dlg.hide() icon_size = QtCore.QSize(self._ai.app_toolbars_icon_size, self._ai.app_toolbars_icon_size) # noinspection PyArgumentList self.toolbar = self.addToolBar('Shortcuts') self.toolbar.setIconSize(icon_size) # home self.home_action = QtWidgets.QAction( QtGui.QIcon(os.path.join(self.media, 'home.png')), 'Home page', self) # noinspection PyUnresolvedReferences self.home_action.triggered.connect(self.load_default) self.toolbar.addAction(self.home_action) # online manual self.open_online_manual_action = None if with_online_manual: self.open_online_manual_action = QtWidgets.QAction( QtGui.QIcon(os.path.join(self.media, 'online_manual.png')), 'Online Manual', self) self.open_online_manual_action.setStatusTip( 'Open the online manual') # noinspection PyUnresolvedReferences self.open_online_manual_action.triggered.connect( self.open_online_manual) self.toolbar.addAction(self.open_online_manual_action) # offline manual self.open_offline_manual_action = None if with_offline_manual: self.open_offline_manual_action = QtWidgets.QAction( QtGui.QIcon(os.path.join(self.media, 'offline_manual.png')), 'Offline Manual', self) self.open_offline_manual_action.setStatusTip( 'Open the offline manual') # noinspection PyUnresolvedReferences self.open_offline_manual_action.triggered.connect( self.open_offline_manual) self.toolbar.addAction(self.open_offline_manual_action) # bug report self.fill_bug_report_action = None if with_bug_report: self.fill_bug_report_action = QtWidgets.QAction( QtGui.QIcon(os.path.join(self.media, 'bug.png')), 'Bug Report', self) self.fill_bug_report_action.setStatusTip('Fill a bug report') # noinspection PyUnresolvedReferences self.fill_bug_report_action.triggered.connect(self.fill_bug_report) self.toolbar.addAction(self.fill_bug_report_action) self.toolbar.addSeparator() # HydrOffice.org self.hyo_action = None if with_hydroffice_link: self.hyo_action = QtWidgets.QAction( QtGui.QIcon(os.path.join(self.media, 'hyo.png')), 'HydrOffice.org', self) # noinspection PyUnresolvedReferences self.hyo_action.triggered.connect(self.load_hydroffice_org) self.toolbar.addAction(self.hyo_action) # noaa self.noaa_action = None if with_noaa_link: self.noaa_action = QtWidgets.QAction( QtGui.QIcon(os.path.join(self.media, 'noaa.png')), 'nauticalcharts.noaa.gov', self) # noinspection PyUnresolvedReferences self.noaa_action.triggered.connect(self.load_noaa_ocs_gov) self.toolbar.addAction(self.noaa_action) # ccom.unh.edu self.ccom_action = None if with_ccom_link: self.ccom_action = QtWidgets.QAction( QtGui.QIcon(os.path.join(self.media, 'ccom.png')), 'ccom.unh.edu', self) # noinspection PyUnresolvedReferences self.ccom_action.triggered.connect(self.load_ccom_unh_edu) self.toolbar.addAction(self.ccom_action) # unh.edu self.unh_action = None if with_unh_link: self.unh_action = QtWidgets.QAction( QtGui.QIcon(os.path.join(self.media, 'unh.png')), 'unh.edu', self) # noinspection PyUnresolvedReferences self.unh_action.triggered.connect(self.load_unh_edu) self.toolbar.addAction(self.unh_action) # http://www.ausseabed.gov.au/ self.ausseabed_action = None if with_ausseabed_link: self.ausseabed_action = QtWidgets.QAction( QtGui.QIcon(os.path.join(self.media, 'ausseabed.png')), 'ausseabed.gov.au', self) # noinspection PyUnresolvedReferences self.ausseabed_action.triggered.connect(self.load_ausseabed_gov_au) self.toolbar.addAction(self.ausseabed_action) self.toolbar.addSeparator() self.noaa_support_action = None if with_noaa_57: # noaa support self.toolbar.addSeparator() self.noaa_support_action = QtWidgets.QAction( QtGui.QIcon(os.path.join(self.media, 'noaa_support.png')), 'NOAA S57 Support Files', self) # noinspection PyUnresolvedReferences self.noaa_support_action.triggered.connect(self.show_noaa_support) self.toolbar.addAction(self.noaa_support_action) self.toolbar.addSeparator() # license self.license_action = None if with_license: self.license_action = QtWidgets.QAction( QtGui.QIcon(os.path.join(self.media, 'license.png')), 'License', self) self.license_action.setStatusTip('License info') # noinspection PyUnresolvedReferences self.license_action.triggered.connect(self.load_license) self.toolbar.addAction(self.license_action) # authors self.authors_dialog = None self.authors_action = QtWidgets.QAction( QtGui.QIcon(os.path.join(self.media, 'authors.png')), 'Contacts', self) self.authors_action.setStatusTip('Contact Authors') # noinspection PyUnresolvedReferences self.authors_action.triggered.connect(self.show_authors) self.toolbar.addAction(self.authors_action) # about self.show_about_action = QtWidgets.QAction( QtGui.QIcon(self._ai.app_icon_path), 'About', self) self.show_about_action.setStatusTip('Info about %s' % app_info.app_name) # noinspection PyUnresolvedReferences self.show_about_action.triggered.connect(self.about_dlg.switch_visible) self.toolbar.addAction(self.show_about_action)