def __init__(self, parent): QSplitter.__init__(self, parent) # List Widget self.csvlist = QListWidget(self) self.csvlist.setContextMenuPolicy(Qt.ActionsContextMenu) plotCSV = QAction(self) plotCSV.setText("Plot") plotCSV.triggered.connect(self.plotCSV) delete = QAction(self) delete.setText("Remove") delete.triggered.connect(self.removeItem) extractCSV = QAction(self) extractCSV.setText("Extract to Arrays") extractCSV.triggered.connect(self.extractArray) self.csvlist.addAction(plotCSV) self.csvlist.addAction(extractCSV) self.csvlist.addAction(delete) self.addWidget(self.csvlist) # Properties widget self.properties = DataSetEditGroupBox(_("參數(Properties)"), CsvParam) self.properties.setEnabled(False) self.addWidget(self.properties)
def __init__(self, parent=None): QSplitter.__init__(self, parent) self.setWindowTitle(MAIN_WINDOW_TITLE) self.setWindowIcon(get_icon("agent.svg")) self.sysTray = SystemTray(self) self.connect(self.sysTray, SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), self.__icon_activated) checks = get_checks() datadog_conf = DatadogConf(get_config_path(), description="Agent settings file: datadog.conf") self.log_file = LogFile() listwidget = QListWidget(self) listwidget.addItems([osp.basename(check.module_name).replace("_", " ").title() for check in checks]) self.properties = PropertiesWidget(self) self.addWidget(listwidget) self.addWidget(self.properties) self.connect(self.properties.enable_button, SIGNAL("clicked()"), lambda: enable_check(self.properties)) self.connect(self.properties.disable_button, SIGNAL("clicked()"), lambda: disable_check(self.properties)) self.connect(self.properties.save_button, SIGNAL("clicked()"), lambda: save_file(self.properties)) self.connect(listwidget, SIGNAL('currentRowChanged(int)'), lambda row: self.properties.set_item(checks[row])) self.connect(self.properties.edit_datadog_conf_button, SIGNAL('clicked()'), lambda: self.properties.set_datadog_conf(datadog_conf)) self.connect(self.properties.view_log_button, SIGNAL('clicked()'), lambda: self.properties.set_log_file(self.log_file)) self.manager_menu = Menu(self) self.connect(self.properties.menu_button, SIGNAL("clicked()"), lambda: self.manager_menu.popup(self.properties.menu_button.mapToGlobal(QPoint(0,0)))) listwidget.setCurrentRow(0) self.setSizes([150, 1]) self.setStretchFactor(1, 1) self.resize(QSize(950, 600)) self.properties.set_datadog_conf(datadog_conf) self.do_refresh()
def __init__(self, package, parent=None): QSplitter.__init__(self, parent) self.setWindowTitle(_("Tests - %s module") % package.__name__) self.setWindowIcon(get_icon("%s.svg" % package.__name__, "guidata.svg")) test_package_name = '%s.tests' % package.__name__ _temp = __import__(test_package_name) test_package = sys.modules[test_package_name] tests = get_tests(test_package) listwidget = QListWidget(self) listwidget.addItems([osp.basename(test.filename) for test in tests]) self.properties = TestPropertiesWidget(self) self.addWidget(listwidget) self.addWidget(self.properties) self.properties.run_button.clicked.connect( lambda: tests[listwidget.currentRow()].run()) self.properties.quit_button.clicked.connect(self.close) listwidget.currentRowChanged.connect( lambda row: self.properties.set_item(tests[row])) listwidget.itemActivated.connect( lambda: tests[listwidget.currentRow()].run()) listwidget.setCurrentRow(0) QShortcut(QKeySequence("Escape"), self, self.close) self.setSizes([150, 1]) self.setStretchFactor(1, 1) self.resize(QSize(950, 600)) self.properties.set_item(tests[0])
def __init__(self, parent): QSplitter.__init__(self, parent) self.imagelist = QListWidget(self) self.addWidget(self.imagelist) self.properties = DataSetEditGroupBox(_("Properties"), ImageParam) self.properties.setEnabled(False) self.addWidget(self.properties)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.widget_layout = QVBoxLayout() title_layout = QHBoxLayout() title_layout.addStretch() style = "<span style=\'color: #444444\'><b>%s</b></span>" title = QLabel(style % "Operations") title_layout.addWidget(title) title_layout.addStretch() self.widget_layout.addLayout(title_layout) # Create ListWidget and add 10 items to move around. self.list_widget = QListWidget() # self.list_widget.setDragDropMode(QAbstractItemView.InternalMove) self.list_widget.setSelectionMode(QAbstractItemView.ExtendedSelection) self.list_widget.setSortingEnabled(False) self.list_widget.currentItemChanged.connect(self._populate_settings_update) self.widget_layout.addWidget(self.list_widget) otitle_layout = QHBoxLayout() otitle_layout.addStretch() otitle = QLabel(style % "Operation settings") otitle_layout.addWidget(otitle) otitle_layout.addStretch() self.widget_layout.addLayout(otitle_layout) self.operations_combo = QComboBox() self.operations_combo.currentIndexChanged.connect(self._populate_settings_add) self.widget_layout.addWidget(self.operations_combo) self.operation_settings = GenericOperationWidget() self.widget_layout.addWidget(self.operation_settings) self.toolbar = QToolBar() self.toolbar.addAction(get_icon('apply.png'), "Apply/Replace", self._change_operation) self.toolbar.addAction(get_icon('editors/edit_add.png'), "Add after", self._add_operation) self.toolbar.addAction(get_icon('trash.png'), "Remove", self._remove_operation) self.widget_layout.addWidget(self.toolbar) self.setLayout(self.widget_layout)
def __init__(self, parent): QSplitter.__init__(self, parent) # List Widget self.arraylist = QListWidget(self) self.arraylist.setContextMenuPolicy(Qt.ActionsContextMenu) newArray = QAction(self) newArray.setText("Paste Array (no header name)") newArray.triggered.connect(self.pasteArray) newArrayWithName = QAction(self) newArrayWithName.setText("Paste Array (with header name)") newArrayWithName.triggered.connect(self.pasteArrayWithName) plotArray = QAction(self) plotArray.setText("Plot Array") plotArray.triggered.connect(self.plotArray) modifyArray = QAction(self) modifyArray.setText("Modify Array(Calibration)") modifyArray.triggered.connect(self.modifyArray) plotScatter = QAction(self) plotScatter.setText("Plot Scatter") plotScatter.triggered.connect(self.plotScatter) plotHist = QAction(self) plotHist.setText("Plot Histogram") plotHist.triggered.connect(self.plotHist) delete = QAction(self) delete.setText("Remove") delete.triggered.connect(self.removeItem) curveDialog = QAction(self) curveDialog.setText("Open Curve Dialog") curveDialog.triggered.connect(self.openCurveDialog) self.arraylist.addAction(newArray) self.arraylist.addAction(newArrayWithName) self.arraylist.addAction(plotArray) self.arraylist.addAction(plotScatter) self.arraylist.addAction(plotHist) self.arraylist.addAction(modifyArray) self.arraylist.addAction(curveDialog) self.arraylist.addAction(delete) self.addWidget(self.arraylist) # Properties widget self.properties = DataSetEditGroupBox(_("參數(Properties)"), CsvParam) self.properties.setEnabled(False) self.addWidget(self.properties)
def create_list_dock(self): list_dock = QDockWidget(_('Files')) self.addDockWidget(Qt.RightDockWidgetArea, list_dock) self.list_widget = QListWidget() self.connect( self.list_widget, SIGNAL("currentItemChanged( QListWidgetItem, QListWidgetItem)"), self.change_selection) list_dock.setWidget(self.list_widget)
class ImageListWithProperties(QSplitter): # Define View的部分 def __init__(self, parent): QSplitter.__init__(self, parent) # List Widget self.csvlist = QListWidget(self) self.csvlist.setContextMenuPolicy(Qt.ActionsContextMenu) plotCSV = QAction(self) plotCSV.setText("Plot") plotCSV.triggered.connect(self.plotCSV) delete = QAction(self) delete.setText("Remove") delete.triggered.connect(self.removeItem) extractCSV = QAction(self) extractCSV.setText("Extract to Arrays") extractCSV.triggered.connect(self.extractArray) self.csvlist.addAction(plotCSV) self.csvlist.addAction(extractCSV) self.csvlist.addAction(delete) self.addWidget(self.csvlist) # Properties widget self.properties = DataSetEditGroupBox(_("參數(Properties)"), CsvParam) self.properties.setEnabled(False) self.addWidget(self.properties) def plotCSV(self): self.emit(SIGNAL("PLOT")) def removeItem(self): self.emit(SIGNAL("REMOVE")) def extractArray(self): self.emit(SIGNAL("EXTRACT_ARRAY"))
class OperationsWidget(QWidget): operations_changed = QtCore.pyqtSignal() operation_changed = QtCore.pyqtSignal(dict, int) operation_added = QtCore.pyqtSignal(dict, int) def __init__(self, parent=None): QWidget.__init__(self, parent) self.widget_layout = QVBoxLayout() title_layout = QHBoxLayout() title_layout.addStretch() style = "<span style=\'color: #444444\'><b>%s</b></span>" title = QLabel(style % "Operations") title_layout.addWidget(title) title_layout.addStretch() self.widget_layout.addLayout(title_layout) # Create ListWidget and add 10 items to move around. self.list_widget = QListWidget() # self.list_widget.setDragDropMode(QAbstractItemView.InternalMove) self.list_widget.setSelectionMode(QAbstractItemView.ExtendedSelection) self.list_widget.setSortingEnabled(False) self.list_widget.currentItemChanged.connect(self._populate_settings_update) self.widget_layout.addWidget(self.list_widget) otitle_layout = QHBoxLayout() otitle_layout.addStretch() otitle = QLabel(style % "Operation settings") otitle_layout.addWidget(otitle) otitle_layout.addStretch() self.widget_layout.addLayout(otitle_layout) self.operations_combo = QComboBox() self.operations_combo.currentIndexChanged.connect(self._populate_settings_add) self.widget_layout.addWidget(self.operations_combo) self.operation_settings = GenericOperationWidget() self.widget_layout.addWidget(self.operation_settings) self.toolbar = QToolBar() self.toolbar.addAction(get_icon('apply.png'), "Apply/Replace", self._change_operation) self.toolbar.addAction(get_icon('editors/edit_add.png'), "Add after", self._add_operation) self.toolbar.addAction(get_icon('trash.png'), "Remove", self._remove_operation) self.widget_layout.addWidget(self.toolbar) self.setLayout(self.widget_layout) def populate_available_operations(self, dict): """ Populate combobox with available operation names """ self.operations_combo.addItems(dict) def set_operations(self, operations_dict): """ Populate operations list with given dict of operations """ self.list_widget.clear() for op in operations_dict: self.list_widget.addItem(Operation(op)) def get_operations(self): """ Return list of operations. """ operations = [] for i in range(self.list_widget.count()): op = self.list_widget.item(i) operations.append(op._op) return operations def _remove_operation(self): self.list_widget.takeItem(self.list_widget.currentRow()) self.operations_changed.emit() def _add_operation(self): """ Add operation currently in self.operation_settings to the operation list. Signals: ======== Emits self.opeartion_added and self.operations_changed on success """ op = self.operation_settings.get_operation() current_row = self.list_widget.currentRow() self.list_widget.insertItem(current_row + 1, Operation(op)) index = self.list_widget.model().index(current_row + 1, 0) self.list_widget.setCurrentIndex(index) self.operation_added.emit(op, current_row + 1) self.operations_changed.emit() def _change_operation(self): """ Replace currently selected operation with operation in self.operation_settings (apply changed settings or replace operation). Signals: ======== Emits self.operation_changed and self.operations_changed on success """ op = self.operation_settings.get_operation() current_row = self.list_widget.currentRow() self.list_widget.takeItem(self.list_widget.currentRow()) self.list_widget.insertItem(current_row, Operation(op)) index = self.list_widget.model().index(current_row, 0) self.list_widget.setCurrentIndex(index) self.operation_changed.emit(op, current_row) self.operations_changed.emit() def _populate_settings_update(self, item): """ Fill self.operation_settings with details of currently selected operation. """ try: idx = self.operations_combo.findText(item._op["module"]) if idx >= 0: self.operations_combo.setCurrentIndex(idx) self.operation_settings.set_operation(item._op) except AttributeError: pass def _populate_settings_add(self, index): self.operation_settings.set_operation({"module": self.operations_combo.currentText()})
def __init__(self, parent=None): log_conf = get_logging_config() QSplitter.__init__(self, parent) self.setWindowTitle(MAIN_WINDOW_TITLE) self.setWindowIcon(get_icon("agent.svg")) self.sysTray = SystemTray(self) self.connect(self.sysTray, SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), self.__icon_activated) checks = get_checks() datadog_conf = DatadogConf(get_config_path()) self.create_logs_files_windows(log_conf) listwidget = QListWidget(self) listwidget.addItems([ osp.basename(check.module_name).replace("_", " ").title() for check in checks ]) self.properties = PropertiesWidget(self) self.setting_button = QPushButton(get_icon("info.png"), "Logs and Status", self) self.menu_button = QPushButton(get_icon("settings.png"), "Actions", self) self.settings = [ ("Forwarder Logs", lambda: [ self.properties.set_log_file(self.forwarder_log_file), self.show_html(self.properties.group_code, self.properties. html_window, False) ]), ("Collector Logs", lambda: [ self.properties.set_log_file(self.collector_log_file), self.show_html(self.properties.group_code, self.properties. html_window, False) ]), ("Dogstatsd Logs", lambda: [ self.properties.set_log_file(self.dogstatsd_log_file), self.show_html(self.properties.group_code, self.properties. html_window, False) ]), ("JMX Fetch Logs", lambda: [ self.properties.set_log_file(self.jmxfetch_log_file), self.show_html(self.properties.group_code, self.properties. html_window, False) ]), ] if Platform.is_windows(): self.settings.extend([ ("Service Logs", lambda: [ self.properties.set_log_file(self.service_log_file), self.show_html(self.properties.group_code, self.properties. html_window, False) ]), ]) self.settings.extend([ ("Agent Status", lambda: [ self.properties.html_window.setHtml(self.properties.html_window .latest_status()), self.show_html(self.properties.group_code, self.properties. html_window, True), self.properties.set_status() ]), ]) self.agent_settings = QPushButton(get_icon("edit.png"), "Settings", self) self.connect( self.agent_settings, SIGNAL("clicked()"), lambda: [ self.properties.set_datadog_conf(datadog_conf), self.show_html(self.properties.group_code, self.properties. html_window, False) ]) self.setting_menu = SettingMenu(self.settings) self.connect( self.setting_button, SIGNAL("clicked()"), lambda: self.setting_menu.popup( self.setting_button.mapToGlobal(QPoint(0, 0)))) self.manager_menu = Menu(self) self.connect( self.menu_button, SIGNAL("clicked()"), lambda: self.manager_menu.popup( self.menu_button.mapToGlobal(QPoint(0, 0)))) holdingBox = QGroupBox("", self) Box = QVBoxLayout(self) Box.addWidget(self.agent_settings) Box.addWidget(self.setting_button) Box.addWidget(self.menu_button) Box.addWidget(listwidget) holdingBox.setLayout(Box) self.addWidget(holdingBox) self.addWidget(self.properties) self.connect(self.properties.enable_button, SIGNAL("clicked()"), lambda: enable_check(self.properties)) self.connect(self.properties.disable_button, SIGNAL("clicked()"), lambda: disable_check(self.properties)) self.connect(self.properties.save_button, SIGNAL("clicked()"), lambda: save_file(self.properties)) self.connect( self.properties.refresh_button, SIGNAL("clicked()"), lambda: [ self.properties.set_log_file(self.properties.current_file), self.properties.html_window.setHtml(self.properties.html_window .latest_status()) ]) self.connect( listwidget, SIGNAL('currentRowChanged(int)'), lambda row: [ self.properties.set_item(checks[row]), self.show_html(self.properties.group_code, self.properties. html_window, False) ]) listwidget.setCurrentRow(0) self.setSizes([150, 1]) self.setStretchFactor(1, 1) self.resize(QSize(950, 600)) self.properties.set_datadog_conf(datadog_conf) self.do_refresh()
def __init__(self, parent=None): QSplitter.__init__(self, parent) self.setWindowTitle(MAIN_WINDOW_TITLE) self.setWindowIcon(get_icon("agent.svg")) self.sysTray = SystemTray(self) self.connect(self.sysTray, SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), self.__icon_activated) checks = get_checks() datadog_conf = DatadogConf(get_config_path(), description="Agent settings file: datadog.conf") self.forwarder_log_file = ForwarderLogFile() self.collector_log_file = CollectorLogFile() self.dogstatsd_log_file = DogstatsdLogFile() self.jmxfetch_log_file = JMXFetchLogFile() listwidget = QListWidget(self) listwidget.addItems([osp.basename(check.module_name).replace("_", " ").title() for check in checks]) self.properties = PropertiesWidget(self) self.setting_button = QPushButton(get_icon("info.png"), "Logs and Status", self) self.menu_button = QPushButton(get_icon("settings.png"), "Actions", self) self.settings = [ ( "Forwarder Logs", lambda: [ self.properties.set_log_file(self.forwarder_log_file), self.show_html(self.properties.group_code, self.properties.html_window, False), ], ), ( "Collector Logs", lambda: [ self.properties.set_log_file(self.collector_log_file), self.show_html(self.properties.group_code, self.properties.html_window, False), ], ), ( "Dogstatsd Logs", lambda: [ self.properties.set_log_file(self.dogstatsd_log_file), self.show_html(self.properties.group_code, self.properties.html_window, False), ], ), ( "JMX Fetch Logs", lambda: [ self.properties.set_log_file(self.jmxfetch_log_file), self.show_html(self.properties.group_code, self.properties.html_window, False), ], ), ( "Agent Status", lambda: [ self.properties.html_window.setHtml(self.properties.html_window.latest_status()), self.show_html(self.properties.group_code, self.properties.html_window, True), self.properties.set_status(), ], ), ] self.agent_settings = QPushButton(get_icon("edit.png"), "Settings", self) self.connect( self.agent_settings, SIGNAL("clicked()"), lambda: [ self.properties.set_datadog_conf(datadog_conf), self.show_html(self.properties.group_code, self.properties.html_window, False), ], ) self.setting_menu = SettingMenu(self.settings) self.connect( self.setting_button, SIGNAL("clicked()"), lambda: self.setting_menu.popup(self.setting_button.mapToGlobal(QPoint(0, 0))), ) self.manager_menu = Menu(self) self.connect( self.menu_button, SIGNAL("clicked()"), lambda: self.manager_menu.popup(self.menu_button.mapToGlobal(QPoint(0, 0))), ) holdingBox = QGroupBox("", self) Box = QVBoxLayout(self) Box.addWidget(self.agent_settings) Box.addWidget(self.setting_button) Box.addWidget(self.menu_button) Box.addWidget(listwidget) holdingBox.setLayout(Box) self.addWidget(holdingBox) self.addWidget(self.properties) self.connect(self.properties.enable_button, SIGNAL("clicked()"), lambda: enable_check(self.properties)) self.connect(self.properties.disable_button, SIGNAL("clicked()"), lambda: disable_check(self.properties)) self.connect(self.properties.save_button, SIGNAL("clicked()"), lambda: save_file(self.properties)) self.connect( self.properties.refresh_button, SIGNAL("clicked()"), lambda: [ self.properties.set_log_file(self.properties.current_file), self.properties.html_window.setHtml(self.properties.html_window.latest_status()), ], ) self.connect( listwidget, SIGNAL("currentRowChanged(int)"), lambda row: [ self.properties.set_item(checks[row]), self.show_html(self.properties.group_code, self.properties.html_window, False), ], ) listwidget.setCurrentRow(0) self.setSizes([150, 1]) self.setStretchFactor(1, 1) self.resize(QSize(950, 600)) self.properties.set_datadog_conf(datadog_conf) self.do_refresh()
def create_info_dock(self): info_dock = QDockWidget(_('Info')) self.addDockWidget(Qt.RightDockWidgetArea, info_dock) self.info_widget = QListWidget() info_dock.setWidget(self.info_widget)
def __init__(self, parent): QSplitter.__init__(self, parent) self.name = 'subject' self.age = 26 self.peakL = 559 self.peakM = 530 self.ref_LED = 10 self.LED1 = 15 self.LED2 = 13.9 self.LED3 = 40.45 self.L_OD = 0.35 self.M_OD = 0.22 self.setContentsMargins(10, 10, 10, 10) self.setOrientation(Qt.Vertical) line1 = QSplitter() line1.setOrientation(Qt.Horizontal) line2 = QSplitter() line2.setOrientation(Qt.Horizontal) line3 = QSplitter() line3.setOrientation(Qt.Horizontal) line4 = QSplitter() line4.setOrientation(Qt.Horizontal) line5 = QSplitter() line5.setOrientation(Qt.Horizontal) line6 = QSplitter() line6.setOrientation(Qt.Horizontal) line7 = QSplitter() line7.setOrientation(Qt.Horizontal) line8 = QSplitter() line8.setOrientation(Qt.Horizontal) self.txt1 = QLineEdit(str(self.name)) self.txt1.setMaximumWidth(100) self.txt2 = QLineEdit(str(self.age)) self.txt2.setMaximumWidth(100) self.txt3 = QLineEdit(str(self.peakL)) self.txt3.setMaximumWidth(100) self.txt4 = QLineEdit(str(self.peakM)) self.txt4.setMaximumWidth(100) self.txt5 = QLineEdit(str(self.ref_LED)) self.txt5.setMaximumWidth(100) self.txt6 = QLineEdit() self.txt6.setMaximumWidth(100) self.txt7 = QLineEdit() self.txt7.setMaximumWidth(100) self.txt8 = QLineEdit() self.txt8.setMaximumWidth(100) label1 = QLabel('ID') label2 = QLabel('age') label3 = QLabel('peak L') label4 = QLabel('peak M') label5 = QLabel('ref LED') label6 = QLabel('LED1') label7 = QLabel('LED2') label8 = QLabel('LED3') line1.addWidget(label1) line2.addWidget(label2) line3.addWidget(label3) line4.addWidget(label4) line5.addWidget(label5) line6.addWidget(label6) line7.addWidget(label7) line8.addWidget(label8) line1.addWidget(self.txt1) line2.addWidget(self.txt2) line3.addWidget(self.txt3) line4.addWidget(self.txt4) line5.addWidget(self.txt5) line6.addWidget(self.txt6) line7.addWidget(self.txt7) line8.addWidget(self.txt8) self.load_button = QPushButton('load data') self.load_button.clicked.connect(self.load) self.analyze_button = QPushButton('analyze') self.analyze_button.clicked.connect(self.analyze) # add left side of the bottom panel left_side = QSplitter() left_side.setOrientation(Qt.Vertical) left_side.addWidget(self.load_button) left_side.addWidget(line1) left_side.addWidget(line2) left_side.addWidget(line3) left_side.addWidget(line4) left_side.addWidget(line5) left_side.addWidget(line6) left_side.addWidget(line7) left_side.addWidget(line8) left_side.addWidget(self.analyze_button) # set up right side of the bottom panel self.results = QListWidget(self) self.save_button = QPushButton('save', self.results) self.save_button.clicked.connect(self.save) # add right side of the bottom panel right_side = QSplitter() right_side.setOrientation(Qt.Vertical) right_side.addWidget(self.results) right_side.addWidget(self.save_button) self.addWidget(right_side) # add left and right side to bottom bottom = QSplitter() bottom.addWidget(left_side) bottom.addWidget(right_side) self.plots = CurveWidget(self, xlabel='wavelength (nm)', ylabel='sensitivity') self.addWidget(self.plots) self.addWidget(bottom) self.show_data(PRINT=False) self.setStretchFactor(0, 0) self.setStretchFactor(1, 1) self.setHandleWidth(10) self.setSizes([800, 1]) self.parse_rc_file()
class CentralWidget(QSplitter): def __init__(self, parent): QSplitter.__init__(self, parent) self.name = 'subject' self.age = 26 self.peakL = 559 self.peakM = 530 self.ref_LED = 10 self.LED1 = 15 self.LED2 = 13.9 self.LED3 = 40.45 self.L_OD = 0.35 self.M_OD = 0.22 self.setContentsMargins(10, 10, 10, 10) self.setOrientation(Qt.Vertical) line1 = QSplitter() line1.setOrientation(Qt.Horizontal) line2 = QSplitter() line2.setOrientation(Qt.Horizontal) line3 = QSplitter() line3.setOrientation(Qt.Horizontal) line4 = QSplitter() line4.setOrientation(Qt.Horizontal) line5 = QSplitter() line5.setOrientation(Qt.Horizontal) line6 = QSplitter() line6.setOrientation(Qt.Horizontal) line7 = QSplitter() line7.setOrientation(Qt.Horizontal) line8 = QSplitter() line8.setOrientation(Qt.Horizontal) self.txt1 = QLineEdit(str(self.name)) self.txt1.setMaximumWidth(100) self.txt2 = QLineEdit(str(self.age)) self.txt2.setMaximumWidth(100) self.txt3 = QLineEdit(str(self.peakL)) self.txt3.setMaximumWidth(100) self.txt4 = QLineEdit(str(self.peakM)) self.txt4.setMaximumWidth(100) self.txt5 = QLineEdit(str(self.ref_LED)) self.txt5.setMaximumWidth(100) self.txt6 = QLineEdit() self.txt6.setMaximumWidth(100) self.txt7 = QLineEdit() self.txt7.setMaximumWidth(100) self.txt8 = QLineEdit() self.txt8.setMaximumWidth(100) label1 = QLabel('ID') label2 = QLabel('age') label3 = QLabel('peak L') label4 = QLabel('peak M') label5 = QLabel('ref LED') label6 = QLabel('LED1') label7 = QLabel('LED2') label8 = QLabel('LED3') line1.addWidget(label1) line2.addWidget(label2) line3.addWidget(label3) line4.addWidget(label4) line5.addWidget(label5) line6.addWidget(label6) line7.addWidget(label7) line8.addWidget(label8) line1.addWidget(self.txt1) line2.addWidget(self.txt2) line3.addWidget(self.txt3) line4.addWidget(self.txt4) line5.addWidget(self.txt5) line6.addWidget(self.txt6) line7.addWidget(self.txt7) line8.addWidget(self.txt8) self.load_button = QPushButton('load data') self.load_button.clicked.connect(self.load) self.analyze_button = QPushButton('analyze') self.analyze_button.clicked.connect(self.analyze) # add left side of the bottom panel left_side = QSplitter() left_side.setOrientation(Qt.Vertical) left_side.addWidget(self.load_button) left_side.addWidget(line1) left_side.addWidget(line2) left_side.addWidget(line3) left_side.addWidget(line4) left_side.addWidget(line5) left_side.addWidget(line6) left_side.addWidget(line7) left_side.addWidget(line8) left_side.addWidget(self.analyze_button) # set up right side of the bottom panel self.results = QListWidget(self) self.save_button = QPushButton('save', self.results) self.save_button.clicked.connect(self.save) # add right side of the bottom panel right_side = QSplitter() right_side.setOrientation(Qt.Vertical) right_side.addWidget(self.results) right_side.addWidget(self.save_button) self.addWidget(right_side) # add left and right side to bottom bottom = QSplitter() bottom.addWidget(left_side) bottom.addWidget(right_side) self.plots = CurveWidget(self, xlabel='wavelength (nm)', ylabel='sensitivity') self.addWidget(self.plots) self.addWidget(bottom) self.show_data(PRINT=False) self.setStretchFactor(0, 0) self.setStretchFactor(1, 1) self.setHandleWidth(10) self.setSizes([800, 1]) self.parse_rc_file() def parse_rc_file(self): ''' ''' handle = open(APP_DIR + '\\lm_ratiorc.txt', 'r') params = json.load(handle) self.save_dir = params['SAVE_DIR'] def analyze(self): ''' ''' success = self.get_input_values() if success: # analyze self.show_data() def get_input_values(self): ''' ''' # check that values in try: if len(str(self.txt1.displayText())) < 2: raise ValueError('No subject name') self.name = str(self.txt1.displayText()) self.age = float(self.txt2.displayText()) self.peakL = float(self.txt3.displayText()) self.peakM = float(self.txt4.displayText()) self.ref_LED = float(self.txt5.displayText()) self.LED1 = float(self.txt6.displayText()) self.LED2 = float(self.txt7.displayText()) self.LED3 = float(self.txt8.displayText()) return True except ValueError: message = [] message.append('ERROR: Make sure values were entered \nproperly.') self.results.addItems(message) return False def load(self): ''' ''' # Open a file finder. Load the csv file. name = QFileDialog.getOpenFileName() try: f = open(name, 'r') raw_dat = f.read() f.close() proceed = True except IOError: message = [] message.append('Could not open file.') self.results.addItems(message) proceed = False if proceed: data = {} lines = raw_dat.split('\n') for line in lines: if line != '': d = line.split(',') array = [] for num in d[1:]: if num != '': array.append(num) data[d[0]] = np.asarray(array, dtype=float) if 'name' in data: self.txt1.setText(str(data['name'][0])) else: self.txt1.setText('') if 'age' in data: self.txt2.setText(str(data['age'][0])) else: self.txt2.setText('') if 'L_peak' in data: self.txt3.setText(str(data['L_peak'][0])) else: self.txt3.setText('') if 'M_peak' in data: self.txt4.setText(str(data['M_peak'][0])) else: self.txt4.setText('') if 'ref' in data: self.txt5.setText(str(data['ref'][0])) else: self.txt5.setText('') if 'LED1' in data: self.txt6.setText(str(np.mean(data['LED1']))) else: self.txt6.setText('') if 'LED2' in data: self.txt7.setText(str(np.mean(data['LED2']))) else: self.txt7.setText('') if 'LED3' in data: self.txt8.setText(str(np.mean(data['LED3']))) else: self.txt8.setText('') def save(self): ''' ''' try: self.show_data(save_plot=True, save_data=True, PRINT=True) message = [] message.append('Success! Plot and data saved.') self.results.addItems(message) except: message = [] message.append('ERROR! Plot and data were not \nsaved.') self.results.addItems(message) def show_data(self, save_plot=False, save_data=False, PRINT=True): ''' ''' LM = LMratio() LM.set_parameters(age=self.age, L_peak=self.peakL, M_peak=self.peakM) LM.set_LED_rel_intensities(ref=self.ref_LED, light1=self.LED1, light2=self.LED2, light3=self.LED3) l_frac, error = LM.find_LMratio(PRINT=False) l_percent = l_frac * 100 _data = LM.return_data() data_x = _data['LED_peaks'] data_y = np.log10( np.array([_data['ref'], _data[1], _data[2], _data[3]])) # get fit spectrum = LM.return_spectrum() cones = LM.return_cones() fit = np.log10(LM.return_fit()) L_cones = np.log10(cones['L']) M_cones = np.log10(cones['M']) items = (make.curve(spectrum, L_cones, 'L cones', color='r', linewidth=2), make.curve(spectrum, M_cones, 'M cones', color='g', linewidth=2), make.curve(spectrum, fit, 'fit', color='k', linewidth=2), make.curve(data_x, data_y, linestyle='NoPen', marker="Diamond", markersize=14, markerfacecolor='k') ) self.plots.plot.del_all_items() for item in items: self.plots.plot.add_item(item) self.plots.plot.set_plot_limits(450, 670, -2, 0) self.plots.plot.replot() if PRINT: message = [self.name] message.append('L: ' + str(round(l_percent, 1))) message.append('M: ' + str(round(100 - l_percent, 2))) message.append('error: ' + str(round(error, 4))) self.results.clear() self.results.addItems(message) if save_plot or save_data: directory = self.save_dir + self.name + '\\' if not os.path.exists(directory): os.makedirs(directory) trial = 1 file_name = directory + self.name + '_' + str(trial) while os.path.exists(file_name + '.csv'): trial += 1 file_name = directory + self.name + '_' + str(trial) if save_plot: LM.plot_lm_ratio( save_name=file_name, save_plot=True, show_plot=False) if save_data: LM.save_data_and_params(file_name) del LM
class ArrayListWithProperties(QSplitter): # Define View的部分 def __init__(self, parent): QSplitter.__init__(self, parent) # List Widget self.arraylist = QListWidget(self) self.arraylist.setContextMenuPolicy(Qt.ActionsContextMenu) newArray = QAction(self) newArray.setText("Paste Array (no header name)") newArray.triggered.connect(self.pasteArray) newArrayWithName = QAction(self) newArrayWithName.setText("Paste Array (with header name)") newArrayWithName.triggered.connect(self.pasteArrayWithName) plotArray = QAction(self) plotArray.setText("Plot Array") plotArray.triggered.connect(self.plotArray) modifyArray = QAction(self) modifyArray.setText("Modify Array(Calibration)") modifyArray.triggered.connect(self.modifyArray) plotScatter = QAction(self) plotScatter.setText("Plot Scatter") plotScatter.triggered.connect(self.plotScatter) plotHist = QAction(self) plotHist.setText("Plot Histogram") plotHist.triggered.connect(self.plotHist) delete = QAction(self) delete.setText("Remove") delete.triggered.connect(self.removeItem) curveDialog = QAction(self) curveDialog.setText("Open Curve Dialog") curveDialog.triggered.connect(self.openCurveDialog) self.arraylist.addAction(newArray) self.arraylist.addAction(newArrayWithName) self.arraylist.addAction(plotArray) self.arraylist.addAction(plotScatter) self.arraylist.addAction(plotHist) self.arraylist.addAction(modifyArray) self.arraylist.addAction(curveDialog) self.arraylist.addAction(delete) self.addWidget(self.arraylist) # Properties widget self.properties = DataSetEditGroupBox(_("參數(Properties)"), CsvParam) self.properties.setEnabled(False) self.addWidget(self.properties) def pasteArray(self): self.emit(SIGNAL("PASTE_NO_NAME")) def pasteArrayWithName(self): self.emit(SIGNAL("PASTE_WITH_NAME")) def plotHist(self): self.emit(SIGNAL("PLOT_HISTOGRAM")) def plotArray(self): self.emit(SIGNAL("PLOT")) def modifyArray(self): self.emit(SIGNAL("MODIFY_ARRAY")) def plotScatter(self): self.emit(SIGNAL("PLOT_SCATTER")) def removeItem(self): self.emit(SIGNAL("REMOVE")) def openCurveDialog(self): self.emit(SIGNAL("OPEN_CURVEDIALOG"))