def BluetoothSetting(self): MainGroupbox = QWidget() layout = QVBoxLayout() groupbox = QGroupBox() groupbox.setFlat(True) B_layout = QVBoxLayout() BB_layout = QHBoxLayout() howto = QLabel("※ 아래에 블루투스로 통신할 휴대폰의 이름(모델명)을 적어주세요.") userBluetoothName = QLineEdit() saveCheck = QCheckBox("저장하기") saveCheck.stateChanged.connect( lambda: StatChange.saveName(saveCheck, userBluetoothName.text())) if os.path.isfile("USERNAME"): # noinspection PyBroadException try: f = open("USERNAME", 'r') data = f.read(300) f.close() data = AES.aesDecrypt(data) userBluetoothName.setText(data) saveCheck.setText("저장 됨") saveCheck.setChecked(True) saveCheck.setEnabled(False) except Exception: Messaging('LSP', 'USERNAME 파일이 깨졌습니다.\n다시 생성해주십시오.', 'Information') os.remove("USERNAME") BluetoothSaveBtn = QPushButton("블루투스 연동") Btn_layout = QHBoxLayout() Btn_layout.setContentsMargins(0, 0, 0, 0) Btn_layout.addWidget(BluetoothSaveBtn) if not saveCheck.isEnabled(): deleteFile = QPushButton("모델명 삭제") Btn_layout.addWidget(deleteFile) deleteFile.clicked.connect(lambda: self.deleteModelFile( saveCheck, Btn_layout, 'USERNAME')) Btn_widget = QWidget() Btn_widget.setLayout(Btn_layout) BluetoothSaveBtn.clicked.connect( lambda: BluetoothServer.BluetoothSetting(Btn_widget, saveCheck, userBluetoothName.text())) B_layout.addWidget(howto) BB_layout.addWidget(userBluetoothName) BB_layout.addWidget(saveCheck) B_layout.addLayout(BB_layout) B_layout.addWidget(Btn_widget) groupbox.setLayout(B_layout) label1 = QLabel("블루투스는 원격으로 잠금/해제를 하기 위해 사용됩니다.") layout.addWidget(label1) layout.addWidget(groupbox) MainGroupbox.setLayout(layout) return MainGroupbox
class CheckDemo(QWidget): def __init__(self): super().__init__() self.initGUI() def initGUI(self): self.setGeometry(400, 400, 450, 350) self.setWindowTitle('CheckBox Demonstration') # -- add a checkbox self.check = QCheckBox('This is a checkbox', self) self.check.setTristate(True) # allowing tristate self.check.resize(250, 30) self.check.move(150, 30) self.check.stateChanged.connect(self.dosth) self.check.setIcon(QIcon('MyIcon.png')) # add a button self.btn1 = QPushButton('Reset', self) self.btn1.setToolTip('This button resets the checkbox!') self.btn1.resize(250, 90) self.btn1.move(100, 100) self.btn1.clicked.connect(self.reset) # -- add a button for disabling/enabling self.btn2 = QPushButton('Disable/Enable', self) self.btn2.setToolTip('This button disables/enables the checkbox!') self.btn2.resize(250, 90) self.btn2.move(100, 200) self.btn2.clicked.connect(self.toggle) self.show() def dosth(self): state = self.check.checkState() if state == 0: self.setWindowTitle('The checkbox was unchecked') elif state == 1: self.setWindowTitle('The checkbox was unchanged') elif state == 2: self.setWindowTitle('The checkbox was checked') def reset(self): self.check.setChecked(False) self.setWindowTitle('CheckBox Demonstration') def toggle(self): if self.check.isEnabled(): self.check.setEnabled(False) self.setWindowTitle('The checkbox has been disabled') else: self.check.setEnabled(True) self.setWindowTitle('The checkbox has been enabled')
class InviteCodeWidget(QWidget): def __init__(self, parent=None, tor_available=False): super(InviteCodeWidget, self).__init__() self.parent = parent self.label = QLabel("Enter invite code:") self.label.setFont(Font(14)) p = self.palette() dimmer_grey = BlendedColor( p.windowText().color(), p.window().color() ).name() self.label.setStyleSheet("color: {}".format(dimmer_grey)) self.label.setAlignment(Qt.AlignCenter) self.code_info_text = ( "An <i>invite code</i> is a short combination of numbers and " 'words (like "7-guitarist-revenge" or "9-potato-gremlin") that ' "allows two parties with the same code to establish a one-time " "secure communication channel with each other. In {}, " "invite codes are used to safely share the credentials needed " "to access resources -- for example, allowing another person or " "device to store files on a grid or granting them the ability to " "view and modify a folder.<p>" "Invite codes can only be used once and expire immediately when " "used or cancelled.".format(APP_NAME) ) self.code_info_button = QPushButton() self.code_info_button.setFlat(True) self.code_info_button.setIcon(QIcon(resource("question"))) self.code_info_button.setIconSize(QSize(13, 13)) if sys.platform == "darwin": self.code_info_button.setFixedSize(16, 16) else: self.code_info_button.setFixedSize(13, 13) self.code_info_button.setToolTip(self.code_info_text) self.code_info_button.clicked.connect(self.on_code_info_button_clicked) self.code_info_button.setFocusPolicy(Qt.NoFocus) label_layout = QGridLayout() label_layout.setHorizontalSpacing(6) label_layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, 0), 1, 1) label_layout.addWidget(self.label, 1, 2, Qt.AlignCenter) label_layout.addWidget(self.code_info_button, 1, 3, Qt.AlignLeft) label_layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, 0), 1, 5) self.lineedit = InviteCodeLineEdit(self) self.tor_checkbox = QCheckBox("Connect over the Tor network") if sys.platform == "darwin": # For some reason, the checkbox and pushbutton overlap slightly on # macOS. A space here adds just enough padding to separate them. self.tor_checkbox.setText(self.tor_checkbox.text() + " ") self.tor_checkbox.setStyleSheet("QCheckBox { color: dimgrey }") self.tor_checkbox.setFocusPolicy(Qt.NoFocus) self.tor_checkbox_effect = QGraphicsOpacityEffect() self.tor_checkbox.setGraphicsEffect(self.tor_checkbox_effect) self.tor_checkbox.setAutoFillBackground(True) self.tor_checkbox_animation_in = QPropertyAnimation( self.tor_checkbox_effect, b"opacity" ) self.tor_checkbox_animation_in.setDuration(500) self.tor_checkbox_animation_in.setStartValue(0) self.tor_checkbox_animation_in.setEndValue(1) self.tor_checkbox_animation_out = QPropertyAnimation( self.tor_checkbox_effect, b"opacity" ) self.tor_checkbox_animation_out.setDuration(500) self.tor_checkbox_animation_out.setStartValue(1) self.tor_checkbox_animation_out.setEndValue(0) self.tor_info_text = ( "<i>Tor</i> is an anonymizing network that helps defend against " "network surveillance and traffic analysis. With this checkbox " "enabled, {} will route all traffic corresponding to this " "connection through the Tor network, concealing your geographical " "location from your storage provider and other parties (such as " "any persons with whom you might share folders).<p>" "Using this option requires that Tor already be installed and " "running on your computer and may be slower or less reliable than " "your normal internet connection.<p>" "For more information or to download Tor, please visit " "<a href=https://torproject.org>https://torproject.org</a>".format( APP_NAME ) ) self.tor_info_button = QPushButton() self.tor_info_button.setFlat(True) self.tor_info_button.setIcon(QIcon(resource("question"))) self.tor_info_button.setIconSize(QSize(13, 13)) if sys.platform == "darwin": self.tor_info_button.setFixedSize(16, 16) else: self.tor_info_button.setFixedSize(13, 13) self.tor_info_button.setToolTip(self.tor_info_text) self.tor_info_button.clicked.connect(self.on_tor_info_button_clicked) self.tor_info_button.setFocusPolicy(Qt.NoFocus) self.tor_info_button_effect = QGraphicsOpacityEffect() self.tor_info_button.setGraphicsEffect(self.tor_info_button_effect) self.tor_info_button.setAutoFillBackground(True) self.tor_info_button_animation_in = QPropertyAnimation( self.tor_info_button_effect, b"opacity" ) self.tor_info_button_animation_in.setDuration(500) self.tor_info_button_animation_in.setStartValue(0) self.tor_info_button_animation_in.setEndValue(1) self.tor_info_button_animation_out = QPropertyAnimation( self.tor_info_button_effect, b"opacity" ) self.tor_info_button_animation_out.setDuration(500) self.tor_info_button_animation_out.setStartValue(1) self.tor_info_button_animation_out.setEndValue(0) if tor_available: self.tor_checkbox_effect.setOpacity(1.0) self.tor_info_button_effect.setOpacity(1.0) else: self.tor_checkbox.setEnabled(False) self.tor_checkbox_effect.setOpacity(0.0) self.tor_info_button_effect.setOpacity(0.0) tor_layout = QGridLayout() tor_layout.setHorizontalSpacing(0) tor_layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, 0), 1, 1) tor_layout.addWidget(self.tor_checkbox, 1, 2, Qt.AlignCenter) tor_layout.addWidget(self.tor_info_button, 1, 3, Qt.AlignLeft) tor_layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, 0), 1, 4) layout = QGridLayout(self) layout.addItem(QSpacerItem(0, 0, 0, QSizePolicy.Expanding), 1, 1) layout.addLayout(label_layout, 2, 1) layout.addWidget(self.lineedit, 3, 1) layout.addLayout(tor_layout, 4, 1) layout.addItem(QSpacerItem(0, 0, 0, QSizePolicy.Expanding), 5, 1) self.tor_checkbox.toggled.connect(self.toggle_tor_status) self.maybe_enable_tor_checkbox() @inlineCallbacks def maybe_enable_tor_checkbox(self): tor = yield get_tor(reactor) if tor and not self.tor_checkbox.isEnabled(): self.tor_checkbox.setEnabled(True) self.tor_checkbox_animation_in.start() self.tor_info_button_animation_in.start() elif not tor and self.tor_checkbox.isEnabled(): self.tor_checkbox.setEnabled(False) self.tor_checkbox_animation_out.start() self.tor_info_button_animation_out.start() def toggle_tor_status(self, state): if state: msgbox = QMessageBox(self) msgbox.setIcon(QMessageBox.Warning) title = "Enable Tor?" text = ( "Tor support in {} is currently <i>experimental</i> and may " "contain serious bugs that could jeopardize your anonymity.<p>" "Are you sure you wish to enable Tor for this connection?<br>".format( APP_NAME ) ) if sys.platform == "darwin": msgbox.setText(title) msgbox.setInformativeText(text) else: msgbox.setWindowTitle(title) msgbox.setText(text) checkbox = QCheckBox( "I understand and accept the risks. Enable Tor." ) msgbox.setCheckBox(checkbox) msgbox.setWindowModality(Qt.ApplicationModal) msgbox.exec_() if not checkbox.isChecked(): self.tor_checkbox.setChecked(False) return self.lineedit.status_action.setIcon(self.lineedit.tor_icon) self.lineedit.status_action.setToolTip( "Tor: Enabled\n\n" "This connection will be routed through the Tor network." ) # self.lineedit.setStyleSheet( # "border-width: 1px;" # "border-style: solid;" # "border-color: {0};" # "border-radius: 2px;" # "padding: 2px;" # "color: {0};".format(TOR_DARK_PURPLE)) else: self.lineedit.status_action.setIcon(self.lineedit.blank_icon) self.lineedit.status_action.setToolTip("") # self.lineedit.setStyleSheet("") def on_tor_info_button_clicked(self): msgbox = QMessageBox(self) msgbox.setIconPixmap(self.lineedit.tor_icon.pixmap(64, 64)) if sys.platform == "darwin": msgbox.setText("About Tor") msgbox.setInformativeText(self.tor_info_text) else: msgbox.setWindowTitle("About Tor") msgbox.setText(self.tor_info_text) msgbox.show() def on_code_info_button_clicked(self): msgbox = QMessageBox(self) msgbox.setIcon(QMessageBox.Information) text = ( "{}<p><a href=https://github.com/gridsync/gridsync/blob/master/doc" "s/invite-codes.md>Learn more...</a>".format(self.code_info_text) ) if sys.platform == "darwin": msgbox.setText("About Invite Codes") msgbox.setInformativeText(text) else: msgbox.setWindowTitle("About Invite Codes") msgbox.setText(text) msgbox.show()
class PostProcessGUI(QDialog): def __init__(self, parent_window=None, _is_dialog=False): super().__init__(parent=parent_window) self._is_dialog = _is_dialog self.initUI() def initUI(self): input_v_layout = QVBoxLayout() input_v_layout.setAlignment(Qt.AlignTop) input_v_layout.setContentsMargins(0, 0, 0, 0) # TODO add a set of parameters there for the post process self.groupBox_post_process = QGroupBox( 'Refine segmentation/Create a binary mask', objectName='groupBox_post_process') self.groupBox_post_process.setCheckable(True) self.groupBox_post_process.setChecked(True) # self.groupBox_post_process.setEnabled(True) group_box_post_process_parameters_layout = QGridLayout() group_box_post_process_parameters_layout.setAlignment(Qt.AlignTop) group_box_post_process_parameters_layout.setHorizontalSpacing(3) group_box_post_process_parameters_layout.setVerticalSpacing(3) # do a radio dialog with all the stuff needed... # test all post_process_method_selection_label = QLabel('Post process method') # (or bond score for pretrained model) post_process_method_selection_label.setStyleSheet("QLabel { color : red; }") self.post_process_method_selection = QComboBox(objectName='post_process_method_selection') self.post_process_method_selection.addItem('Default (Slow/robust) (EPySeg pre-trained model only!)') self.post_process_method_selection.addItem('Fast (May contain more errors) (EPySeg pre-trained model only!)') self.post_process_method_selection.addItem('Old method (Sometimes better than default) (EPySeg pre-trained model only!)') self.post_process_method_selection.addItem('Simply binarize output using threshold') self.post_process_method_selection.addItem('Keep first channel only') self.post_process_method_selection.addItem('None (Raw model output)') self.post_process_method_selection.currentTextChanged.connect(self._post_process_method_changed) group_box_post_process_parameters_layout.addWidget(post_process_method_selection_label, 0, 0, 1, 1) group_box_post_process_parameters_layout.addWidget(self.post_process_method_selection, 0, 1, 1, 3) # TODO --> always make this relative threshold_label = QLabel( 'Threshold: (in case of over/under segmentation, please increase/decrease, respectively)') # (or bond score for pretrained model) threshold_label.setStyleSheet("QLabel { color : red; }") self.threshold_bond_or_binarisation = QDoubleSpinBox(objectName='threshold_bond_or_binarisation') self.threshold_bond_or_binarisation.setSingleStep(0.01) self.threshold_bond_or_binarisation.setRange(0.01, 1) # 100_000 makes no sense (oom) but anyway self.threshold_bond_or_binarisation.setValue(0.42) # probably should be 1 to 3 depending on the tissue self.threshold_bond_or_binarisation.setEnabled(False) # threshold_hint = QLabel() # (or bond score for pretrained model) self.autothreshold = QCheckBox("Auto",objectName='autothreshold') self.autothreshold.setChecked(True) self.autothreshold.stateChanged.connect(self._threshold_changed) group_box_post_process_parameters_layout.addWidget(threshold_label, 1, 0, 1, 2) group_box_post_process_parameters_layout.addWidget(self.threshold_bond_or_binarisation, 1, 2) group_box_post_process_parameters_layout.addWidget(self.autothreshold, 1, 3) # groupBox_post_process_parameters_layout.addWidget(threshold_hint, 0, 3) filter_by_size_label = QLabel('Further filter segmentation by size:') self.filter_by_cell_size_combo = QComboBox(objectName='filter_by_cell_size_combo') self.filter_by_cell_size_combo.addItem('None (quite often the best choice)') self.filter_by_cell_size_combo.addItem('Local median (slow/very good) divided by') self.filter_by_cell_size_combo.addItem('Cells below Average area (global) divided by') self.filter_by_cell_size_combo.addItem('Global median divided by') self.filter_by_cell_size_combo.addItem('Cells below size (in px)') # add a listener to model Architecture self.filter_by_cell_size_combo.currentTextChanged.connect(self._filter_changed) group_box_post_process_parameters_layout.addWidget(filter_by_size_label, 2, 0) group_box_post_process_parameters_layout.addWidget(self.filter_by_cell_size_combo, 2, 1, 1, 2) self.avg_area_division_or_size_spinbox = QSpinBox(objectName='avg_area_division_or_size_spinbox') self.avg_area_division_or_size_spinbox.setSingleStep(1) self.avg_area_division_or_size_spinbox.setRange(1, 10000000) # 100_000 makes no sense (oom) but anyway self.avg_area_division_or_size_spinbox.setValue(2) # probably should be 1 to 3 depending on the tissue self.avg_area_division_or_size_spinbox.setEnabled(False) group_box_post_process_parameters_layout.addWidget(self.avg_area_division_or_size_spinbox, 2, 3) self.prevent_exclusion_of_too_many_cells_together = QCheckBox('Do not exclude groups bigger than', objectName='prevent_exclusion_of_too_many_cells_together') self.prevent_exclusion_of_too_many_cells_together.setChecked(False) self.prevent_exclusion_of_too_many_cells_together.setEnabled(False) # max_nb_of_cells_to_be_excluded_together_label = QLabel('Group size') self.max_nb_of_cells_to_be_excluded_together_spinbox = QSpinBox(objectName='max_nb_of_cells_to_be_excluded_together_spinbox') self.max_nb_of_cells_to_be_excluded_together_spinbox.setSingleStep(1) self.max_nb_of_cells_to_be_excluded_together_spinbox.setRange(1, 10000000) # max makes no sense self.max_nb_of_cells_to_be_excluded_together_spinbox.setValue( 3) # default should be 2 or 3 because seg is quite good so above makes no sense self.max_nb_of_cells_to_be_excluded_together_spinbox.setEnabled(False) cells_text_labels = QLabel('cells') self.restore_secure_cells = QCheckBox('Restore most likely cells',objectName='restore_secure_cells') self.restore_secure_cells.setChecked(False) self.restore_secure_cells.setEnabled(False) # help for post process # help_ico = QIcon.fromTheme('help-contents') self.help_button_postproc = QPushButton('?', None) bt_width = self.help_button_postproc.fontMetrics().boundingRect(self.help_button_postproc.text()).width() + 7 self.help_button_postproc.setMaximumWidth(bt_width * 2) self.help_button_postproc.clicked.connect(self.show_tip) group_box_post_process_parameters_layout.addWidget(self.restore_secure_cells, 3, 0) group_box_post_process_parameters_layout.addWidget(self.prevent_exclusion_of_too_many_cells_together, 3, 1) group_box_post_process_parameters_layout.addWidget(self.max_nb_of_cells_to_be_excluded_together_spinbox, 3, 2) group_box_post_process_parameters_layout.addWidget(cells_text_labels, 3, 3) # TODO --> improve layout to make help button smaller group_box_post_process_parameters_layout.addWidget(self.help_button_postproc, 0, 5, 3, 1) self.groupBox_post_process.setLayout(group_box_post_process_parameters_layout) input_v_layout.addWidget(self.groupBox_post_process) self.setLayout(input_v_layout) if self._is_dialog: # OK and Cancel buttons self.buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, QtCore.Qt.Horizontal, self) self.buttons.accepted.connect(self.accept) self.buttons.rejected.connect(self.reject) self.layout().addWidget(self.buttons) def _threshold_changed(self): self.threshold_bond_or_binarisation.setEnabled(not self.autothreshold.isChecked()) # self.post_process_method_selection.addItem('Default (Slow/robust)') # self.post_process_method_selection.addItem('Fast (May contain more errors)') # self.post_process_method_selection.addItem('Old method (Less constant than default but sometimes better)') # self.post_process_method_selection.addItem('Simply binarize output using threshold') # self.post_process_method_selection.addItem('None (Raw model output)') def _post_process_method_changed(self): text = self.post_process_method_selection.currentText().lower() if 'none' in text or 'first' in text: self.set_threshold_enabled(False) self.set_safety_parameters(False) self.set_filter_by_size_enabled(False) elif 'simply' in text: self.set_threshold_enabled(True) self.set_safety_parameters(False) self.set_filter_by_size_enabled(False) elif 'old' in text: self.set_threshold_enabled(False) self.set_safety_parameters(True) self.set_filter_by_size_enabled(True) else: self.set_threshold_enabled(True) self.set_safety_parameters(False) self.set_filter_by_size_enabled(True) def set_filter_by_size_enabled(self, bool): if bool is False: self.filter_by_cell_size_combo.setEnabled(False) self.avg_area_division_or_size_spinbox.setEnabled(False) else: self.filter_by_cell_size_combo.setEnabled(True) self.avg_area_division_or_size_spinbox.setEnabled(True) def set_threshold_enabled(self, bool): if bool is False: self.autothreshold.setEnabled(False) self.threshold_bond_or_binarisation.setEnabled(False) else: self.autothreshold.setEnabled(True) self._threshold_changed() def set_safety_parameters(self, bool): self._filter_changed() def show_tip(self): QToolTip.showText(self.sender().mapToGlobal(QPoint(30, 30)), markdown_file_to_html('refine_segmentation.md')) def isChecked(self): return self.groupBox_post_process.isChecked() def setChecked(self, bool): return self.groupBox_post_process.setChecked(bool) def _filter_changed(self): current_filter = self.filter_by_cell_size_combo.currentText().lower() current_mode = self.post_process_method_selection.currentText().lower() if 'one' in current_filter: self.avg_area_division_or_size_spinbox.setEnabled(False) self.max_nb_of_cells_to_be_excluded_together_spinbox.setEnabled(False) self.prevent_exclusion_of_too_many_cells_together.setEnabled(False) self.restore_secure_cells.setEnabled(False) else: self.avg_area_division_or_size_spinbox.setEnabled(True) self.max_nb_of_cells_to_be_excluded_together_spinbox.setEnabled(True) self.prevent_exclusion_of_too_many_cells_together.setEnabled(True) self.restore_secure_cells.setEnabled(True) if 'divided' in current_filter: self.avg_area_division_or_size_spinbox.setValue(2) else: self.avg_area_division_or_size_spinbox.setValue(300) if not 'old' in current_mode: self.max_nb_of_cells_to_be_excluded_together_spinbox.setEnabled(False) self.prevent_exclusion_of_too_many_cells_together.setEnabled(False) self.restore_secure_cells.setEnabled(False) def _get_post_process_filter(self): current_filter = self.filter_by_cell_size_combo.currentText().lower() if 'one' in current_filter or not self.filter_by_cell_size_combo.isEnabled(): return None if 'size' in current_filter: return self.avg_area_division_or_size_spinbox.value() if 'verage' in current_filter: return 'avg' if 'local' in current_filter: return 'local' if 'global' in current_filter: return 'global median' def get_parameters_directly(self): '''Get the parameters for model training Returns ------- dict containing post processing parameters ''' self.post_process_parameters = {} post_proc_method = self.post_process_method_selection.currentText().lower() if 'none' in post_proc_method: self.post_process_parameters['post_process_algorithm'] = None else: self.post_process_parameters['post_process_algorithm'] = post_proc_method self.post_process_parameters['filter'] = self._get_post_process_filter() if self.threshold_bond_or_binarisation.isEnabled(): self.post_process_parameters['threshold'] = self.threshold_bond_or_binarisation.value() if self.autothreshold.isEnabled() and self.autothreshold.isChecked(): self.post_process_parameters[ 'threshold'] = None # None means autothrehsold # maybe add more options some day if self.avg_area_division_or_size_spinbox.isEnabled(): self.post_process_parameters['correction_factor'] = self.avg_area_division_or_size_spinbox.value() if self.restore_secure_cells.isEnabled(): self.post_process_parameters['restore_safe_cells'] = self.restore_secure_cells.isChecked() if self.max_nb_of_cells_to_be_excluded_together_spinbox.isEnabled(): self.post_process_parameters[ 'cutoff_cell_fusion'] = self.max_nb_of_cells_to_be_excluded_together_spinbox.value() if self.prevent_exclusion_of_too_many_cells_together.isChecked() else None if 'old' in self.post_process_method_selection.currentText().lower(): # just for max use that --> maybe do this as an option some day self.post_process_parameters['hq_predictions'] = 'max' return self.post_process_parameters def get_parameters(self): return (self.get_parameters_directly()) @staticmethod def getDataAndParameters(parent_window=None, _is_dialog=False): # get all the params for augmentation dialog = PostProcessGUI(parent_window=parent_window, _is_dialog=_is_dialog) result = dialog.exec_() parameters = dialog.get_parameters() return (parameters, result == QDialog.Accepted)
class ScriptsMenu(QWidget): def interface_check(function): def wrapper(self): function(self) try: self.on_block() except: return wrapper return wrapper def __init__(self): super().__init__() self.layout = QGridLayout() self.setLayout(self.layout) row_hight = 30 margins = self.layout.contentsMargins() margins.setTop(row_hight) margins.setRight(20) self.layout.setContentsMargins(margins) # Initializing GUI elements self.settings_label = QLabel('Settings') self.platform_var_list = QComboBox() self.thread_var_list = QComboBox() self.intel64 = QCheckBox('Intel 64') self.IA32 = QCheckBox('IA32') self.TL = QCheckBox('Threading layer') self.omp = QRadioButton('OpenMP') self.tbb = QRadioButton('TBB') self.lib_name = QLineEdit() self.functions_list = QListWidget() self.save_build_script = QPushButton('Save build script') self.functions_names = [] self.status_receiver = None self.lib_name.setPlaceholderText('Library name...') # Preparing elements by giving initial values and etc self.settings_label.setAlignment(Qt.AlignBottom) self.save_build_script.setDisabled(True) self.save_build_script.clicked.connect(self.on_save_build_script) self.IA32.clicked.connect(self.on_block) self.intel64.clicked.connect(self.on_block) self.TL.clicked.connect(self.set_tl) self.lib_name.textEdited.connect(self.on_block) self.platform_var_list.currentIndexChanged.connect(self.on_target_system_selection) # Setting all widgets in their places self.layout.addWidget(self.settings_label, 0, 0) self.layout.addWidget(self.TL, 1, 0) self.layout.addWidget(self.omp, 2, 0) self.layout.addWidget(self.tbb, 3, 0) self.layout.addWidget(self.intel64, 2, 1) self.layout.addWidget(self.IA32, 3, 1) self.layout.addWidget(self.platform_var_list, 2, 2, 1, 2) self.layout.addWidget(self.thread_var_list, 3, 2, 1, 2) self.layout.addWidget(self.lib_name, 4, 0, 1, 4) self.layout.addWidget(self.functions_list, 5, 0, 1, 4) self.layout.addWidget(self.save_build_script, 6, 0, 1, 4) self.settings_label.setFixedHeight(row_hight) self.TL.setFixedHeight(row_hight) self.platform_var_list.setFixedHeight(row_hight) self.thread_var_list.setFixedHeight(row_hight) self.__post_check() def set_configs(self, package): self.check_configs(package) self.TL.setChecked(settings.CONFIGS[package]['TL']) self.omp.setChecked(settings.CONFIGS[package]['OpenMP']) self.tbb.setChecked(settings.CONFIGS[package]['TBB']) self.set_tl() self.intel64.setChecked(settings.CONFIGS[package]['intel64']) self.IA32.setChecked(settings.CONFIGS[package]['IA32']) if self.intel64.isEnabled(): if not self.intel64.isChecked() and not self.IA32.isChecked(): self.intel64.setChecked(True) elif self.IA32.isEnabled(): self.IA32.setChecked(True) self.thread_var_list.setCurrentText(utils.MULTI_THREADED) if settings.CONFIGS[package]['Multi-threaded'] \ else self.thread_var_list.setCurrentText(utils.SINGLE_THREADED) self.functions_names = settings.CONFIGS[package]['functions_list'] def check_configs(self, package): self.intel64_libs_path = self.parent.source.path_to_libs[package][utils.INTEL64] self.ia32_libs_path = self.parent.source.path_to_libs[package][utils.IA32] if self.intel64_libs_path: self.intel64.setEnabled(True) else: settings.CONFIGS[package]['intel64'] = False self.intel64.setDisabled(True) if self.ia32_libs_path: self.IA32.setEnabled(True) else: settings.CONFIGS[package]['IA32'] = False self.IA32.setDisabled(True) if self.check_dir('tl'): self.TL.setEnabled(True) else: settings.CONFIGS[package]['TL'] = False self.TL.setDisabled(True) self.thread_var_list.clear() if self.check_dir('threaded'): self.thread_var_list.addItems([utils.SINGLE_THREADED, utils.MULTI_THREADED]) else: self.thread_var_list.addItem(utils.SINGLE_THREADED) settings.CONFIGS[package]['Multi-threaded'] = False def check_dir(self, dir): return os.path.exists(os.path.join(self.intel64_libs_path, dir)) or \ os.path.exists(os.path.join(self.ia32_libs_path, dir)) def get_configs(self, package): if self.TL.isEnabled(): settings.CONFIGS[package]['TL'] = self.TL.isChecked() if settings.CONFIGS[package]['TL']: settings.CONFIGS[package]['OpenMP'] = self.omp.isChecked() settings.CONFIGS[package]['TBB'] = self.tbb.isChecked() settings.CONFIGS[package]['intel64'] = self.intel64.isChecked() settings.CONFIGS[package]['IA32'] = self.IA32.isChecked() settings.CONFIGS[package]['Multi-threaded'] = (self.thread_var_list.currentText() == utils.MULTI_THREADED) settings.CONFIGS[package]['functions_list'] = self.functions_names def set_status_output(self, status_receiver): self.status_receiver = status_receiver def __get_interface_state(self): return {settings.PACKAGE: self.parent.source.ipp.isEnabled() or self.parent.source.ippcp.isEnabled(), settings.PLATFORM: self.IA32.isChecked() or self.intel64.isChecked(), settings.LIB_NAME: bool(self.lib_name.text()), settings.FUNCTIONS: bool(self.functions_names), settings.ANDK: not ((not bool(utils.ANDROID_NDK_PATH)) and self.platform_var_list.currentText() == utils.ANDROID) } def on_item_selected(self, item): self.functions_list.setCurrentItem(item) def on_block(self): autobuild_requrements = settings.AUTOBUILD_BUTTON_RULES script_requrements = settings.SCRIPT_BUTTON_GENERATOR_RULES interface_state = self.__get_interface_state() if autobuild_requrements == interface_state: self.parent.set_auto_build_disabled(False) self.status_receiver.showMessage("Ready to build custom library") else: self.parent.set_auto_build_disabled(True) differences = dict(autobuild_requrements.items() - interface_state.items()) self.status_receiver.showMessage("Set " + sorted(differences, key=len)[0]) if script_requrements == {i: interface_state.get(i) for i in script_requrements.keys()}: self.save_build_script.setDisabled(False) else: self.save_build_script.setDisabled(True) def set_tl(self): if self.TL.isEnabled(): self.set_threading_layer_enabled(self.TL.isChecked()) self.parent.source.tl_selected = self.TL.isChecked() else: self.set_threading_layer_enabled(False) self.parent.source.tl_selected = False if self.parent.source.ipp.isChecked(): self.parent.source.show_menu(utils.IPP) if not self.omp.isChecked() and not self.tbb.isChecked(): if self.omp.isEnabled(): self.omp.setChecked(True) elif self.tbb.isEnabled(): self.tbb.setChecked(True) def set_threading_layer_enabled(self, bool): self.omp.setEnabled(bool) if self.check_dir(os.path.join('tl', 'openmp')) else self.omp.setDisabled(True) self.tbb.setEnabled(bool) if self.check_dir(os.path.join('tl', 'tbb')) else self.tbb.setDisabled(True) def on_save_build_script(self): library_path = QFileDialog.getExistingDirectory(self, 'Select a folder') if library_path == '': return host_system = utils.HOST_SYSTEM target_system = self.platform_var_list.currentText() functions = self.functions_names library_name = self.lib_name.text() threading = self.thread_var_list.currentText() == 'Multi-threaded' threading_layer_type = self.parent.get_treading_layer_type() if self.parent.source.ipp.isChecked(): package = utils.IPP root = utils.IPPROOT else: package = utils.IPPCP root = utils.IPPCRYPTOROOT os.environ[root] = settings.CONFIGS[package]['Path'] if self.IA32.isChecked(): generate_script(package, host_system, target_system, functions, library_path, library_name, utils.IA32, threading, threading_layer_type, ) if self.intel64.isChecked(): generate_script(package, host_system, target_system, functions, library_path, library_name, utils.INTEL64, threading, threading_layer_type) QMessageBox.about(self, 'Success', 'Generation completed!') @interface_check def on_target_system_selection(self): system = self.platform_var_list.currentText() if utils.ONLY_THREADABLE[system]: self.thread_var_list.setCurrentIndex(1) self.thread_var_list.setDisabled(True) else: self.thread_var_list.setDisabled(False) if not utils.SUPPORTED_ARCHITECTURES[system][utils.IA32]: self.IA32.setCheckState(Qt.Unchecked) self.IA32.setDisabled(True) else: self.IA32.setDisabled(False) if not utils.SUPPORTED_ARCHITECTURES[system][utils.INTEL64]: self.intel64.setCheckState(Qt.Unchecked) self.intel64.setDisabled(True) else: self.intel64.setDisabled(False) def add_items(self, items): """ Sorts and adds items to list view :param items: list of strings """ self.functions_list.clear() if items: items.sort() self.functions_list.addItems(items) self.functions_list.setCurrentItem(self.functions_list.item(0)) self.functions_list.repaint() def add_item(self, function): """ Adds new function to required list :param domain: domain of function :param function: name if function """ self.functions_names.append(function) self.add_items(self.functions_names) def remove_item(self): """ Removes function from required list """ if self.functions_list.currentItem() is None: return None lib = self.functions_list.currentItem().text() self.functions_names.remove(lib) self.add_items(self.functions_names) return lib def __post_check(self): """ Fills platforms combo box according to host system """ if utils.HOST_SYSTEM == utils.LINUX: self.platform_var_list.addItem(utils.LINUX) elif utils.HOST_SYSTEM == utils.MACOSX: self.platform_var_list.addItem(utils.MACOSX) elif utils.HOST_SYSTEM == utils.WINDOWS: self.platform_var_list.addItem(utils.WINDOWS)
class InfoPanel(QWidget): def __init__(self): super().__init__() self.timer = QTimer() self.measurer = MeasureService(simulation_mode=True) self.temperature_history = list() self.humidity_history = list() self.pressure_history = list() self.timestamp_history = list() self.vva_temp_flag = False self.vva_humi_flag = False self.data_num = 0 self.initUI() def initUI(self): self.setWindowTitle("Weather controller v1.1") self.setFixedSize(900, 500) self.label_general = QLabel("General settings") self.date_value = QLabel("") self.autoupdate = QCheckBox("Auto update") self.imitation = QCheckBox("Imitation") self.imitation.setChecked(True) self.label_min_t = QLabel("min") self.label_min_t.setAlignment(QtCore.Qt.AlignRight) self.label_min_h = QLabel("min") self.label_min_h.setAlignment(QtCore.Qt.AlignRight) self.label_max_t = QLabel("max") self.label_max_t.setAlignment(QtCore.Qt.AlignRight) self.label_max_h = QLabel("max") self.label_max_h.setAlignment(QtCore.Qt.AlignRight) self.label_interval = QLabel("Update interval (ms):") self.interval_line = QSpinBox() self.interval_line.setRange(0, 10000) self.interval_line.setValue(500) self.interval_line.setMaximumWidth(100) self.label_vva_temp = QLabel("Temperature VVA (C):") self.checkbox_vva_temp = QCheckBox() self.vva_temp_min = QSpinBox() self.vva_temp_min.setEnabled(False) self.vva_temp_max = QSpinBox() self.vva_temp_max.setEnabled(False) self.vva_temp_min.setMinimum(-273) self.vva_temp_max.setMinimum(-273) self.vva_temp_min.setValue(20) self.vva_temp_max.setValue(30) self.vva_temp_min.setMaximumWidth(100) self.vva_temp_max.setMaximumWidth(100) self.label_vva_humi = QLabel("Humidity VVA (%):") self.checkbox_vva_humi = QCheckBox() self.vva_humi_min = QSpinBox() self.vva_humi_min.setEnabled(False) self.vva_humi_max = QSpinBox() self.vva_humi_max.setEnabled(False) self.vva_humi_min.setMinimum(0) self.vva_humi_max.setMinimum(0) self.vva_humi_min.setMaximum(100) self.vva_humi_max.setMaximum(100) self.vva_humi_min.setValue(50) self.vva_humi_max.setValue(90) self.vva_humi_min.setMaximumWidth(100) self.vva_humi_max.setMaximumWidth(100) self.button_set_vva = QPushButton("Set VVA") self.button_set_vva.setEnabled(False) self.button_get_data = QPushButton("Get data") self.button_clear_plot = QPushButton("Clear plot") self.label_temperature = QLabel("Temperature (C):") self.label_humidity = QLabel("Humidity (%):") self.label_pressure = QLabel("Pressure (mmHg):") self.value_temperature = QLabel("N/A") self.value_humidity = QLabel("N/A") self.value_pressure = QLabel("N/A") self.plot_temperature = PlotWidget(labels={'left': 'Temperature, C'}, background=None) self.plot_humidity = PlotWidget(labels={'left': 'Humidity, %'}, background=None) self.plot_pressure = PlotWidget(labels={'left': 'Pressure, mmHg'}, background=None) self.plot_temperature.showGrid(x=True, y=True) self.plot_humidity.showGrid(x=True, y=True) self.plot_pressure.showGrid(x=True, y=True) self.curve_temperature = self.plot_temperature.plot(pen='b') self.curve_humidity = self.plot_humidity.plot(pen='b') self.curve_pressure = self.plot_pressure.plot(pen='b') self.curve_avg_temperature = self.plot_temperature.plot(pen='m') self.curve_avg_humidity = self.plot_humidity.plot(pen='m') self.curve_avg_pressure = self.plot_pressure.plot(pen='m') self.curve_min_temperature = self.plot_temperature.plot(pen='r') self.curve_min_humidity = self.plot_humidity.plot(pen='r') self.curve_max_temperature = self.plot_temperature.plot(pen='r') self.curve_max_humidity = self.plot_humidity.plot(pen='r') self.alarm_area = QTextEdit() self.alarm_area.setDisabled(True) self.button_get_data.clicked.connect(self.button_get_data_clicked) self.button_clear_plot.clicked.connect(self.button_clear_plot_clicked) self.button_set_vva.clicked.connect(self.button_set_vva_clicked) self.imitation.clicked.connect(self.imitation_changed) self.autoupdate.clicked.connect(self.auto_update_changed) self.checkbox_vva_temp.clicked.connect(self.vva_temp_changed) self.checkbox_vva_humi.clicked.connect(self.vva_humi_changed) self.timer.timeout.connect(self.get_data) main_layout = QGridLayout() main_layout.setAlignment(QtCore.Qt.AlignTop) main_layout.addWidget(self.label_general, 0, 0) main_layout.addWidget(self.date_value, 0, 1, 1, 2) main_layout.addWidget(self.autoupdate, 1, 0) main_layout.addWidget(self.imitation, 1, 1) main_layout.addWidget(self.label_interval, 2, 0, 1, 2) main_layout.addWidget(self.interval_line, 2, 2) main_layout.addWidget(self.label_vva_temp, 3, 0, 1, 2) main_layout.addWidget(self.checkbox_vva_temp, 3, 2) main_layout.addWidget(self.label_min_t, 4, 1) main_layout.addWidget(self.vva_temp_min, 4, 2) main_layout.addWidget(self.label_max_t, 5, 1) main_layout.addWidget(self.vva_temp_max, 5, 2) main_layout.addWidget(self.label_vva_humi, 6, 0, 1, 2) main_layout.addWidget(self.checkbox_vva_humi, 6, 2) main_layout.addWidget(self.label_min_h, 7, 1) main_layout.addWidget(self.vva_humi_min, 7, 2) main_layout.addWidget(self.label_max_h, 8, 1) main_layout.addWidget(self.vva_humi_max, 8, 2) main_layout.addWidget(self.button_set_vva, 9, 0) main_layout.addWidget(self.button_get_data, 9, 1) main_layout.addWidget(self.button_clear_plot, 9, 2) main_layout.addWidget(self.label_temperature, 10, 0) main_layout.addWidget(self.value_temperature, 10, 1, 1, 2) main_layout.addWidget(self.label_humidity, 11, 0) main_layout.addWidget(self.value_humidity, 11, 1, 1, 2) main_layout.addWidget(self.label_pressure, 12, 0) main_layout.addWidget(self.value_pressure, 12, 1, 1, 2) main_layout.addWidget(self.alarm_area, 13, 0, 2, 3) plot_layout = QVBoxLayout() plot_layout.addWidget(self.plot_temperature) plot_layout.addWidget(self.plot_humidity) plot_layout.addWidget(self.plot_pressure) g_layout = QHBoxLayout() g_layout.addLayout(main_layout) g_layout.addLayout(plot_layout) self.setLayout(g_layout) self.show() def auto_update_changed(self): self.timer.start(int(self.interval_line.text( ))) if self.autoupdate.isChecked() else self.timer.stop() self.button_get_data.setEnabled(not self.button_get_data.isEnabled()) self.button_clear_plot.setEnabled( not self.button_clear_plot.isEnabled()) self.interval_line.setEnabled(not self.interval_line.isEnabled()) self.imitation.setEnabled(not self.imitation.isEnabled()) def button_get_data_clicked(self): self.get_data() def button_clear_plot_clicked(self): self.temperature_history.clear() self.humidity_history.clear() self.pressure_history.clear() self.timestamp_history.clear() self.update_main_lines() self.clear_avg_lines() self.clear_vva_temp() self.clear_vva_humi() def clear_avg_lines(self): self.curve_avg_temperature.setData([], []) self.curve_avg_humidity.setData([], []) self.curve_avg_pressure.setData([], []) def clear_vva_temp(self): self.curve_min_temperature.setData([], []) self.curve_max_temperature.setData([], []) def clear_vva_humi(self): self.curve_min_humidity.setData([], []) self.curve_max_humidity.setData([], []) def button_set_vva_clicked(self): if self.checkbox_vva_temp.isChecked() and self.vva_temp_is_valid(): self.vva_temp_flag = True if self.checkbox_vva_humi.isChecked() and self.vva_humi_is_valid(): self.vva_humi_flag = True def vva_temp_is_valid(self): return int(self.vva_temp_min.text()) <= int(self.vva_temp_max.text()) def vva_humi_is_valid(self): return int(self.vva_humi_min.text()) <= int(self.vva_humi_max.text()) def get_data(self): data = self.measurer.measure() if data.is_empty(): return time = dt.datetime.now() self.date_value.setText(str(time)) self.value_temperature.setText(str(data.temperature)) self.value_humidity.setText(str(data.humidity)) self.value_pressure.setText(str(data.pressure)) self.analyse_data(data) self.fill_plot_data(data) def analyse_data(self, data): if self.vva_temp_flag and data.temperature > float( self.vva_temp_max.text()): self.alarm_area.setText("TEMP is higher than top of VVA!\n" + self.alarm_area.toPlainText()) if self.vva_temp_flag and data.temperature < float( self.vva_temp_min.text()): self.alarm_area.setText("TEMP is lower than bottom of VVA!\n" + self.alarm_area.toPlainText()) if self.vva_humi_flag and data.humidity > float( self.vva_humi_max.text()): self.alarm_area.setText("HUMI is higher than top of VVA!\n" + self.alarm_area.toPlainText()) if self.vva_humi_flag and data.humidity < float( self.vva_humi_min.text()): self.alarm_area.setText("HUMI is lower than bottom of VVA!\n" + self.alarm_area.toPlainText()) def fill_plot_data(self, data): if len(self.timestamp_history) >= 50: self.temperature_history.pop(0) self.humidity_history.pop(0) self.pressure_history.pop(0) self.timestamp_history.pop(0) self.update_data(data) self.update_main_lines() self.update_avg_lines() if self.vva_temp_flag: self.update_vva_temp() if self.vva_humi_flag: self.update_vva_humi() def update_data(self, data): self.temperature_history.append(float(data.temperature)) self.humidity_history.append(float(data.humidity)) self.pressure_history.append(float(data.pressure)) self.timestamp_history.append(self.data_num) self.data_num += 1 def update_main_lines(self): self.curve_temperature.setData(self.timestamp_history, self.temperature_history) self.curve_humidity.setData(self.timestamp_history, self.humidity_history) self.curve_pressure.setData(self.timestamp_history, self.pressure_history) def update_avg_lines(self): self.curve_avg_temperature.setData( [min(self.timestamp_history), max(self.timestamp_history)], [ round(float(mean(self.temperature_history)), 2), round(float(mean(self.temperature_history)), 2) ]) self.curve_avg_humidity.setData( [min(self.timestamp_history), max(self.timestamp_history)], [mean(self.humidity_history), mean(self.humidity_history)]) self.curve_avg_pressure.setData( [min(self.timestamp_history), max(self.timestamp_history)], [mean(self.pressure_history), mean(self.pressure_history)]) def update_vva_temp(self): self.curve_min_temperature.setData( [min(self.timestamp_history), max(self.timestamp_history)], [float(self.vva_temp_min.text()), float(self.vva_temp_min.text())]) self.curve_max_temperature.setData( [min(self.timestamp_history), max(self.timestamp_history)], [float(self.vva_temp_max.text()), float(self.vva_temp_max.text())]) def update_vva_humi(self): self.curve_min_humidity.setData( [min(self.timestamp_history), max(self.timestamp_history)], [float(self.vva_humi_min.text()), float(self.vva_humi_min.text())]) self.curve_max_humidity.setData( [min(self.timestamp_history), max(self.timestamp_history)], [float(self.vva_humi_max.text()), float(self.vva_humi_max.text())]) def update_vva_temp(self): self.curve_min_temperature.setData( [min(self.timestamp_history), max(self.timestamp_history)], [float(self.vva_temp_min.text()), float(self.vva_temp_min.text())]) self.curve_max_temperature.setData( [min(self.timestamp_history), max(self.timestamp_history)], [float(self.vva_temp_max.text()), float(self.vva_temp_max.text())]) def update_vva_humi(self): self.curve_min_humidity.setData( [min(self.timestamp_history), max(self.timestamp_history)], [float(self.vva_humi_min.text()), float(self.vva_humi_min.text())]) self.curve_max_humidity.setData( [min(self.timestamp_history), max(self.timestamp_history)], [float(self.vva_humi_max.text()), float(self.vva_humi_max.text())]) def imitation_changed(self): self.measurer.set_simulation_mode(self.imitation.isChecked()) def vva_temp_changed(self): self.vva_temp_min.setEnabled(not self.vva_temp_min.isEnabled()) self.vva_temp_max.setEnabled(not self.vva_temp_max.isEnabled()) self.button_set_vva.setEnabled(self.checkbox_vva_temp.isChecked() or self.checkbox_vva_humi.isChecked()) if not self.checkbox_vva_temp.isChecked(): self.vva_temp_flag = False self.clear_vva_temp() def vva_humi_changed(self): self.vva_humi_min.setEnabled(not self.vva_humi_min.isEnabled()) self.vva_humi_max.setEnabled(not self.vva_humi_max.isEnabled()) self.button_set_vva.setEnabled(self.checkbox_vva_temp.isChecked() or self.checkbox_vva_humi.isChecked()) if not self.checkbox_vva_humi.isChecked(): self.vva_humi_flag = False self.clear_vva_humi()
class CheckBoxEdit(QWidget): """ Widget with centered checkbox. """ def __init__(self, parent): super(CheckBoxEdit, self).__init__(parent) self.__editor = QCheckBox(self) layout = QHBoxLayout(self) layout.addWidget(self.__editor, 0, Qt.AlignCenter) layout.setContentsMargins(1, 1, 1, 1) self.setAutoFillBackground(True) def set_property(self, name: str, value: QVariant): """ Sets property. :param name: Property's name. :param value: New Value. """ self.__editor.setProperty(name, value) Tools.write_verbose_class_method_name(self, CheckBoxEdit.set_property, name, str(value.value())) def get_property(self, name: str) -> QVariant: """ Returns property's value. :param name: Property's name. :return: Value. """ result = self.__editor.property(name) Tools.write_verbose_class_method_name(self, CheckBoxEdit.get_property, name, str(result)) return result @property def enabled(self): """ Returns whether editor is enabled. :return: True if editor is enabled, otherwise False. """ result = self.__editor.isEnabled() Tools.write_verbose_class_method_name(self, "enabled", "get_enabled", str(result)) return result @enabled.setter def enabled(self, value: bool): """ Sets editor is enabled. :param value: New value. """ self.__editor.setEnabled(value) Tools.write_verbose_class_method_name(self, "enabled", "set_enabled", str(value)) @property def checked(self): """ Returns whether editor is checked. :return: True if editor is checked, otherwise False. """ result = self.__editor.isChecked() Tools.write_verbose_class_method_name(self, "checked", "get_checked", str(result)) return result @checked.setter def checked(self, value: bool): """ Sets editor is checked. :param value: New value. """ self.__editor.setChecked(value) Tools.write_verbose_class_method_name(self, "checked", "set_checked", str(value)) @property def state_changed(self): """ Returns state changed signal. :return: Signal. """ return self.__editor.stateChanged
class SimulationConfig(GenericInterfaceConfigWidget): """ Widget allowing to set up the simulation parameters """ simuModeChanged = pyqtSignal(bool) def __init__(self, parent=None): """ Initialize the class by creating the different user entries @param parent: parent of the widget """ super(SimulationConfig, self).__init__("Simulation parameters", parent=parent) self.initial_checked = True # Configuration of the simulation self.configuration = SIMU_CONFIG # By default it is not valid self.is_config_valid = False self.initialize_content() self.connect_update() def initialize_content(self): """ Create and add the user entries allowing to set up the simulation mode """ # Add a check box to specify whether the simulation mode should be activated self.check_box = QCheckBox("Simulation", objectName="simu checkbox") self.check_box.setChecked(self.initial_checked) self.layout.addWidget(self.check_box, 0, 0) self.gazebo_file_entry_widget = uew.GazeboWorldEntryWidget(parent=self) self.gazebo_folder_entry_widget = uew.GazeboFolderEntryWidget(parent=self) self.starting_pose_entry_widget = uew.StartingPoseEntryWidget(browser_button=False, placeholder_text="-J shoulder_pan_joint 0.5 " "-J shoulder_lift_joint 1.5 -J ...", parent=self) self.layout.addWidget(self.gazebo_file_entry_widget) self.layout.addWidget(self.gazebo_folder_entry_widget) self.layout.addWidget(self.starting_pose_entry_widget) def state_changed(self, checked): """ Triggers a signal if the checkbox ends up in a different state than the initial one @param checked: Boolean stating whether the box is checked or not """ self.simuModeChanged.emit(checked != self.initial_checked) def connect_update(self): """ Connect signals to a slot allowing to update the simulation configuration """ self.check_box.toggled.connect(self.update_config) self.gazebo_file_entry_widget.canBeSaved.connect(self.update_config) self.gazebo_folder_entry_widget.canBeSaved.connect(self.update_config) self.starting_pose_entry_widget.canBeSaved.connect(self.update_config) def update_config(self, is_checked): """ Update the current simulation configuration @param is_checked: Boolean stating whether the box is checked or not """ valid_input = self.sender().isChecked() if self.sender() is self.check_box else self.sender().valid_input self.configuration[self.sender().objectName()] = valid_input self.update_validity() if isinstance(valid_input, bool): self.state_changed(is_checked) def update_validity(self): """ Update the attribute specifying whether the current configuration is valid """ simu, world = self.configuration["simu checkbox"], self.configuration["UE Gazebo world file"] folder, pose = self.configuration["UE Gazebo model folder"], self.configuration["UE Starting pose"] if simu and self.check_box.isEnabled() and any(x is None for x in (world, folder, pose)): self.is_config_valid = False return self.is_config_valid = True def save_config(self, settings): """ Store the state of this widget and its children into settings @param settings: QSettings object in which widgets' information are stored """ settings.beginGroup(self.objectName()) current_state = self.check_box.isChecked() settings.setValue("is_checked", current_state) self.initial_checked = current_state for widget in (self.gazebo_file_entry_widget, self.gazebo_folder_entry_widget, self.starting_pose_entry_widget): widget.save_config(settings) settings.endGroup() def restore_config(self, settings): """ Restore the children's widget from the configuration saved in settings @param settings: QSettings object that contains information of the widgets to restore """ settings.beginGroup(self.objectName()) state_to_set = settings.value("is_checked", type=bool) self.initial_checked = state_to_set self.check_box.setChecked(state_to_set) for widget in (self.gazebo_file_entry_widget, self.gazebo_folder_entry_widget, self.starting_pose_entry_widget): widget.restore_config(settings) settings.endGroup()
def init_options(self): if self.layout() is None: self.center() self.setWindowTitle('Options') # Grid for checkbox options pref_header = QLabel('Preferences') pref_header.setObjectName('preferences') # In order to customize style in stylesheet set_header = QLabel('Settings') set_header.setObjectName('settings') h_line = QFrame() h_line.setFrameShape(QFrame.HLine) set_dir = QLabel('Set Screenshot Directory:') set_album = QLabel('Set imgur Album:') cb_click_send = QCheckBox('Click Balloon to Copy Image Link', self) cb_click_send.setChecked(True) cb_no_copy = QCheckBox('Never Copy Image Link') cb_auto_open = QCheckBox('Open Image in Browser') cb_auto_send = QCheckBox('Automatically Copy Image Link') cb_launch_start = QCheckBox('Launch on Start up') cb_launch_start.setDisabled(True) cb_no_copy.setChecked(True) cb_no_copy.setDisabled(True) cb_click_send.stateChanged.connect(lambda: cb_no_copy.setChecked(not cb_no_copy.isChecked())) cb_click_send.stateChanged.connect(lambda: cb_auto_send.setDisabled(cb_auto_send.isEnabled())) cb_click_send.stateChanged.connect(lambda: cb_auto_send.setChecked(cb_auto_send.isChecked())) cb_click_send.stateChanged.connect(self.toggle_click) cb_click_send.stateChanged.emit(1) cb_auto_send.stateChanged.connect(lambda: cb_click_send.setDisabled(cb_click_send.isEnabled())) cb_auto_send.stateChanged.connect(lambda: cb_click_send.setChecked(cb_click_send.isChecked())) cb_auto_send.stateChanged.connect(lambda: cb_no_copy.setChecked(not cb_no_copy.isChecked())) cb_auto_send.stateChanged.connect(self.toggle_auto_upload) cb_auto_open.stateChanged.connect(self.toggle_auto_open) dir_field = QLineEdit() dir_field.insert(self.scan_dir) album_choice = QComboBox() album_list = [alb for alb in self.albums.keys() if alb != 'Main'] album_choice.addItems(album_list) album_choice.insertSeparator(len(album_list) + 1) album_choice.insertItem(len(album_list) + 2, 'Main') album_choice.setCurrentIndex(len(album_list) + 1) album_choice.activated[str].connect(self.set_album) set_dir_button = QPushButton("Set") set_dir_button.clicked.connect(lambda: self.select_dir(dir_field)) set_dir_button.setMaximumWidth(80) options_layout = QGridLayout() options_layout.addWidget(pref_header, 0, 0) options_layout.addWidget(cb_click_send, 1, 0) options_layout.addWidget(cb_auto_send, 2, 0) options_layout.addWidget(cb_no_copy, 3, 0) options_layout.addWidget(cb_auto_open, 4, 0) options_layout.addWidget(h_line, 5, 0) options_layout.addWidget(cb_launch_start, 6, 0) options_layout.addWidget(set_header, 7, 0) options_layout.addWidget(set_dir, 8, 0) options_layout.addWidget(dir_field, 9, 0) options_layout.addWidget(set_dir_button, 10, 0) options_layout.addWidget(set_album, 11, 0) options_layout.addWidget(album_choice, 12, 0) ok_button = QPushButton("Ok") ok_button.clicked.connect(self.close) # cancel_button = QPushButton("Cancel") # Window Layout hbox = QHBoxLayout() hbox.addWidget(ok_button) # hbox.addWidget(cancel_button) # Add this later hbox.addStretch(1) vbox = QVBoxLayout() vbox.addLayout(options_layout) vbox.addLayout(hbox) self.setLayout(vbox) self.setStyleSheet(""" QWidget { background-color: rgb(50,50,50); } QLineEdit { border-color: 1px white; border-radius: 3px; padding: 0 8px; selection-color: #85BF25; background-color: white; } QComboBox { color: black; background-color: white; selection-background-color: rgb(50,50,50); selection-color: #85BF25; border: 1px black; border-radius: 3px; padding: 1px 18px 1px 3px; min-width: 6em; } QComboBox QListView{ color: white; border: 1px black; border-radius: 3px; padding: 1px 18px 1px 3px; min-width: 6em; border-color: #85BF25; } QComboBox::drop-down { width: 15px; } QLabel#preferences { color: #85BF25; font: bold 14px; } QLabel#settings { color: #85BF25; font: bold 14px; } QLabel { color: white; } QLabel#set_header { color: white; font: bold 14px; } QCheckBox { color: white; } QListWidget { color: white; } QPushButton { background-color: rgb(50,50,50); border-color: solid black; border-width: 2px; color: rgb(255,255,255); font: bold 12px; } """) else: pass