def open_tool(self, item, _): if not item.data(0, Qt.UserRole): return group = item.data(0, Qt.UserRole + 1) tool = item.data(0, Qt.UserRole + 2) for sub_window in self.mdi_area.subWindowList(): if sub_window.windowTitle() == item.text(0): sub_window.setFocus() return if group == 0: if tool == 0: tool_widget = OriginalWidget(self.image) elif tool == 1: tool_widget = DigestWidget(self.filename, self.image) elif tool == 2: tool_widget = EditorWidget() elif tool == 3: tool_widget = ReverseWidget() else: return elif group == 1: if tool == 0: tool_widget = HeaderWidget(self.filename) elif tool == 1: tool_widget = ExifWidget(self.filename) elif tool == 2: tool_widget = ThumbWidget(self.filename, self.image) elif tool == 3: tool_widget = LocationWidget(self.filename) else: return elif group == 2: if tool == 0: tool_widget = MagnifierWidget(self.image) elif tool == 1: tool_widget = HistWidget(self.image) elif tool == 2: tool_widget = AdjustWidget(self.image) elif tool == 3: tool_widget = ComparisonWidget(self.filename, self.image) else: return elif group == 3: if tool == 0: tool_widget = GradientWidget(self.image) elif tool == 1: tool_widget = EchoWidget(self.image) elif tool == 2: tool_widget = WaveletWidget(self.image) elif tool == 3: tool_widget = FrequencyWidget(self.image) else: return elif group == 4: if tool == 0: tool_widget = PlotsWidget(self.image) elif tool == 1: tool_widget = SpaceWidget(self.image) elif tool == 2: tool_widget = PcaWidget(self.image) elif tool == 3: tool_widget = StatsWidget(self.image) else: return elif group == 5: if tool == 0: tool_widget = NoiseWidget(self.image) elif tool == 1: tool_widget = MinMaxWidget(self.image) elif tool == 2: tool_widget = PlanesWidget(self.image) else: return elif group == 6: if tool == 0: tool_widget = QualityWidget(self.filename, self.image) elif tool == 1: tool_widget = ElaWidget(self.image) # elif tool == 2: # tool_widget = MultipleWidget(self.image) else: return elif group == 7: if tool == 0: tool_widget = ContrastWidget(self.image) elif tool == 1: tool_widget = CloningWidget(self.image) elif tool == 2: tool_widget = SplicingWidget(self.image) else: return elif group == 8: if tool == 0: tool_widget = MedianWidget(self.image) elif tool == 3: tool_widget = StereoWidget(self.image) else: return else: return tool_widget.info_message.connect(self.show_message) sub_window = QMdiSubWindow() sub_window.setWidget(tool_widget) sub_window.setWindowTitle(item.text(0)) sub_window.setObjectName(item.text(0)) sub_window.setAttribute(Qt.WA_DeleteOnClose) sub_window.setWindowIcon(QIcon(f"icons/{group}.svg")) self.mdi_area.addSubWindow(sub_window) sub_window.show() sub_window.destroyed.connect(self.disable_bold) self.tree_widget.set_bold(item.text(0), enabled=True)
def open_tool(self, item, _): if not item.data(0, Qt.UserRole): return group = item.data(0, Qt.UserRole + 1) tool = item.data(0, Qt.UserRole + 2) for sub_window in self.mdi_area.subWindowList(): if sub_window.windowTitle() == item.text(0): sub_window.setWindowState(Qt.WindowActive) sub_window.setFocus() return tool_widget = None if group == 0: if tool == 0: tool_widget = OriginalWidget(self.image) elif tool == 1: tool_widget = DigestWidget(self.filename, self.image) elif tool == 2: tool_widget = EditorWidget() elif tool == 3: tool_widget = ReverseWidget() else: return elif group == 1: if tool == 0: tool_widget = StructureWidget(self.filename) elif tool == 1: tool_widget = MetadataWidget(self.filename) elif tool == 2: tool_widget = ThumbWidget(self.filename, self.image) elif tool == 3: tool_widget = LocationWidget(self.filename) else: return elif group == 2: if tool == 0: tool_widget = MagnifierWidget(self.image) elif tool == 1: tool_widget = ComparisonWidget(self.image) elif tool == 2: tool_widget = AdjustWidget(self.image) elif tool == 3: tool_widget = FourierWidget(self.image) else: return elif group == 3: if tool == 0: tool_widget = QualityWidget(self.filename) elif tool == 1: tool_widget = ElaWidget(self.image) elif tool == 2: tool_widget = MultipleWidget(self.image) else: return elif group == 4: if tool == 1: tool_widget = PcaWidget(self.image) elif tool == 2: tool_widget = StatsWidget(self.image) elif tool == 3: tool_widget = SpaceWidget(self.image) else: return elif group == 5: if tool == 0: tool_widget = GradientWidget(self.image) elif tool == 1: tool_widget = EchoWidget(self.image) else: return elif group == 6: if tool == 0: tool_widget = NoiseWidget(self.image) elif tool == 1: tool_widget = MinMaxWidget(self.image) elif tool == 2: tool_widget = PlanesWidget(self.image) else: return # FIXME: Aggiungere un metodo init e dopo fare il connect, sennò i messaggi del costruttore non si vedono tool_widget.info_message.connect(self.show_message) tool_widget.help_clicked.connect(self.show_help) sub_window = QMdiSubWindow() sub_window.setWidget(tool_widget) sub_window.setWindowTitle(item.text(0)) sub_window.setObjectName(item.text(0)) sub_window.setAttribute(Qt.WA_DeleteOnClose) sub_window.setWindowIcon(QIcon('icons/{}.svg'.format(group))) self.mdi_area.addSubWindow(sub_window) sub_window.show() sub_window.destroyed.connect(self.disable_bold) self.tree_widget.set_bold(item.text(0), enabled=True)
class MainWindow(QMainWindow): def __init__(self, exp): super(MainWindow, self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) self.setWindowIcon(QIcon('icons/main.ico')) # Setup status bar. Cannot do this in the Designer. self.btn_idle = QPushButton("Record", self) self.btn_idle.setStyleSheet("background-color : red") self.btn_idle.setCheckable(True) self.ui.statusbar.addWidget(self.btn_idle) self.exp = exp self.threadpool = QThreadPool() # Setup the GUI windows # self.showMaximized() self.set_windows() # Menu bar function binding self.ui.actionNew.triggered.connect(self.OnNewExperiment) self.ui.actionOpen.triggered.connect(self.OnOpenExperiment) self.ui.actionSave.triggered.connect(self.OnSaveExperiment) self.ui.actionTileWindows.triggered.connect(self.OnTileWindows) self.ui.actionOpenWindows.triggered.connect(self.OnShowWindows) self.ui.actionLoadScript.triggered.connect(self.OnLoadScript) self.ui.actionReloadScript.triggered.connect(self.OnReloadScript) # Status bar self.btn_idle.clicked.connect(self.OnRecord) # Keyboard shortcuts self.full_screen = False self.shortcut_full_screen = QShortcut(QKeySequence('F11'), self) self.shortcut_full_screen.activated.connect(self.OnFullScreen) # Start looking for data files self.start_file_thread() self.start_plot_thread() self.showMaximized() # Open the application in full screen mode self.show() def set_table_win(self): # Add data table sub-window self.data_table = DataTable(self.exp, self) self.data_table.signals.plot.connect(self.replot) self.DataTableWindow = QMdiSubWindow() self.DataTableWindow.setWidget(self.data_table) self.ui.mdiArea.addSubWindow(self.DataTableWindow) self.DataTableWindow.show() def set_param_win(self): # Add analysis parameters self.analysis_parameters = Parameter(self.exp, self) self.analysis_parameters.signals.plot.connect(self.replot) self.ParameterWindow = QMdiSubWindow() self.ParameterWindow.setWidget(self.analysis_parameters) self.ui.mdiArea.addSubWindow(self.ParameterWindow) self.ParameterWindow.show() # Add note window self.exp_notes = Notes(self.exp, self) self.NotesWindow = QMdiSubWindow() self.NotesWindow.setWidget(self.exp_notes) self.ui.mdiArea.addSubWindow(self.NotesWindow) self.NotesWindow.show() def set_figs_win(self): # Add plots self.FigureWindows = {} self.figs = {} _figs = self.exp.get_figures() for _name in _figs.keys(): self.figs[_name] = MplCanvas(_figs[_name]) self.FigureWindows[_name] = QMdiSubWindow() self.FigureWindows[_name].setWidget(self.figs[_name]) self.FigureWindows[_name].resize(500, 400) self.ui.mdiArea.addSubWindow(self.FigureWindows[_name]) self.FigureWindows[_name].show() def set_windows(self): self.set_table_win() self.set_param_win() self.set_figs_win() self.OnTileWindows() def clear_windows(self, subwindows='all'): if subwindows == 'all': subwindows = self.ui.mdiArea.subWindowList() for _win in subwindows: self.ui.mdiArea.removeSubWindow(_win) def refresh_windows(self): self.clear_windows() self.set_windows() def start_file_thread(self): # Start file thread self.file_thread = FileThread(self.exp, self) self.file_thread.signals.result.connect(self.add_result) self.file_thread.start() def stop_file_thread(self): self.file_thread.abort() def start_plot_thread(self): self.plot_thread = PlotThread(self) self.plot_thread.start() def stop_plot_thread(self): self.plot_thread.abort() @Slot() def replot(self): self.plot_thread.replot() @Slot() def OnFullScreen(self): if self.full_screen: self.showMaximized() else: self.showFullScreen() self.full_screen = not self.full_screen @Slot() def OnTileWindows(self): _win_width = self.ui.mdiArea.width() # Window width top_row_height = 450 _table_win_width = max(1200, _win_width * 0.65) _param_win_width = 3. / 7. * (_win_width - _table_win_width) _notes_win_width = (_win_width - _table_win_width - _param_win_width) # Position table window _ract = QRect(0., 0., _table_win_width, top_row_height) self.DataTableWindow.setGeometry(_ract) self.DataTableWindow.move(0, 0) # Positon parameter window _ract = QRect(0., 0., _param_win_width, top_row_height) self.ParameterWindow.setGeometry(_ract) self.ParameterWindow.move(_table_win_width, 0) # Position Note window _ract = QRect(0., 0., _notes_win_width, top_row_height) self.NotesWindow.setGeometry(_ract) self.NotesWindow.move(_table_win_width + _param_win_width, 0) # Tile figure windwos _fig_win_size = _win_width / 4. for ii, _name in enumerate(self.FigureWindows.keys()): x_shift = ii % 4 y_shift = math.floor(ii / 4) _rect = QRect(0., 0., _fig_win_size, _fig_win_size) self.FigureWindows[_name].setGeometry(_rect) self.FigureWindows[_name].move( _fig_win_size * x_shift, _fig_win_size * y_shift + top_row_height) @Slot() def OnShowWindows(self): self.refresh_windows() @Slot() def OnNewExperiment(self): self.OnSaveExperiment() _info = self.exp.get_exp_info() _name = _info['name'] _script = os.path.join(_info['script_dir'], _info['script']) dlg = NewExpDialog(name=_name, script=_script) if dlg.exec_(): _name = dlg.get_name() _script = dlg.get_script() self.exp = Experiment(name=_name, script=_script) self.file_thread.set_experiment(self.exp) self.clear_windows() self.set_windows() @Slot() def OnOpenExperiment(self): dlg = QFileDialog() dlg.setNameFilter("Experiment (*.info)") if dlg.exec_(): dirname = dlg.selectedFiles()[0] dirname = dirname.replace( '/', '\\' ) # Convert to Windows path. Maybe use pathlib in the future exp = load_exp(dirname) self.exp = exp self.file_thread.set_experiment(self.exp) self.clear_windows() self.set_windows() @Slot() def OnSaveExperiment(self): self.exp.save() @Slot() def OnLoadScript(self): dlg = QFileDialog() dlg.setNameFilter("Script (*.ipynb)") if dlg.exec_(): _script = dlg.selectedFiles()[0] self.exp.set_analysis_script(_script) self.clear_windows() self.set_windows() @Slot() def OnReloadScript(self): # Load from data folder instead of script folder _script = os.path.join(self.exp.exp_dir, self.exp.script_filename) if self.exp.script_filename.strip() == '': console_print( 'Main Window', 'Unknown scrit file! Use "Load Script" in the "Analysis" Menu.' .format(_script), method='error') return if not os.path.exists(_script): console_print('Main Window', 'Script ({}) doesn\'t exist!'.format(_script)) return _params = self.exp.get_parameters( ) # Preserve the parameters when reload self.exp.set_analysis_script(_script) self.clear_windows() self.set_windows() self.analysis_parameters.set_parameters( _params) # Set to current parameters @Slot() def OnRecord(self): _status = self.btn_idle.isChecked() if self.file_thread == None: # Restart the file thread if it crashed self.start_file_thread() self.file_thread.set_save(_status) if _status: self.btn_idle.setStyleSheet("background-color : green") else: self.btn_idle.setStyleSheet("background-color : red") return 1 @Slot(int) def add_result(self, data_id): self.data_table.add_run(data_id) self.replot() @Slot() def update_figures(self): # Refresh the GUI for new figures. for _name in self.figs.keys(): self.figs[_name].draw() return 1 def load_analysis_script(self, filename): self.exp.set_analysis_script(filename) # self.ui.mdiArea.removeSubWindow(self.ParameterWindow) self.analysis_parameters = Parameter(self.exp, self) self.ParameterWindow.setWidget(self.analysis_parameters)
def __init__(self, parent, title, data, id=0, hidden_columns=[], index_column=None, childSubWindow={}, type=1, file_path=None): """ :param title: Window title :param data: Table show data :param hidden_columns: Columns to be hidden :param index_column: which column is index column :param childSubWindow: When double click each row, which child table should be opened Sample: { "title":"", "type": "table", "table_name": "option/underlyings/%underlying_order_book_id%", "where:"", "select":"", "hidden_columns":[], "index_column":[], "childSubWindow":{}, } :return: """ self.parent = parent self.window = parent.window self.mdi_area = parent.mdi_area if index_column: data.index = list(data[index_column]) data.index.name = index_column subWindow = QMdiSubWindow() setattr(subWindow, "subWindowType", 0) setattr(subWindow, "btData", data) setattr(subWindow, "btId", id) setattr(subWindow, "btType", type) setattr(subWindow, "btFilePath", file_path) setattr(subWindow, "childSubWindow", childSubWindow) setattr(subWindow, "hidden_columns", hidden_columns) tableView = QTableView() # 双击列的信号 tableView.horizontalHeader().sectionDoubleClicked.connect( lambda event: self.onTableViewColumnDoubleClicked(event, None)) # 双击行的信号 tableView.verticalHeader().sectionDoubleClicked.connect( self.onTableViewRowDoubleClicked) # 双击cell的信号 tableView.doubleClicked.connect(self.onTableViewCellDoubleClicked) # 右键列 headers = tableView.horizontalHeader() headers.setContextMenuPolicy(Qt.CustomContextMenu) headers.customContextMenuRequested.connect( lambda event: self.onTableViewColumnClicked(event, tableView)) headers.setSelectionMode(QAbstractItemView.SingleSelection) cornerButton = tableView.findChild(QAbstractButton) cornerButton.customContextMenuRequested.connect( self.onCornerButtonRightClicked) tableView.setWindowTitle(title) tableView.setWindowIcon(QtGui.QIcon("../icon/sheet.png")) proxyModel = QtCore.QSortFilterProxyModel(subWindow) mode = pandas_mode.PandasModel(data) proxyModel.setSourceModel(mode) tableView.setModel(proxyModel) self._hide_columns(tableView, data, hidden_columns) systemMenu = subWindow.systemMenu() last_action = systemMenu.actions()[-1] display_setting = self.window.findChild(QAction, "display_action") systemMenu.insertAction(last_action, display_setting) subWindow.setAttribute(Qt.WA_DeleteOnClose) subWindow.setWidget(tableView) self.mdi_area.addSubWindow(subWindow) subWindow.show()