def load(pyside=True): if not pyside: raise RuntimeError("unsupported") here = os.path.abspath(os.path.dirname(__file__)).replace("\\", "/") if Helper.is_windows(): import win32api # noinspection PyProtectedMember here = win32api.GetLongPathName(here).replace("\\", "/") style_path = os.path.join(here, "app.stylesheet").replace("\\", "/") # logger.debug(f"here: {here}") # logger.debug(f"style path: {style_path}") style = str() with open(style_path) as fid: style = fid.read().replace("LOCAL_PATH", here) # print(style) if platform.system().lower() == 'darwin': # see issue #12 on github mac_fix = ''' QDockWidget::title { background-color: #31363b; text-align: center; height: 12px; } ''' style += mac_fix return style
def __init__(self): QtWidgets.QMainWindow.__init__(self) logger.info("current configuration:\n%s" % Helper(lib_info=lib_info).package_info()) # set the application name self.name = app_info.app_name self.version = app_info.app_version self.setWindowTitle('{} {}'.format(self.name, self.version)) self.setMinimumSize(QtCore.QSize(500, 800)) self.resize(QtCore.QSize(920, 840)) self.exception_signal.connect(self.show_exception_dialog) # noinspection PyArgumentList _app = QtCore.QCoreApplication.instance() _app.setApplicationName('%s' % self.name) _app.setOrganizationName("HydrOffice") _app.setOrganizationDomain("hydroffice.org") # set icons icon_info = QtCore.QFileInfo(app_info.app_icon_path) self.setWindowIcon(QtGui.QIcon(icon_info.absoluteFilePath())) if Helper.is_windows(): try: # This is needed to display the app icon on the taskbar on # Windows 7 import ctypes app_id = '%s v.%s' % (self.name, self.version) ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID( app_id) except AttributeError as e: logger.debug("Unable to change app icon: %s" % e) self.qax_widget = QAXWidget(main_win=self) self.qax_widget.setDocumentMode(True) self.qax_widget.status_message.connect(self.update_status_bar) self._add_menu_bar() self.status_bar = QtWidgets.QStatusBar() self.setStatusBar(self.status_bar) self.status_bar.showMessage('...') self.setCentralWidget(self.qax_widget)
def __init__(self): QtWidgets.QMainWindow.__init__(self) logger.info("current configuration:\n%s" % Helper(lib_info=lib_info).package_info()) # set the application name self.name = app_info.app_name self.version = app_info.app_version self.setWindowTitle('%s v.%s' % (self.name, self.version)) self.setMinimumSize(QtCore.QSize(500, 500)) self.resize(QtCore.QSize(920, 840)) # noinspection PyArgumentList _app = QtCore.QCoreApplication.instance() _app.setApplicationName('%s' % self.name) _app.setOrganizationName("HydrOffice") _app.setOrganizationDomain("hydroffice.org") # set icons icon_info = QtCore.QFileInfo(app_info.app_icon_path) self.setWindowIcon(QtGui.QIcon(icon_info.absoluteFilePath())) if Helper.is_windows(): try: # This is needed to display the app icon on the taskbar on Windows 7 import ctypes app_id = '%s v.%s' % (self.name, self.version) ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID( app_id) except AttributeError as e: logger.debug("Unable to change app icon: %s" % e) # make tabs self.tabs = QtWidgets.QTabWidget() self.setCentralWidget(self.tabs) self.tabs.setIconSize(QtCore.QSize(52, 52)) # qaqc tab self.tab_qax = QAXWidget(main_win=self) # noinspection PyArgumentList idx = self.tabs.insertTab(0, self.tab_qax, QtGui.QIcon(app_info.app_icon_path), "") self.tabs.setTabToolTip(idx, "QAX") # info self.tab_info = InfoTab(lib_info=lib_info, app_info=app_info, with_online_manual=True, with_offline_manual=True, with_bug_report=True, with_hydroffice_link=True, with_ccom_link=True, with_noaa_link=True, with_unh_link=False, with_license=True, with_noaa_57=True, with_ausseabed_link=True, main_win=self) # noinspection PyArgumentList idx = self.tabs.insertTab( 1, self.tab_info, QtGui.QIcon(os.path.join(self.media, 'info.png')), "") self.tabs.setTabToolTip(idx, "Info") # init default settings settings = QtCore.QSettings() start_tab = settings.value("start_tab") if (start_tab is None) or (start_tab > 0): start_tab = 0 settings.setValue("start_tab", start_tab) self.tabs.setCurrentIndex(start_tab) self.statusBar().setStyleSheet( "QStatusBar{color:rgba(0,0,0,128);font-size: 8pt;}") self.status_bar_normal_style = self.statusBar().styleSheet() self.statusBar().showMessage("%s" % app_info.app_version, 2000) timer = QtCore.QTimer(self) # noinspection PyUnresolvedReferences timer.timeout.connect(self.update_gui) # noinspection PyArgumentList timer.start(300000) # 5 mins self.update_gui()
class TestABCLibHelper(unittest.TestCase): def setUp(self): self.h = Helper(lib_info=LibInfo()) @unittest.skipIf(Helper.is_linux(), "test not supported on Linux") def test_explore_folder(self): self.assertTrue(self.h.explore_folder(__file__)) self.assertFalse(self.h.explore_folder(__file__ + ".fake")) self.assertTrue(self.h.explore_folder(os.path.dirname(__file__))) self.assertFalse(self.h.explore_folder(os.path.dirname(__file__) + "fake")) def test_first_match(self): # fake dict a_dict = { "a": 1, "b": 99, "c": 1, } # test if it gives back the first matching key self.assertTrue(Helper.first_match(a_dict, 1) in ["a", "c"]) # test if it raises with a not-existing value with self.assertRaises(RuntimeError): Helper.first_match(a_dict, 2) def test_is_64bit_os(self): self.assertIsInstance(self.h.is_64bit_os(), bool) def test_is_64bit_python(self): self.assertIsInstance(self.h.is_64bit_python(), bool) def test_is_darwin_linux_windows(self): self.assertIsInstance(self.h.is_darwin(), bool) self.assertIsInstance(self.h.is_linux(), bool) self.assertIsInstance(self.h.is_windows(), bool) self.assertTrue(any([self.h.is_linux(), self.h.is_darwin(), self.h.is_windows()])) def test_is_pydro(self): self.assertIsInstance(self.h.is_pydro(), bool) def test_is_url(self): self.assertTrue(self.h.is_url("https://www.hydroffice.org")) self.assertTrue(self.h.is_url("http://www.hydroffice.org")) self.assertFalse(self.h.is_url("ftp://fake/url")) def test_python_path(self): self.assertTrue(os.path.exists(self.h.python_path())) def test_package_info(self): self.assertIsInstance(self.h.package_info(qt_html=True), str) self.assertIsInstance(self.h.package_info(qt_html=False), str) def test_package_folder(self): self.assertTrue(os.path.exists(self.h.package_folder())) def test_hydroffice_folder(self): self.assertTrue(os.path.exists(self.h.hydroffice_folder()))