def __init__(self, parent=None): super(TabWidget, self).__init__(parent=None) self._pytesting = False self.about_win = None self.about_btn = QToolButtonBase(icons.get_icon('info')) self.about_btn.setIconSize(icons.get_iconsize('small')) self.about_btn.setFixedSize(32, 32) self.about_btn.setToolTip('About GWHAT...') self.about_btn.clicked.connect(self._about_btn_isclicked) self.bug_btn = QToolButtonBase(icons.get_icon('report_bug')) self.bug_btn.setIconSize(icons.get_iconsize('small')) self.bug_btn.setFixedSize(32, 32) self.bug_btn.setToolTip('Report issue...') self.bug_btn.clicked.connect( lambda: QDesktopServices.openUrl(QUrl(GITHUB_ISSUES_URL))) self._button_box = QWidget(self) layout = QHBoxLayout(self._button_box) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(1) layout.addWidget(self.about_btn) layout.addWidget(self.bug_btn) tab_bar = TabBar(self, parent) self.setTabBar(tab_bar) tab_bar.sig_resized.connect(self._move_about_btn) tab_bar.sig_tab_layout_changed.connect(self._move_about_btn) self.about_btn.raise_()
def __init__(self, icon, icon_raised=None, size=None, parent=None): self._icon = icons.get_icon(icon) if isinstance(icon, str) else icon self._icon_raised = (icons.get_icon(icon_raised) if isinstance( icon_raised, str) else icon_raised) super(OnOffToolButton, self).__init__(self._icon, parent) self.installEventFilter(self) if size is not None: self.setIconSize(icons.get_iconsize(size))
def __init__(self, icon, icon_raised=None, size=None, parent=None): self._icon = icons.get_icon(icon) if isinstance(icon, str) else icon self._icon_raised = (icons.get_icon(icon_raised) if isinstance(icon_raised, str) else icon_raised) super(OnOffToolButton, self).__init__(self._icon, parent) self.installEventFilter(self) if size is not None: self.setIconSize(icons.get_iconsize(size))
def setup_wxdset_mngr(self): """Setup the manager for the weather datasets.""" # ---- Toolbar self.wxdsets_cbox = QComboBox() self.wxdsets_cbox.currentIndexChanged.connect(self.wxdset_changed) self.btn_load_meteo = QToolButtonSmall(icons.get_icon('importFile')) self.btn_load_meteo.setToolTip('Import a new weather dataset...') self.btn_load_meteo.clicked.connect(self.import_wxdataset) self.btn_del_wxdset = QToolButtonSmall('delete_data') self.btn_del_wxdset.setToolTip('Delete current dataset.') self.btn_del_wxdset.clicked.connect(self.del_current_wxdset) btn_closest_meteo = QToolButtonSmall(icons.get_icon('closest_meteo')) btn_closest_meteo.setToolTip('<p>Select the weather station closest' ' from the observation well.</p>') btn_closest_meteo.clicked.connect(self.set_closest_wxdset) btn_weather_normals = QToolButtonSmall(icons.get_icon('meteo')) btn_weather_normals.setToolTip( "Show the normals for the current weather dataset.") btn_weather_normals.clicked.connect(self.show_weather_normals) self.btn_export_weather = ExportWeatherButton(workdir=self.workdir) self.btn_export_weather.setIconSize(icons.get_iconsize('small')) wx_toolbar = ToolBarWidget() for widg in [ self.btn_load_meteo, self.btn_del_wxdset, btn_closest_meteo, btn_weather_normals, self.btn_export_weather ]: wx_toolbar.addWidget(widg) # ---- Info Box self.meteo_info_widget = StrSpinBox() # ---- Main Layout grpbox = QGroupBox('Weather Dataset : ') layout = QGridLayout(grpbox) layout.setSpacing(5) layout.addWidget(self.wxdsets_cbox, 1, 0) layout.addWidget(self.meteo_info_widget, 2, 0) layout.addWidget(wx_toolbar, 3, 0) return grpbox
def __initUI__(self): # ---- Toolbar self.btn_save = btn_save = QToolButtonNormal(icons.get_icon('save')) btn_save.setToolTip('Save the well hydrograph') # btn_draw is usefull for debugging purposes btn_draw = QToolButtonNormal(icons.get_icon('refresh')) btn_draw.setToolTip('Force a refresh of the well hydrograph') btn_draw.hide() self.btn_load_layout = QToolButtonNormal( icons.get_icon('load_graph_config')) self.btn_load_layout.setToolTip( "<p>Load graph layout for the current water level " " datafile if it exists</p>") self.btn_load_layout.clicked.connect(self.load_layout_isClicked) self.btn_save_layout = QToolButtonNormal( icons.get_icon('save_graph_config')) self.btn_save_layout.setToolTip('Save current graph layout') self.btn_save_layout.clicked.connect(self.save_layout_isClicked) btn_bestfit_waterlvl = QToolButtonNormal(icons.get_icon('fit_y')) btn_bestfit_waterlvl.setToolTip('Best fit the water level scale') btn_bestfit_time = QToolButtonNormal(icons.get_icon('fit_x')) btn_bestfit_time.setToolTip('Best fit the time scale') self.btn_page_setup = QToolButtonNormal(icons.get_icon('page_setup')) self.btn_page_setup.setToolTip('Show the page setup window') self.btn_page_setup.clicked.connect(self.page_setup_win.show) btn_color_pick = QToolButtonNormal(icons.get_icon('color_picker')) btn_color_pick.setToolTip('<p>Show a window to setup the color palette' ' used to draw the hydrograph</p.') btn_color_pick.clicked.connect(self.color_palette_win.show) self.btn_language = LangToolButton() self.btn_language.setToolTip( "Set the language of the text shown in the graph.") self.btn_language.sig_lang_changed.connect(self.layout_changed) self.btn_language.setIconSize(icons.get_iconsize('normal')) # ---- Zoom Panel btn_zoom_out = QToolButtonSmall(icons.get_icon('zoom_out')) btn_zoom_out.setToolTip('Zoom out (ctrl + mouse-wheel-down)') btn_zoom_out.clicked.connect(self.zoom_out) btn_zoom_in = QToolButtonSmall(icons.get_icon('zoom_in')) btn_zoom_in.setToolTip('Zoom in (ctrl + mouse-wheel-up)') btn_zoom_in.clicked.connect(self.zoom_in) self.zoom_disp = QSpinBox() self.zoom_disp.setAlignment(Qt.AlignCenter) self.zoom_disp.setButtonSymbols(QAbstractSpinBox.NoButtons) self.zoom_disp.setReadOnly(True) self.zoom_disp.setSuffix(' %') self.zoom_disp.setRange(0, 9999) self.zoom_disp.setValue(100) zoom_pan = myqt.QFrameLayout() zoom_pan.setSpacing(3) zoom_pan.addWidget(btn_zoom_out, 0, 0) zoom_pan.addWidget(btn_zoom_in, 0, 1) zoom_pan.addWidget(self.zoom_disp, 0, 2) # LAYOUT : btn_list = [btn_save, btn_draw, self.btn_load_layout, self.btn_save_layout, VSep(), btn_bestfit_waterlvl, btn_bestfit_time, VSep(), self.btn_page_setup, btn_color_pick, self.btn_language, VSep(), zoom_pan] subgrid_toolbar = QGridLayout() toolbar_widget = QWidget() row = 0 for col, btn in enumerate(btn_list): subgrid_toolbar.addWidget(btn, row, col) subgrid_toolbar.setSpacing(5) subgrid_toolbar.setContentsMargins(0, 0, 0, 0) subgrid_toolbar.setColumnStretch(col + 1, 100) toolbar_widget.setLayout(subgrid_toolbar) # ---- LEFT PANEL # SubGrid Hydrograph Frame : self.hydrograph = hydrograph.Hydrograph() self.hydrograph_scrollarea = mplFigViewer.ImageViewer() self.hydrograph_scrollarea.zoomChanged.connect(self.zoom_disp.setValue) grid_hydrograph = QGridLayout() grid_hydrograph.addWidget(self.hydrograph_scrollarea, 0, 0) grid_hydrograph.setRowStretch(0, 500) grid_hydrograph.setColumnStretch(0, 500) grid_hydrograph.setContentsMargins(0, 0, 0, 0) # (L, T, R, B) # ASSEMBLING SubGrids : grid_layout = QGridLayout() self.grid_layout_widget = QFrame() row = 0 grid_layout.addWidget(toolbar_widget, row, 0) row += 1 grid_layout.addLayout(grid_hydrograph, row, 0) grid_layout.setContentsMargins(0, 0, 0, 0) # (L, T, R, B) grid_layout.setSpacing(5) grid_layout.setColumnStretch(0, 500) grid_layout.setRowStretch(1, 500) self.grid_layout_widget.setLayout(grid_layout) # ---- Right Panel self.tabscales = self.__init_scalesTabWidget__() self.right_panel = myqt.QFrameLayout() self.right_panel.addWidget(self.dmngr, 0, 0) self.right_panel.addWidget(self.tabscales, 1, 0) self.right_panel.setRowStretch(2, 100) self.right_panel.setSpacing(15) # ---- MAIN GRID mainGrid = QGridLayout() mainGrid.addWidget(self.grid_layout_widget, 0, 0) mainGrid.addWidget(VSep(), 0, 1) mainGrid.addWidget(self.right_panel, 0, 2) mainGrid.setContentsMargins(10, 10, 10, 10) # (L, T, R, B) mainGrid.setSpacing(15) mainGrid.setColumnStretch(0, 500) mainGrid.setColumnMinimumWidth(2, 250) self.setLayout(mainGrid) # ---- EVENTS # Toolbox Layout : btn_bestfit_waterlvl.clicked.connect(self.best_fit_waterlvl) btn_bestfit_time.clicked.connect(self.best_fit_time) btn_draw.clicked.connect(self.draw_hydrograph) btn_save.clicked.connect(self.select_save_path) # Hydrograph Layout : self.Ptot_scale.valueChanged.connect(self.layout_changed) self.qweather_bin.currentIndexChanged.connect(self.layout_changed) # ---- Init Image self.hydrograph_scrollarea.load_mpl_figure(self.hydrograph)
def _setup_icon(self): """Setup the icon of the button according to its auto raise state.""" if self._icon_raised is None: return icon = self._icon_raised if self.value() else self._icon self.setIcon(icon) # %% if __name__ == '__main__' if __name__ == '__main__': app = QApplication(sys.argv) drop_button = DropDownButton(icon=icons.get_icon('todate')) drop_button.addItems([str(i) for i in range(2017, 1899, -1)]) onoff_button = OnOffToolButton('play', 'stop') onoff_button.setIconSize(icons.get_iconsize('normal')) lang_button = LangToolButton() lang_button.setIconSize(icons.get_iconsize('normal')) toolbar = ToolBarWidget() toolbar.addWidget(onoff_button) toolbar.addWidget(drop_button) toolbar.addWidget(lang_button) toolbar.show() sys.exit(app.exec_())
def __initUI__(self): self.setWindowTitle('Weather Averages') self.setWindowIcon(icons.get_icon('master')) # ---- Toolbar # Initialize the widgets : menu_save = QMenu() menu_save.addAction('Save normals graph as...', self.save_graph) menu_save.addAction('Save normals table as...', self.save_normals) btn_save = QToolButtonNormal(icons.get_icon('save')) btn_save.setToolTip('Save normals') btn_save.setMenu(menu_save) btn_save.setPopupMode(QToolButton.InstantPopup) btn_save.setStyleSheet("QToolButton::menu-indicator {image: none;}") self.btn_export = ExportWeatherButton() self.btn_export.setIconSize(icons.get_iconsize('normal')) btn_showStats = QToolButtonNormal(icons.get_icon('showGrid')) btn_showStats.setToolTip( "Show the monthly weather normals data table.") btn_showStats.clicked.connect(self.show_monthly_grid) btn_language = LangToolButton() btn_language.setToolTip( "Set the language of the text shown in the graph.") btn_language.sig_lang_changed.connect(self.set_lang) btn_language.setIconSize(icons.get_iconsize('normal')) # Instantiate and define a layout for the year range widget : self.year_rng = RangeSpinBoxes(1000, 9999) self.year_rng.setRange(1800, datetime.now().year) self.year_rng.sig_range_changed.connect(self.update_normals) btn_expand = QToolButtonVRectSmall(icons.get_icon('expand_range_vert')) btn_expand.clicked.connect(self.expands_year_range) btn_expand.setToolTip("Set the maximal possible year range.") lay_expand = QGridLayout() lay_expand.addWidget(self.year_rng.spb_upper, 0, 0) lay_expand.addWidget(btn_expand, 0, 1) lay_expand.setContentsMargins(0, 0, 0, 0) lay_expand.setSpacing(1) qgrid = QHBoxLayout(self.year_rng) qgrid.setContentsMargins(0, 0, 0, 0) qgrid.addWidget(QLabel('Year Range :')) qgrid.addWidget(self.year_rng.spb_lower) qgrid.addWidget(QLabel('to')) qgrid.addLayout(lay_expand) # Generate the layout of the toolbar : toolbar_widget = ToolBarWidget() for btn in [ btn_save, self.btn_export, btn_showStats, btn_language, None, self.year_rng ]: toolbar_widget.addWidget(btn) # ---- Main Layout # Initialize the widgets : self.fig_weather_normals = FigWeatherNormals() self.grid_weather_normals = GridWeatherNormals() self.grid_weather_normals.hide() # Generate the layout : mainGrid = QGridLayout() row = 0 mainGrid.addWidget(toolbar_widget, row, 0) row += 1 mainGrid.addWidget(self.fig_weather_normals, row, 0) row += 1 mainGrid.addWidget(self.grid_weather_normals, row, 0) mainGrid.setContentsMargins(10, 10, 10, 10) # (L, T, R, B) mainGrid.setSpacing(10) mainGrid.setRowStretch(row, 500) mainGrid.setColumnStretch(0, 500) self.setLayout(mainGrid)
def __initGUI__(self): # ---- Navigator self.btn_prev = QToolButtonNormal(icons.get_icon('go_previous')) self.btn_prev.clicked.connect(self.navigate_brf) self.btn_next = QToolButtonNormal(icons.get_icon('go_next')) self.btn_next.clicked.connect(self.navigate_brf) self.current_brf = QSpinBox() self.current_brf.setRange(0, 99) self.current_brf.setAlignment(Qt.AlignCenter) self.current_brf.setButtonSymbols(QAbstractSpinBox.NoButtons) self.current_brf.setCorrectionMode( QAbstractSpinBox.CorrectToNearestValue) self.current_brf.valueChanged.connect(self.navigate_brf) self.current_brf.setValue(0) self.total_brf = QLabel('/ 0') # ---- Language button self.btn_language = LangToolButton() self.btn_language.setToolTip( "Set the language of the text shown in the graph.") self.btn_language.sig_lang_changed.connect(self.plot_brf) self.btn_language.setIconSize(icons.get_iconsize('normal')) # ---- Toolbar # Generate the buttons : self.btn_del = QToolButtonNormal(icons.get_icon('delete_data')) self.btn_del.setToolTip('Delete current BRF results') self.btn_del.clicked.connect(self.del_brf) self.btn_del_all = QToolButtonNormal(icons.get_icon('close_all')) self.btn_del_all.setToolTip( 'Delete all BRF results for the current water level dataset.') self.btn_del_all.clicked.connect(self.del_all_brf) self.btn_save = btn_save = QToolButtonNormal(icons.get_icon('save')) btn_save.setToolTip('Save current BRF graph as...') btn_save.clicked.connect(self.select_savefig_path) self.btn_export = QToolButtonNormal(icons.get_icon('export_data')) self.btn_export.setToolTip('Export data to file.') self.btn_export.clicked.connect(self.select_export_brfdata_filepath) self.btn_copy = QToolButtonNormal('copy_clipboard') self.btn_copy.setToolTip('Copy figure to clipboard as image.') self.btn_copy.clicked.connect(self.copyfig_to_clipboard) self.btn_setp = QToolButtonNormal(icons.get_icon('page_setup')) self.btn_setp.setToolTip('Show graph layout parameters...') self.btn_setp.clicked.connect(self.toggle_graphpannel) # Generate the layout : self.tbar = myqt.QFrameLayout() buttons = [ btn_save, self.btn_copy, self.btn_export, self.btn_del, self.btn_del_all, VSep(), self.btn_prev, self.current_brf, self.total_brf, self.btn_next, VSep(), self.btn_setp, self.btn_language ] for btn in buttons: if isinstance(btn, QLayout): self.tbar.addLayout(btn, 1, self.tbar.columnCount()) else: self.tbar.addWidget(btn, 1, self.tbar.columnCount()) row = self.tbar.columnCount() self.tbar.addWidget(HSep(), 0, 0, 1, row + 1) self.tbar.setColumnStretch(row, 100) self.tbar.setContentsMargins(10, 0, 10, 10) # (l, t, r, b) # ---- Graph Canvas self.fig_frame = QFrame() self.fig_frame.setFrameStyle(StyleDB().frame) self.fig_frame.setObjectName("figframe") self.fig_frame.setStyleSheet("#figframe {background-color:white;}") self.brf_canvas = FigureCanvasQTAgg(BRFFigure()) fflay = QGridLayout(self.fig_frame) fflay.setContentsMargins(0, 0, 0, 0) # (left, top, right, bottom) fflay.addWidget(self.tbar, 1, 0) fflay.addWidget(self.brf_canvas, 0, 0) # ---- Graph Options Panel self.graph_opt_panel = BRFOptionsPanel() self.graph_opt_panel.sig_graphconf_changed.connect(self.plot_brf) # ---- Main Layout ml = QGridLayout(self) ml.addWidget(self.fig_frame, 0, 2) ml.addWidget(self.graph_opt_panel, 0, 3) ml.setColumnStretch(1, 100)
def __initUI__(self): # ---- Toolbar self.btn_save = btn_save = QToolButtonNormal(icons.get_icon('save')) btn_save.setToolTip('Save the well hydrograph') # btn_draw is usefull for debugging purposes btn_draw = QToolButtonNormal(icons.get_icon('refresh')) btn_draw.setToolTip('Force a refresh of the well hydrograph') btn_draw.hide() self.btn_load_layout = QToolButtonNormal( icons.get_icon('load_graph_config')) self.btn_load_layout.setToolTip( "<p>Load graph layout for the current water level " " datafile if it exists</p>") self.btn_load_layout.clicked.connect(self.load_layout_isClicked) self.btn_save_layout = QToolButtonNormal( icons.get_icon('save_graph_config')) self.btn_save_layout.setToolTip('Save current graph layout') self.btn_save_layout.clicked.connect(self.save_layout_isClicked) btn_bestfit_waterlvl = QToolButtonNormal(icons.get_icon('fit_y')) btn_bestfit_waterlvl.setToolTip('Best fit the water level scale') btn_bestfit_time = QToolButtonNormal(icons.get_icon('fit_x')) btn_bestfit_time.setToolTip('Best fit the time scale') self.btn_page_setup = QToolButtonNormal(icons.get_icon('page_setup')) self.btn_page_setup.setToolTip('Show the page setup window') self.btn_page_setup.clicked.connect(self.page_setup_win.show) btn_color_pick = QToolButtonNormal(icons.get_icon('color_picker')) btn_color_pick.setToolTip('<p>Show a window to setup the color palette' ' used to draw the hydrograph</p.') btn_color_pick.clicked.connect(self.color_palette_win.show) self.btn_language = LangToolButton() self.btn_language.setToolTip( "Set the language of the text shown in the graph.") self.btn_language.sig_lang_changed.connect(self.layout_changed) self.btn_language.setIconSize(icons.get_iconsize('normal')) # ---- Zoom Panel btn_zoom_out = QToolButtonSmall(icons.get_icon('zoom_out')) btn_zoom_out.setToolTip('Zoom out (ctrl + mouse-wheel-down)') btn_zoom_out.clicked.connect(self.zoom_out) btn_zoom_in = QToolButtonSmall(icons.get_icon('zoom_in')) btn_zoom_in.setToolTip('Zoom in (ctrl + mouse-wheel-up)') btn_zoom_in.clicked.connect(self.zoom_in) self.zoom_disp = QSpinBox() self.zoom_disp.setAlignment(Qt.AlignCenter) self.zoom_disp.setButtonSymbols(QAbstractSpinBox.NoButtons) self.zoom_disp.setReadOnly(True) self.zoom_disp.setSuffix(' %') self.zoom_disp.setRange(0, 9999) self.zoom_disp.setValue(100) zoom_pan = myqt.QFrameLayout() zoom_pan.setSpacing(3) zoom_pan.addWidget(btn_zoom_out, 0, 0) zoom_pan.addWidget(btn_zoom_in, 0, 1) zoom_pan.addWidget(self.zoom_disp, 0, 2) # LAYOUT : btn_list = [ btn_save, btn_draw, self.btn_load_layout, self.btn_save_layout, VSep(), btn_bestfit_waterlvl, btn_bestfit_time, VSep(), self.btn_page_setup, btn_color_pick, self.btn_language, VSep(), zoom_pan ] subgrid_toolbar = QGridLayout() toolbar_widget = QWidget() row = 0 for col, btn in enumerate(btn_list): subgrid_toolbar.addWidget(btn, row, col) subgrid_toolbar.setSpacing(5) subgrid_toolbar.setContentsMargins(0, 0, 0, 0) subgrid_toolbar.setColumnStretch(col + 1, 100) toolbar_widget.setLayout(subgrid_toolbar) # ---- LEFT PANEL # SubGrid Hydrograph Frame : self.hydrograph = hydrograph.Hydrograph() self.hydrograph_scrollarea = mplFigViewer.ImageViewer() self.hydrograph_scrollarea.zoomChanged.connect(self.zoom_disp.setValue) grid_hydrograph = QGridLayout() grid_hydrograph.addWidget(self.hydrograph_scrollarea, 0, 0) grid_hydrograph.setRowStretch(0, 500) grid_hydrograph.setColumnStretch(0, 500) grid_hydrograph.setContentsMargins(0, 0, 0, 0) # (L, T, R, B) # ASSEMBLING SubGrids : grid_layout = QGridLayout() self.grid_layout_widget = QFrame() row = 0 grid_layout.addWidget(toolbar_widget, row, 0) row += 1 grid_layout.addLayout(grid_hydrograph, row, 0) grid_layout.setContentsMargins(0, 0, 0, 0) # (L, T, R, B) grid_layout.setSpacing(5) grid_layout.setColumnStretch(0, 500) grid_layout.setRowStretch(1, 500) self.grid_layout_widget.setLayout(grid_layout) # ---- Right Panel self.tabscales = self.__init_scalesTabWidget__() self.right_panel = myqt.QFrameLayout() self.right_panel.addWidget(self.dmngr, 0, 0) self.right_panel.addWidget(self.tabscales, 1, 0) self.right_panel.setRowStretch(2, 100) self.right_panel.setSpacing(15) # ---- MAIN GRID mainGrid = QGridLayout() mainGrid.addWidget(self.grid_layout_widget, 0, 0) mainGrid.addWidget(VSep(), 0, 1) mainGrid.addWidget(self.right_panel, 0, 2) mainGrid.setContentsMargins(10, 10, 10, 10) # (L, T, R, B) mainGrid.setSpacing(15) mainGrid.setColumnStretch(0, 500) mainGrid.setColumnMinimumWidth(2, 250) self.setLayout(mainGrid) # ---- EVENTS # Toolbox Layout : btn_bestfit_waterlvl.clicked.connect(self.best_fit_waterlvl) btn_bestfit_time.clicked.connect(self.best_fit_time) btn_draw.clicked.connect(self.draw_hydrograph) btn_save.clicked.connect(self.select_save_path) # Hydrograph Layout : self.Ptot_scale.valueChanged.connect(self.layout_changed) self.qweather_bin.currentIndexChanged.connect(self.layout_changed) # ---- Init Image self.hydrograph_scrollarea.load_mpl_figure(self.hydrograph)
def __initUI__(self): self.setWindowTitle('Weather Stations Browser') self.setWindowIcon(icons.get_icon('master')) self.setWindowFlags(Qt.Window) now = datetime.now() # ---- Tab Widget Search # ---- Proximity filter groupbox label_Lat = QLabel('Latitude :') label_Lat2 = QLabel('North') self.lat_spinBox = QDoubleSpinBox() self.lat_spinBox.setAlignment(Qt.AlignCenter) self.lat_spinBox.setSingleStep(0.1) self.lat_spinBox.setValue(0) self.lat_spinBox.setMinimum(0) self.lat_spinBox.setMaximum(180) self.lat_spinBox.setSuffix(u' °') self.lat_spinBox.valueChanged.connect(self.proximity_grpbox_toggled) label_Lon = QLabel('Longitude :') label_Lon2 = QLabel('West') self.lon_spinBox = QDoubleSpinBox() self.lon_spinBox.setAlignment(Qt.AlignCenter) self.lon_spinBox.setSingleStep(0.1) self.lon_spinBox.setValue(0) self.lon_spinBox.setMinimum(0) self.lon_spinBox.setMaximum(180) self.lon_spinBox.setSuffix(u' °') self.lon_spinBox.valueChanged.connect(self.proximity_grpbox_toggled) self.radius_SpinBox = QComboBox() self.radius_SpinBox.addItems(['25 km', '50 km', '100 km', '200 km']) self.radius_SpinBox.currentIndexChanged.connect( self.search_filters_changed) prox_search_grid = QGridLayout() row = 0 prox_search_grid.addWidget(label_Lat, row, 1) prox_search_grid.addWidget(self.lat_spinBox, row, 2) prox_search_grid.addWidget(label_Lat2, row, 3) row += 1 prox_search_grid.addWidget(label_Lon, row, 1) prox_search_grid.addWidget(self.lon_spinBox, row, 2) prox_search_grid.addWidget(label_Lon2, row, 3) row += 1 prox_search_grid.addWidget(QLabel('Search Radius :'), row, 1) prox_search_grid.addWidget(self.radius_SpinBox, row, 2) prox_search_grid.setColumnStretch(0, 100) prox_search_grid.setColumnStretch(4, 100) prox_search_grid.setRowStretch(row+1, 100) prox_search_grid.setHorizontalSpacing(20) prox_search_grid.setContentsMargins(10, 10, 10, 10) # (L, T, R, B) self.prox_grpbox = QGroupBox("Proximity filter :") self.prox_grpbox.setCheckable(True) self.prox_grpbox.setChecked(False) self.prox_grpbox.toggled.connect(self.proximity_grpbox_toggled) self.prox_grpbox.setLayout(prox_search_grid) # ---- Province filter prov_names = ['All'] prov_names.extend(self.PROV_NAME) self.prov_widg = QComboBox() self.prov_widg.addItems(prov_names) self.prov_widg.setCurrentIndex(0) self.prov_widg.currentIndexChanged.connect(self.search_filters_changed) layout = QGridLayout() layout.addWidget(self.prov_widg, 2, 1) layout.setColumnStretch(2, 100) layout.setVerticalSpacing(10) prov_grpbox = QGroupBox("Province filter :") prov_grpbox.setLayout(layout) # ---- Data availability filter # Number of years with data self.nbrYear = QSpinBox() self.nbrYear.setAlignment(Qt.AlignCenter) self.nbrYear.setSingleStep(1) self.nbrYear.setMinimum(0) self.nbrYear.setValue(3) self.nbrYear.valueChanged.connect(self.search_filters_changed) subgrid1 = QGridLayout() subgrid1.addWidget(self.nbrYear, 0, 0) subgrid1.addWidget(QLabel('years of data between'), 0, 1) subgrid1.setHorizontalSpacing(10) subgrid1.setContentsMargins(0, 0, 0, 0) # (L, T, R, B) subgrid1.setColumnStretch(2, 100) # Year range self.minYear = QSpinBox() self.minYear.setAlignment(Qt.AlignCenter) self.minYear.setSingleStep(1) self.minYear.setMinimum(1840) self.minYear.setMaximum(now.year) self.minYear.setValue(1840) self.minYear.valueChanged.connect(self.minYear_changed) label_and = QLabel('and') label_and.setAlignment(Qt.AlignCenter) self.maxYear = QSpinBox() self.maxYear.setAlignment(Qt.AlignCenter) self.maxYear.setSingleStep(1) self.maxYear.setMinimum(1840) self.maxYear.setMaximum(now.year) self.maxYear.setValue(now.year) self.maxYear.valueChanged.connect(self.maxYear_changed) subgrid2 = QGridLayout() subgrid2.addWidget(self.minYear, 0, 0) subgrid2.addWidget(label_and, 0, 1) subgrid2.addWidget(self.maxYear, 0, 2) subgrid2.setHorizontalSpacing(10) subgrid2.setContentsMargins(0, 0, 0, 0) # (L, T, R, B) subgrid2.setColumnStretch(4, 100) # Subgridgrid assembly grid = QGridLayout() grid.addWidget(QLabel('Search for stations with at least'), 0, 0) grid.addLayout(subgrid1, 1, 0) grid.addLayout(subgrid2, 2, 0) grid.setVerticalSpacing(5) grid.setRowStretch(0, 100) # grid.setContentsMargins(0, 0, 0, 0) # (L, T, R, B) self.year_widg = QGroupBox("Data Availability filter :") self.year_widg.setLayout(grid) # ---- Toolbar self.btn_addSta = btn_addSta = QPushButton('Add') btn_addSta.setIcon(icons.get_icon('add2list')) btn_addSta.setIconSize(icons.get_iconsize('small')) btn_addSta.setToolTip('Add selected found weather stations to the ' 'current list of weather stations.') btn_addSta.clicked.connect(self.btn_addSta_isClicked) btn_save = QPushButton('Save') btn_save.setIcon(icons.get_icon('save')) btn_save.setIconSize(icons.get_iconsize('small')) btn_save.setToolTip('Save current found stations info in a csv file.') btn_save.clicked.connect(self.btn_save_isClicked) self.btn_fetch = btn_fetch = QPushButton('Fetch') btn_fetch.setIcon(icons.get_icon('refresh')) btn_fetch.setIconSize(icons.get_iconsize('small')) btn_fetch.setToolTip("Updates the climate station database by" " fetching it again from the ECCC ftp server.") btn_fetch.clicked.connect(self.btn_fetch_isClicked) toolbar_grid = QGridLayout() toolbar_widg = QWidget() for col, btn in enumerate([btn_addSta, btn_save, btn_fetch]): toolbar_grid.addWidget(btn, 0, col+1) toolbar_grid.setColumnStretch(toolbar_grid.columnCount(), 100) toolbar_grid.setSpacing(5) toolbar_grid.setContentsMargins(0, 30, 0, 0) # (L, T, R, B) toolbar_widg.setLayout(toolbar_grid) # ---- Left Panel panel_title = QLabel('<b>Weather Station Search Criteria :</b>') left_panel = QFrame() left_panel_grid = QGridLayout() left_panel_grid.addWidget(panel_title, 0, 0) left_panel_grid.addWidget(self.prox_grpbox, 1, 0) left_panel_grid.addWidget(prov_grpbox, 2, 0) left_panel_grid.addWidget(self.year_widg, 3, 0) left_panel_grid.setRowStretch(4, 100) left_panel_grid.addWidget(toolbar_widg, 5, 0) left_panel_grid.setVerticalSpacing(20) left_panel_grid.setContentsMargins(0, 0, 0, 0) # (L, T, R, B) left_panel.setLayout(left_panel_grid) # ----- Main grid # Widgets vLine1 = QFrame() vLine1.setFrameStyle(StyleDB().VLine) # Grid main_layout = QGridLayout(self) main_layout.addWidget(left_panel, 0, 0) main_layout.addWidget(vLine1, 0, 1) main_layout.addWidget(self.station_table, 0, 2) main_layout.addWidget(self.waitspinnerbar, 0, 2) main_layout.setContentsMargins(10, 10, 10, 10) # (L,T,R,B) main_layout.setRowStretch(0, 100) main_layout.setHorizontalSpacing(15) main_layout.setVerticalSpacing(5) main_layout.setColumnStretch(col, 100)
def __initUI__(self): # ---- Current Date ---- now = datetime.now() now = (now.day, now.month, now.year, now.hour, now.minute) # ----------------------------------------------------- PROJECT INFO -- # ---- Widgets ---- self.name = QLineEdit() self.author = QLineEdit() self.date = QLabel('%02d/%02d/%d %02d:%02d' % now) self.createdby = QLabel(__namever__) # ---- Layout ---- projet_info = QGridLayout() row = 0 projet_info.addWidget(QLabel('Project Title :'), row, 0) projet_info.addWidget(self.name, row, 1) row += 1 projet_info.addWidget(QLabel('Author :'), row, 0) projet_info.addWidget(self.author, row, 1) row += 1 projet_info.addWidget(QLabel('Created :'), row, 0) projet_info.addWidget(self.date, row, 1) row += 1 projet_info.addWidget(QLabel('Software :'), row, 0) projet_info.addWidget(self.createdby, row, 1) projet_info.setSpacing(10) projet_info.setColumnStretch(1, 100) projet_info.setColumnMinimumWidth(1, 250) projet_info.setContentsMargins(0, 0, 0, 0) # (L, T, R, B) # --------------------------------------------- LOCATION COORDINATES -- locaCoord_title = QLabel('<b>Project Location Coordinates:</b>') locaCoord_title.setAlignment(Qt.AlignLeft) self.lat_spinbox = myqt.QDoubleSpinBox(0, 3, 0.1, ' °') self.lat_spinbox.setRange(0, 180) self.lon_spinbox = myqt.QDoubleSpinBox(0, 3, 0.1, ' °') self.lon_spinbox.setRange(0, 180) # ----- layout ---- loc_coord = QGridLayout() row = 0 loc_coord.addWidget(locaCoord_title, row, 0, 1, 11) row += 1 loc_coord.setColumnStretch(0, 100) loc_coord.addWidget(QLabel('Latitude :'), row, 1) loc_coord.addWidget(self.lat_spinbox, row, 2) loc_coord.addWidget(QLabel('North'), row, 3) loc_coord.setColumnStretch(4, 100) loc_coord.addWidget(VSep(), row, 5) loc_coord.setColumnStretch(6, 100) loc_coord.addWidget(QLabel('Longitude :'), row, 7) loc_coord.addWidget(self.lon_spinbox, row, 8) loc_coord.addWidget(QLabel('West'), row, 9) loc_coord.setColumnStretch(10, 100) loc_coord.setSpacing(10) loc_coord.setContentsMargins(0, 0, 0, 0) # (L, T, R, B) # --------------------------------------------------------- Browse ---- # ---- widgets ---- save_in_folder = os.path.abspath(os.path.join('..', 'Projects')) directory_label = QLabel('Save in Folder:') self.directory = QLineEdit() self.directory.setReadOnly(True) self.directory.setText(save_in_folder) self.directory.setMinimumWidth(350) btn_browse = QToolButton() btn_browse.setAutoRaise(True) btn_browse.setIcon(icons.get_icon('openFolder')) btn_browse.setIconSize(icons.get_iconsize('small')) btn_browse.setToolTip('Browse...') btn_browse.setFocusPolicy(Qt.NoFocus) btn_browse.clicked.connect(self.browse_saveIn_folder) browse = QGridLayout() browse.addWidget(directory_label, 0, 0) browse.addWidget(self.directory, 0, 1) browse.addWidget(btn_browse, 0, 2) browse.setContentsMargins(0, 0, 0, 0) # (L, T, R, B) browse.setColumnStretch(1, 100) browse.setSpacing(10) # ---------------------------------------------------------- Toolbar -- # ---- widgets ---- btn_save = QPushButton(' Save') btn_save.setMinimumWidth(100) btn_save.clicked.connect(self.save_project) btn_cancel = QPushButton(' Cancel') btn_cancel.setMinimumWidth(100) btn_cancel.clicked.connect(self.close) # ---- layout ---- toolbar = QGridLayout() toolbar.addWidget(btn_save, 0, 1) toolbar.addWidget(btn_cancel, 0, 2) toolbar.setSpacing(10) toolbar.setColumnStretch(0, 100) toolbar.setContentsMargins(0, 0, 0, 0) # (L, T, R, B) # ------------------------------------------------------------- MAIN -- main_layout = QGridLayout(self) main_layout.addLayout(projet_info, 0, 0) main_layout.addWidget(HSep(), 1, 0) main_layout.addLayout(loc_coord, 2, 0) main_layout.addWidget(HSep(), 3, 0) main_layout.addLayout(browse, 4, 0) main_layout.addLayout(toolbar, 5, 0) main_layout.setVerticalSpacing(25) main_layout.setContentsMargins(15, 15, 15, 15) # (L, T, R, B)
def __initGUI__(self): # ---- Navigator self.btn_prev = QToolButtonNormal(icons.get_icon('go_previous')) self.btn_prev.clicked.connect(self.navigate_brf) self.btn_next = QToolButtonNormal(icons.get_icon('go_next')) self.btn_next.clicked.connect(self.navigate_brf) self.current_brf = QSpinBox() self.current_brf.setRange(0, 99) self.current_brf.setAlignment(Qt.AlignCenter) self.current_brf.setButtonSymbols(QAbstractSpinBox.NoButtons) self.current_brf.setCorrectionMode( QAbstractSpinBox.CorrectToNearestValue) self.current_brf.valueChanged.connect(self.navigate_brf) self.current_brf.setValue(0) self.total_brf = QLabel('/ 0') # ---- Language button self.btn_language = LangToolButton() self.btn_language.setToolTip( "Set the language of the text shown in the graph.") self.btn_language.sig_lang_changed.connect(self.plot_brf) self.btn_language.setIconSize(icons.get_iconsize('normal')) # ---- Toolbar # Generate the buttons : self.btn_del = QToolButtonNormal(icons.get_icon('delete_data')) self.btn_del.setToolTip('Delete current BRF results') self.btn_del.clicked.connect(self.del_brf) self.btn_del_all = QToolButtonNormal(icons.get_icon('close_all')) self.btn_del_all.setToolTip( 'Delete all BRF results for the current water level dataset.') self.btn_del_all.clicked.connect(self.del_all_brf) self.btn_save = btn_save = QToolButtonNormal(icons.get_icon('save')) btn_save.setToolTip('Save current BRF graph as...') btn_save.clicked.connect(self.select_savefig_path) self.btn_export = QToolButtonNormal(icons.get_icon('export_data')) self.btn_export.setToolTip('Export data to file.') self.btn_export.clicked.connect(self.select_export_brfdata_filepath) self.btn_copy = QToolButtonNormal('copy_clipboard') self.btn_copy.setToolTip('Copy figure to clipboard as image.') self.btn_copy.clicked.connect(self.copyfig_to_clipboard) self.btn_setp = QToolButtonNormal(icons.get_icon('page_setup')) self.btn_setp.setToolTip('Show graph layout parameters...') self.btn_setp.clicked.connect(self.toggle_graphpannel) # Generate the layout : self.tbar = myqt.QFrameLayout() buttons = [btn_save, self.btn_copy, self.btn_export, self.btn_del, self.btn_del_all, VSep(), self.btn_prev, self.current_brf, self.total_brf, self.btn_next, VSep(), self.btn_setp, self.btn_language] for btn in buttons: if isinstance(btn, QLayout): self.tbar.addLayout(btn, 1, self.tbar.columnCount()) else: self.tbar.addWidget(btn, 1, self.tbar.columnCount()) row = self.tbar.columnCount() self.tbar.addWidget(HSep(), 0, 0, 1, row+1) self.tbar.setColumnStretch(row, 100) self.tbar.setContentsMargins(10, 0, 10, 10) # (l, t, r, b) # ---- Graph Canvas self.fig_frame = QFrame() self.fig_frame.setFrameStyle(StyleDB().frame) self.fig_frame.setObjectName("figframe") self.fig_frame.setStyleSheet("#figframe {background-color:white;}") self.brf_canvas = FigureCanvasQTAgg(BRFFigure()) fflay = QGridLayout(self.fig_frame) fflay.setContentsMargins(0, 0, 0, 0) # (left, top, right, bottom) fflay.addWidget(self.tbar, 1, 0) fflay.addWidget(self.brf_canvas, 0, 0) # ---- Graph Options Panel self.graph_opt_panel = BRFOptionsPanel() self.graph_opt_panel.sig_graphconf_changed.connect(self.plot_brf) # ---- Main Layout ml = QGridLayout(self) ml.addWidget(self.fig_frame, 0, 2) ml.addWidget(self.graph_opt_panel, 0, 3) ml.setColumnStretch(1, 100)