def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.setWindowTitle(__namever__) self.setWindowIcon(icons.get_icon('master')) if platform.system() == 'Windows': import ctypes myappid = 'gwhat_application' # arbitrary string ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID( myappid) # Setup the project manager. and data managers. splash.showMessage("Initializing project and data managers...") self.pmanager = ProjetManager(self) self.pmanager.currentProjetChanged.connect(self.new_project_loaded) # Setup the data manager. self.dmanager = DataManager(parent=self, pm=self.pmanager) self.dmanager.setMaximumWidth(250) self.dmanager.sig_new_console_msg.connect(self.write2console) # Generate the GUI. self.__initUI__() splash.finish(self) self.showMaximized() # Load the last opened project. projectfile = get_path_from_configs('main', 'last_project_filepath') result = self.pmanager.load_project(projectfile) if result is False: self.tab_hydrograph.setEnabled(False) self.tab_hydrocalc.setEnabled(False)
def datamanager(project, qtbot): datamanager = DataManager(projet=project, pytesting=True) qtbot.addWidget(datamanager) qtbot.addWidget(datamanager.new_waterlvl_win) qtbot.addWidget(datamanager.new_weather_win) datamanager.show() return datamanager
def hydrocalc_bot(qtbot): pf = os.path.join(working_dir, "@ new-prô'jèt!.gwt") pr = ProjetReader(pf) dm = DataManager() dm.set_projet(pr) hydrocalc = WLCalc(dm) qtbot.addWidget(hydrocalc) return hydrocalc, qtbot
def hydroprint_bot(qtbot): pf = os.path.join(working_dir, "@ new-prô'jèt!.gwt") pr = ProjetReader(pf) dm = DataManager() dm.set_projet(pr) hydroprint = HydroprintGUI(dm) qtbot.addWidget(hydroprint) qtbot.addWidget(hydroprint.page_setup_win) return hydroprint, qtbot
def data_manager_bot(qtbot): data_manager = DataManager(projet=ProjetReader(projetpath), pytesting=True) qtbot.addWidget(data_manager) qtbot.addWidget(data_manager.new_waterlvl_win) qtbot.addWidget(data_manager.new_weather_win) return data_manager, qtbot
def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.setWindowTitle(__namever__) self.setWindowIcon(icons.get_icon('master')) if platform.system() == 'Windows': import ctypes myappid = 'gwhat_application' # arbitrary string ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID( myappid) # Setup preferences : self.whatPref = WHATPref(self) self.projectfile = self.whatPref.projectfile self.projectdir = osp.dirname(self.projectfile) # Setup the project and data managers : splash.showMessage("Initializing project and data managers...") self.pmanager = ProjetManager(self) self.pmanager.currentProjetChanged.connect(self.new_project_loaded) self.dmanager = DataManager(parent=self, pm=self.pmanager) self.dmanager.setMaximumWidth(250) # Generate the GUI : self.__initUI__() splash.finish(self) self.showMaximized() # Load the last opened project : result = self.pmanager.load_project(self.projectfile) if result is False: self.tab_dwnld_data.setEnabled(False) self.tab_fill_weather_data.setEnabled(False) self.tab_hydrograph.setEnabled(False) self.tab_hydrocalc.setEnabled(False)
def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.setWindowTitle(__namever__) self.setWindowIcon(icons.get_icon('master')) if platform.system() == 'Windows': import ctypes myappid = 'gwhat_application' # arbitrary string ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID( myappid) # Setup preferences : self.whatPref = WHATPref(self) self.projectfile = self.whatPref.projectfile self.projectdir = osp.dirname(self.projectfile) # Setup the project and data managers. splash.showMessage("Initializing project and data managers...") self.pmanager = ProjetManager(self) self.pmanager.currentProjetChanged.connect(self.new_project_loaded) self.dmanager = DataManager(parent=self, pm=self.pmanager) self.dmanager.setMaximumWidth(250) self.dmanager.sig_new_console_msg.connect(self.write2console) # Generate the GUI. self.__initUI__() splash.finish(self) self.showMaximized() # Load the last opened project : result = self.pmanager.load_project(self.projectfile) if result is False: self.tab_dwnld_data.setEnabled(False) self.tab_fill_weather_data.setEnabled(False) self.tab_hydrograph.setEnabled(False) self.tab_hydrocalc.setEnabled(False)
def datamanager(project): datamanager = DataManager() datamanager.set_projet(project) return datamanager
class MainWindow(QMainWindow): def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.setWindowTitle(__namever__) self.setWindowIcon(icons.get_icon('master')) if platform.system() == 'Windows': import ctypes myappid = 'gwhat_application' # arbitrary string ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID( myappid) # Setup preferences : self.whatPref = WHATPref(self) self.projectfile = self.whatPref.projectfile self.projectdir = osp.dirname(self.projectfile) # Setup the project and data managers : splash.showMessage("Initializing project and data managers...") self.pmanager = ProjetManager(self) self.pmanager.currentProjetChanged.connect(self.new_project_loaded) self.dmanager = DataManager(parent=self, pm=self.pmanager) self.dmanager.setMaximumWidth(250) # Generate the GUI : self.__initUI__() splash.finish(self) self.showMaximized() # Load the last opened project : result = self.pmanager.load_project(self.projectfile) if result is False: self.tab_dwnld_data.setEnabled(False) self.tab_fill_weather_data.setEnabled(False) self.tab_hydrograph.setEnabled(False) self.tab_hydrocalc.setEnabled(False) def __initUI__(self): # ---- TAB WIDGET # download weather data : splash.showMessage("Initializing download weather data...") self.tab_dwnld_data = DwnldWeatherWidget(self) self.tab_dwnld_data.set_workdir(self.projectdir) # gapfill weather data : splash.showMessage("Initializing gapfill weather data...") self.tab_fill_weather_data = GapFillWeatherGUI(self) self.tab_fill_weather_data.set_workdir(self.projectdir) # hydrograph : splash.showMessage("Initializing plot hydrograph...") self.tab_hydrograph = HydroPrint.HydroprintGUI(self.dmanager) splash.showMessage("Initializing analyse hydrograph...") self.tab_hydrocalc = HydroCalc.WLCalc(self.dmanager) self.tab_hydrocalc.sig_new_mrc.connect( self.tab_hydrograph.mrc_wl_changed) self.tab_hydrocalc.rechg_eval_widget.sig_new_gluedf.connect( self.tab_hydrograph.glue_wl_changed) # ---- TABS ASSEMBLY self.tab_widget = TabWidget() self.tab_widget.addTab(self.tab_dwnld_data, 'Download Weather') self.tab_widget.addTab(self.tab_fill_weather_data, 'Gapfill Weather') self.tab_widget.addTab(self.tab_hydrograph, 'Plot Hydrograph') self.tab_widget.addTab(self.tab_hydrocalc, 'Analyze Hydrograph') self.tab_widget.setCornerWidget(self.pmanager) self.tab_widget.currentChanged.connect(self.sync_datamanagers) # ---- Main Console splash.showMessage("Initializing main window...") self.main_console = QTextEdit() self.main_console.setReadOnly(True) self.main_console.setLineWrapMode(QTextEdit.NoWrap) style = 'Regular' family = StyleDB().fontfamily size = self.whatPref.fontsize_console fontSS = ('font-style: %s;' 'font-size: %s;' 'font-family: %s;') % (style, size, family) self.main_console.setStyleSheet("QWidget{%s}" % fontSS) msg = '<font color=black>Thanks for using %s.</font>' % __appname__ self.write2console(msg) self.write2console('<font color=black>' 'Please report any bug or wishful feature at' ' [email protected].' '</font>') # ---- Signal Piping issuer = self.tab_dwnld_data issuer.ConsoleSignal.connect(self.write2console) issuer = self.tab_fill_weather_data issuer.ConsoleSignal.connect(self.write2console) issuer = self.tab_hydrograph issuer.ConsoleSignal.connect(self.write2console) # ---- Splitter Widget splitter = QSplitter(self) splitter.setOrientation(Qt.Vertical) splitter.addWidget(self.tab_widget) splitter.addWidget(self.main_console) splitter.setCollapsible(0, True) splitter.setStretchFactor(0, 100) # Forces initially the main_console to its minimal height: splitter.setSizes([100, 1]) # ---- Main Grid main_widget = QWidget() self.setCentralWidget(main_widget) mainGrid = QGridLayout(main_widget) mainGrid.addWidget(splitter, 0, 0) mainGrid.addWidget(self.tab_fill_weather_data.pbar, 1, 0) mainGrid.addWidget(self.tab_dwnld_data.pbar, 2, 0) mainGrid.addWidget(self.tab_hydrocalc.rechg_eval_widget.progressbar, 3, 0) def write2console(self, text): """ This function is the bottle neck through which all messages writen in the console must go through. """ textime = '<font color=black>[%s] </font>' % ctime()[4:-8] self.main_console.append(textime + text) def sync_datamanagers(self): """ Move the data manager from tab _Plot Hydrograph_ to tab _Analyze Hydrograph_ and vice-versa. """ current = self.tab_widget.tabBar().currentIndex() if current == 3: self.tab_hydrocalc.right_panel.addWidget(self.dmanager, 0, 0) elif current == 2: self.tab_hydrograph.right_panel.addWidget(self.dmanager, 0, 0) def new_project_loaded(self): """Handles when a new project is loaded in the project manager.""" filename = self.pmanager.projet.filename dirname = os.path.dirname(filename) # Update WHAT.pref file : self.whatPref.projectfile = filename self.whatPref.save_pref_file() # Update UI : self.tab_dwnld_data.setEnabled(True) self.tab_fill_weather_data.setEnabled(True) self.tab_hydrograph.setEnabled(True) self.tab_hydrocalc.setEnabled(True) # Update the child widgets : # dwnld_weather_data lat = self.pmanager.projet.lat lon = self.pmanager.projet.lon self.tab_dwnld_data.set_workdir(dirname) self.tab_dwnld_data.set_station_browser_latlon((lat, lon)) # fill_weather_data self.tab_fill_weather_data.set_workdir(dirname) self.tab_fill_weather_data.load_data_dir_content() def show(self): """Qt method override to center the app on the screen.""" super(MainWindow, self).show() qr = self.frameGeometry() cp = QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) def closeEvent(self, event): """Qt method override to close the project before close the app.""" print('Closing projet') self.pmanager.close_projet() print('Closing GWHAT') event.accept()
def test_last_opened_datasets(qtbot, projectpath): """ Test that the data manager recall correctly the water level and weather datasets that were last opened when opening a new project. Cover the new feature added in PR #267. """ datamanager = DataManager(projet=ProjetReader(projectpath)) qtbot.addWidget(datamanager) datamanager.show() # Add some water level dataset. for name in ['wldset1', 'wldset2', 'wldset3']: datamanager.new_wldset_imported(name, WLDataFrame(WLFILENAME)) assert datamanager.get_current_wldset().name == 'wldset3' # Add some weather dataset. for name in ['wxdset1', 'wxdset2', 'wxdset3']: datamanager.new_wxdset_imported(name, WXDataFrame(WXFILENAME)) assert datamanager.get_current_wxdset().name == 'wxdset3' # Change the current water level and weather datasets. datamanager.set_current_wldset('wldset2') assert datamanager.get_current_wldset().name == 'wldset2' datamanager.set_current_wxdset('wxdset2') assert datamanager.get_current_wxdset().name == 'wxdset2' # Close the datamanager and its project. datamanager.projet.close() datamanager.close() # Create a new datamanager and assert that the last opened water level # and weather datasets are remembered correctly. datamanager2 = DataManager(projet=ProjetReader(projectpath)) qtbot.addWidget(datamanager2) datamanager2.show() assert datamanager2.get_current_wldset().name == 'wldset2' assert datamanager2.get_current_wxdset().name == 'wxdset2'
cp = self.parentWidget().mapToGlobal(QPoint(wp / 2., hp / 2.)) else: cp = QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) self.setFixedSize(self.size()) # ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: if __name__ == '__main__': # pragma: no cover import sys f = 'C:/Users/jnsebgosselin/Desktop/Project4Testing/Project4Testing.what' app = QApplication(sys.argv) ft = app.font() ft.setFamily('Segoe UI') ft.setPointSize(11) app.setFont(ft) pm = ProjetManager(projet=None) pm.show() dm = DataManager(pm=pm) dm.show() app.exec_()
else: cp = QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) self.setFixedSize(self.size()) # ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: if __name__ == '__main__': # pragma: no cover import sys f = 'C:/Users/jnsebgosselin/Desktop/Project4Testing/Project4Testing.what' app = QApplication(sys.argv) ft = app.font() ft.setFamily('Segoe UI') ft.setPointSize(11) app.setFont(ft) pm = ProjetManager(projet=None) pm.show() dm = DataManager(pm=pm) dm.show() app.exec_()
class MainWindow(QMainWindow): def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.setWindowTitle(__namever__) self.setWindowIcon(icons.get_icon('master')) if platform.system() == 'Windows': import ctypes myappid = 'gwhat_application' # arbitrary string ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID( myappid) # Setup preferences : self.whatPref = WHATPref(self) self.projectfile = self.whatPref.projectfile self.projectdir = osp.dirname(self.projectfile) # Setup the project and data managers. splash.showMessage("Initializing project and data managers...") self.pmanager = ProjetManager(self) self.pmanager.currentProjetChanged.connect(self.new_project_loaded) self.dmanager = DataManager(parent=self, pm=self.pmanager) self.dmanager.setMaximumWidth(250) self.dmanager.sig_new_console_msg.connect(self.write2console) # Generate the GUI. self.__initUI__() splash.finish(self) self.showMaximized() # Load the last opened project : result = self.pmanager.load_project(self.projectfile) if result is False: self.tab_dwnld_data.setEnabled(False) self.tab_fill_weather_data.setEnabled(False) self.tab_hydrograph.setEnabled(False) self.tab_hydrocalc.setEnabled(False) def __initUI__(self): # ---- TAB WIDGET # download weather data : splash.showMessage("Initializing download weather data...") self.tab_dwnld_data = DwnldWeatherWidget(self) self.tab_dwnld_data.set_workdir(self.projectdir) # gapfill weather data : splash.showMessage("Initializing gapfill weather data...") self.tab_fill_weather_data = GapFillWeatherGUI(self) self.tab_fill_weather_data.set_workdir(self.projectdir) # hydrograph : splash.showMessage("Initializing plot hydrograph...") self.tab_hydrograph = HydroPrint.HydroprintGUI(self.dmanager) splash.showMessage("Initializing analyse hydrograph...") self.tab_hydrocalc = HydroCalc.WLCalc(self.dmanager) self.tab_hydrocalc.sig_new_mrc.connect( self.tab_hydrograph.mrc_wl_changed) self.tab_hydrocalc.rechg_eval_widget.sig_new_gluedf.connect( self.tab_hydrograph.glue_wl_changed) # ---- TABS ASSEMBLY self.tab_widget = TabWidget() self.tab_widget.addTab(self.tab_dwnld_data, 'Download Weather') self.tab_widget.addTab(self.tab_fill_weather_data, 'Gapfill Weather') self.tab_widget.addTab(self.tab_hydrograph, 'Plot Hydrograph') self.tab_widget.addTab(self.tab_hydrocalc, 'Analyze Hydrograph') self.tab_widget.setCornerWidget(self.pmanager) self.tab_widget.currentChanged.connect(self.sync_datamanagers) # ---- Main Console splash.showMessage("Initializing main window...") self.main_console = QTextEdit() self.main_console.setReadOnly(True) self.main_console.setLineWrapMode(QTextEdit.NoWrap) style = 'Regular' family = StyleDB().fontfamily size = self.whatPref.fontsize_console fontSS = ('font-style: %s;' 'font-size: %s;' 'font-family: %s;' ) % (style, size, family) self.main_console.setStyleSheet("QWidget{%s}" % fontSS) msg = '<font color=black>Thanks for using %s.</font>' % __appname__ self.write2console(msg) self.write2console('<font color=black>' 'Please report any bug or wishful feature at' ' [email protected].' '</font>') # ---- Signal Piping issuer = self.tab_dwnld_data issuer.ConsoleSignal.connect(self.write2console) issuer = self.tab_fill_weather_data issuer.ConsoleSignal.connect(self.write2console) issuer = self.tab_hydrograph issuer.ConsoleSignal.connect(self.write2console) # ---- Splitter Widget splitter = QSplitter(self) splitter.setOrientation(Qt.Vertical) splitter.addWidget(self.tab_widget) splitter.addWidget(self.main_console) splitter.setCollapsible(0, True) splitter.setStretchFactor(0, 100) # Forces initially the main_console to its minimal height: splitter.setSizes([100, 1]) # ---- Main Grid main_widget = QWidget() self.setCentralWidget(main_widget) mainGrid = QGridLayout(main_widget) mainGrid.addWidget(splitter, 0, 0) mainGrid.addWidget(self.tab_fill_weather_data.pbar, 1, 0) mainGrid.addWidget(self.tab_dwnld_data.pbar, 2, 0) mainGrid.addWidget( self.tab_hydrocalc.rechg_eval_widget.progressbar, 3, 0) def write2console(self, text): """ This function is the bottle neck through which all messages writen in the console must go through. """ textime = '<font color=black>[%s] </font>' % ctime()[4:-8] self.main_console.append(textime + text) def sync_datamanagers(self): """ Move the data manager from tab _Plot Hydrograph_ to tab _Analyze Hydrograph_ and vice-versa. """ current = self.tab_widget.tabBar().currentIndex() if current == 3: self.tab_hydrocalc.right_panel.addWidget(self.dmanager, 0, 0) elif current == 2: self.tab_hydrograph.right_panel.addWidget(self.dmanager, 0, 0) def new_project_loaded(self): """Handles when a new project is loaded in the project manager.""" filename = self.pmanager.projet.filename dirname = os.path.dirname(filename) # Update WHAT.pref file : self.whatPref.projectfile = filename self.whatPref.save_pref_file() # Update UI : self.tab_dwnld_data.setEnabled(True) self.tab_fill_weather_data.setEnabled(True) self.tab_hydrograph.setEnabled(True) self.tab_hydrocalc.setEnabled(True) # Update the child widgets : # dwnld_weather_data lat = self.pmanager.projet.lat lon = self.pmanager.projet.lon self.tab_dwnld_data.set_workdir(dirname) self.tab_dwnld_data.set_station_browser_latlon((lat, lon)) # fill_weather_data self.tab_fill_weather_data.set_workdir(dirname) self.tab_fill_weather_data.load_data_dir_content() def show(self): """Qt method override to center the app on the screen.""" super(MainWindow, self).show() qr = self.frameGeometry() cp = QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) def closeEvent(self, event): """Qt method override to close the project before close the app.""" print('Closing projet') self.pmanager.close_projet() print('Closing GWHAT') event.accept()
class MainWindow(QMainWindow): def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.setWindowTitle(__namever__) self.setWindowIcon(icons.get_icon('master')) if platform.system() == 'Windows': import ctypes myappid = 'gwhat_application' # arbitrary string ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID( myappid) # Setup the project manager. and data managers. splash.showMessage("Initializing project and data managers...") self.pmanager = ProjetManager(self) self.pmanager.currentProjetChanged.connect(self.new_project_loaded) # Setup the data manager. self.dmanager = DataManager(parent=self, pm=self.pmanager) self.dmanager.setMaximumWidth(250) self.dmanager.sig_new_console_msg.connect(self.write2console) # Generate the GUI. self.__initUI__() splash.finish(self) self.showMaximized() # Load the last opened project. projectfile = get_path_from_configs('main', 'last_project_filepath') result = self.pmanager.load_project(projectfile) if result is False: self.tab_hydrograph.setEnabled(False) self.tab_hydrocalc.setEnabled(False) def __initUI__(self): """ Setup the GUI of the main window. """ # Setup the main console. splash.showMessage("Initializing main window...") self.main_console = QTextBrowser() self.main_console.setReadOnly(True) self.main_console.setLineWrapMode(QTextEdit.NoWrap) self.main_console.setOpenExternalLinks(True) style = 'Regular' family = StyleDB().fontfamily size = CONF.get('main', 'fontsize_console') fontSS = ('font-style: %s;' 'font-size: %s;' 'font-family: %s;') % (style, size, family) self.main_console.setStyleSheet("QWidget{%s}" % fontSS) msg = '<font color=black>Thanks for using %s.</font>' % __appname__ self.write2console(msg) msg = ('Please help GWHAT by reporting bugs on our ' '<a href="https://github.com/jnsebgosselin/gwhat/issues">' 'Issues Tracker</a>.') self.write2console('<font color=black>%s</font>' % msg) # Setup the tab plot hydrograph. splash.showMessage("Initializing plot hydrograph...") self.tab_hydrograph = HydroPrint.HydroprintGUI(self.dmanager) self.tab_hydrograph.ConsoleSignal.connect(self.write2console) # Setup the tab analyse hydrograph. splash.showMessage("Initializing analyse hydrograph...") self.tab_hydrocalc = HydroCalc.WLCalc(self.dmanager) self.tab_hydrocalc.sig_new_mrc.connect( self.tab_hydrograph.mrc_wl_changed) self.tab_hydrocalc.rechg_eval_widget.sig_new_gluedf.connect( self.tab_hydrograph.glue_wl_changed) # Add each tab to the tab widget. self.tab_widget = TabWidget() self.tab_widget.addTab(self.tab_hydrograph, 'Plot Hydrograph') self.tab_widget.addTab(self.tab_hydrocalc, 'Analyze Hydrograph') self.tab_widget.setCornerWidget(self.pmanager) self.tab_widget.currentChanged.connect(self.sync_datamanagers) self.sync_datamanagers() # Setup the splitter widget. splitter = QSplitter(Qt.Vertical, parent=self) splitter.addWidget(self.tab_widget) splitter.addWidget(self.main_console) splitter.setCollapsible(0, True) splitter.setStretchFactor(0, 100) # Forces initially the main_console to its minimal height: splitter.setSizes([100, 1]) # Setup the layout of the main widget. main_widget = QWidget() self.setCentralWidget(main_widget) mainGrid = QGridLayout(main_widget) mainGrid.addWidget(splitter, 0, 0) mainGrid.addWidget(self.tab_hydrocalc.rechg_eval_widget.progressbar, 3, 0) def write2console(self, text): """ This function is the bottle neck through which all messages writen in the console must go through. """ textime = '<font color=black>[%s] </font>' % ctime()[4:-8] self.main_console.append(textime + text) def sync_datamanagers(self): """ Move the data manager from tab _Plot Hydrograph_ to tab _Analyze Hydrograph_ and vice-versa. """ current = self.tab_widget.tabBar().currentIndex() if current == 0: self.tab_hydrograph.right_panel.addWidget(self.dmanager, 0, 0) elif current == 1: self.tab_hydrocalc.right_panel.addWidget(self.dmanager, 0, 0) def new_project_loaded(self): """Handles when a new project is loaded in the project manager.""" # Save the project file path in the configs. save_path_to_configs('main', 'last_project_filepath', self.pmanager.projet.filename) # Update the GUI. self.tab_hydrograph.setEnabled(True) self.tab_hydrocalc.setEnabled(True) def closeEvent(self, event): """Qt method override to close the project before close the app.""" print('Closing projet') self.pmanager.close_projet() print('Closing GWHAT') event.accept()