def getParts4Combo(self, combo: QComboBox): combo.clear() combo.clearEditText() sql = "SELECT num_part FROM part;" out = self.db.get(sql) for supplier in out: combo.addItem(supplier[0]) combo.setEnabled(True)
def add_supplier_list_to_combo(self, combo: QComboBox): # clear QComboBox combo.clear() combo.clearEditText() # DB Query and update QConboBox sql = "SELECT name_supplier_short FROM supplier;" out = self.db.get(sql) for supplier in out: combo.addItem(supplier[0])
def on_click_set_part(self, ent_part: QLineEdit, combo_1: QComboBox, check: QCheckBox, ent_desc: QLineEdit, combo_2: QComboBox): # obtain part number num_part = ent_part.text() ent_part.setText(None) # obtain original part number if selected id_part_orig = 'NULL' if combo_1.isEnabled(): num_part_org = combo_1.currentText() sql1 = self.db.sql( "SELECT id_part FROM part WHERE num_part = '?';", [num_part_org]) print(sql1) out = self.db.get(sql1) for id in out: id_part_orig = id[0] combo_1.clear() combo_1.clearEditText() combo_1.setEnabled(False) # clear QCheckBox if check.isChecked(): check.setEnabled(False) # obtain part description description = ent_desc.text() ent_desc.setText(None) # obtain id_supplier from selected supplier on the QComboBox supplier = combo_2.currentText() sql2 = self.db.sql( "SELECT id_supplier FROM supplier WHERE name_supplier_short = '?';", [supplier]) print(sql2) out = self.db.get(sql2) for id in out: id_supplier = id[0] print(num_part) print(description) print(supplier) print(id_supplier) # insert new part to part table sql3 = self.db.sql( "INSERT INTO part VALUES(NULL, ?, ?, '?', '?', NULL, NULL);", [id_part_orig, id_supplier, num_part, description]) print(sql3) self.db.put(sql3)
def SetTranslateEngineItem(self, comboBox: QComboBox): """设定当前支持的翻译引擎。 Args: comboBox (QComboBox): [description] """ comboBox.clear() length = len(self.transalteEngine) for i in range(0, length): comboBox.insertItem( i, QCoreApplication.translate("Translator", self.transalteEngine[i], None)) return
def SetLanguageItem(self, comboBox: QComboBox): """设置当前支持的语言。 Args: comboBox (QComboBox): 带设定的文本框。 """ comboBox.clear() length = len(self.languages) for i in range(0, length): comboBox.insertItem( i, QCoreApplication.translate("Translator", self.languages[i], None)) return
def getPartsOptionCombo(self, label: QLabel, combo: QComboBox, check: QCheckBox): combo.clear() combo.clearEditText() if check.checkState() == Qt.Checked: sql = "SELECT num_part FROM part;" out = self.db.get(sql) for supplier in out: combo.addItem(supplier[0]) label.setStyleSheet( "QLabel {font-size:10pt; padding: 0 2px;color: black;}") combo.setEnabled(True) else: label.setStyleSheet( "QLabel {font-size:10pt; padding: 0 2px;color: gray;}") combo.setEnabled(False)
class DeviceBox(QGroupBox): def __init__(self, controller, parent=None): super().__init__("Device", parent=parent) self.controller = controller self.is_connected = False layout = QVBoxLayout() self.setLayout(layout) self.button_refresh = QPushButton("Refresh") self.combobox_ports = QComboBox() self.button_connect = QPushButton("Connect") layout.addWidget(self.button_refresh) layout.addWidget(self.combobox_ports) layout.addWidget(self.button_connect) self.button_refresh.clicked.connect(self.refresh_ports) self.button_connect.clicked.connect(self.connect_to_device) def refresh_ports(self): self.combobox_ports.clear() self.combobox_ports.addItems(self.controller.get_ports_names()) def connect_to_device(self): if not self.is_connected: port = self.combobox_ports.currentText() self.controller.connect_to_device(port) else: self.controller.disconnect_device() self.is_connected = self.controller.is_device_connected() if self.is_connected: self.button_connect.setText("Disconnect") else: self.button_connect.setText("Connect")
class PredictionWindow(QWidget): """Subwindow dedicated to random forest prediction functions.""" # Private Instance Attributes: # - _predict_btn: Button that signals for a prediction to be made. # - _predict_btn: Button that signals for the selected model to be deleted. # - _model: The RandomForest model currently loaded. # - _model_info: QPlainTextEdit widget displaying information about the selected model. # - _target_date: Calendar widget for the user to select a target prediction date. # -_plot_window: Window for displaying historical information with a prediction. _predict_btn: QDialogButtonBox _delete_btn: QDialogButtonBox _model: QComboBox _model_info: QPlainTextEdit _target_date: QCalendarWidget _plot_window: QMainWindow def __init__(self) -> None: super().__init__() main_layout = QGridLayout() button_box = self._create_button_box() main_layout.addWidget(self._create_options_group_box(), 0, 0) main_layout.addWidget(button_box, 1, 0) main_layout.setSizeConstraint(QLayout.SetMinimumSize) self.setLayout(main_layout) self._refresh_model_info() self.setWindowTitle('Predict') self._plot_window = QMainWindow() def show(self) -> None: """Override of QWidget's show() function. Refreshes window and then shows the window. """ self._refresh_lists() return super().show() @property def _selected_model(self) -> Union[RandomForest, None]: """Gets the currently selected model.""" model_name = self._model.currentText() if model_name != '': try: return load_model(model_name) except pickle.UnpicklingError: self._error_event(f'{model_name} is an invalid model.') return None else: return None def _create_button_box(self) -> QDialogButtonBox: """Creates the lower control buttons at the bottom of the window.""" button_box = QDialogButtonBox() self._predict_btn = button_box.addButton('Predict', QDialogButtonBox.ActionRole) self._delete_btn = button_box.addButton('Delete Model', QDialogButtonBox.ActionRole) refresh_btn = button_box.addButton('Refresh &Options', QDialogButtonBox.ActionRole) self._predict_btn.clicked.connect(self._predict) refresh_btn.clicked.connect(self._refresh_lists) self._delete_btn.clicked.connect(self._delete) return button_box def _create_options_group_box(self) -> QGroupBox: """Returns the group of prediction options.""" options_group_box = QGroupBox("Options") options_layout = QGridLayout() left_options = QGridLayout() right_options = QGridLayout() date_label = QLabel("Target Date:") self._target_date = QCalendarWidget() left_options.addWidget(date_label, 0, 0) left_options.addWidget(self._target_date, 1, 0, 1, 3) left_options.setColumnStretch(0, 1) self._model = QComboBox() self._model_info = QPlainTextEdit() self._model_info.setReadOnly(True) self._model.currentTextChanged.connect(self._refresh_model_info) self._refresh_lists() models_label = QLabel("Models:") info_label = QLabel("Model Information:") right_options.addWidget(models_label, 0, 0) right_options.addWidget(self._model, 1, 0) right_options.addWidget(info_label, 2, 0) right_options.addWidget(self._model_info, 3, 0) options_layout.addLayout(left_options, 0, 0) options_layout.addLayout(right_options, 0, 1) options_group_box.setLayout(options_layout) return options_group_box def _delete(self) -> None: """Deletes the currently selected dataset.""" self.setEnabled(False) name = self._model.currentText() warning = f'Are you sure you want to delete {name}?' response = QMessageBox.warning(self, self.tr("Delete Model"), warning, QMessageBox.Yes, QMessageBox.No) if response == QMessageBox.Yes: data_ingest.delete_data(name, file_type='model') self._refresh_lists() self.setEnabled(True) def _refresh_lists(self) -> None: """Refreshes avaliable datasets for training.""" self._model.clear() data_list = data_ingest.get_avaliable_data(search_type='model') self._model.addItems(data_list) def _refresh_model_info(self) -> None: """Refreshes avaliable features for the selected target.""" self._predict_btn.setEnabled(False) self._target_date.setEnabled(False) self._model_info.clear() model_name = self._model.currentText() model = self._selected_model if model is None: self._delete_btn.setEnabled(False) return None self._delete_btn.setEnabled(True) self._display_model_info(model) req_features = model.window.req_features avaliable_sym = data_ingest.get_avaliable_sym() if len(req_features - avaliable_sym) != 0: self._error_event( f'Missing required data for {model_name}: {req_features - avaliable_sym}' ) return None dfs = load_corresponding_dataframes(model) grouped_dataframe = data_ingest.create_grouped_dataframe(dfs) date_offset = pd.DateOffset(days=model.window.target_shift) self._target_date.setMaximumDate(grouped_dataframe.index.max() + date_offset) self._target_date.setMinimumDate(grouped_dataframe.index.min() + date_offset) self._target_date.setEnabled(True) self._predict_btn.setEnabled(True) return None def _display_model_info(self, model: RandomForest) -> None: """Updates model info box to display current model's information.""" self._model_info.appendPlainText( f'Target Feature Name: \n{model.window.target_lbl}') self._model_info.appendPlainText('Window Information:') self._model_info.appendPlainText( f'\t- Window Size: {model.window.window_size}') self._model_info.appendPlainText( f'\t- Target Shift: {model.window.target_shift}') self._model_info.appendPlainText( f'\t- Required Features: {model.window.req_features}') self._model_info.appendPlainText('Forest Information:') self._model_info.appendPlainText( f'\t- Number of Trees: {model.forest.n_trees}') self._model_info.appendPlainText( f'\t- Tree Max Depth: {model.forest.max_depth}') self._model_info.appendPlainText(f'\t- Seed: {model.forest.seed}') def _predict(self) -> None: """Creates a model prediction using the selected target date and model.""" self.setEnabled(False) self._predict_btn.setEnabled(False) model = self._selected_model if model is None: self.setEnabled(True) return None target_date = self._target_date.selectedDate().toPython() try: dfs = load_corresponding_dataframes(model) prediction_input = data_ingest.create_input( model.window.window_size, model.window.target_shift, target_date, dfs) except ce.MissingData: self._error_event( 'Missing required data. Could be that loaded datasets have holes.' ) self.setEnabled(True) return None prediction = model.predict(prediction_input) historical_dfs = load_corresponding_dataframes(model, 'target') if len(historical_dfs) == 0: self._prediction_historical_error(prediction) else: self._plot_prediction(historical_dfs, model, prediction, target_date) self._predict_btn.setEnabled(True) self.setEnabled(True) return None def _plot_prediction(self, historical_dfs: list[pd.DataFrame], model: RandomForest, prediction: ndarray, target_date: datetime.date) -> None: """Opens a window with a plot of the historical target data as well as the prediction the model made.""" hdf = historical_dfs[0] for frame in historical_dfs[1:]: hdf = hdf.combine_first(frame) window_end = target_date - \ pd.DateOffset(days=model.window.target_shift) window_start = window_end - pd.DateOffset(days=30 - 1) hdf = pd.Series( hdf.loc[window_end:window_start][model.window.target_lbl]) hdf_data = hdf.to_list() hdf_dates = hdf.index hdf_dates = [ts.to_pydatetime().timestamp() for ts in hdf_dates] b_axis = pg.DateAxisItem(orientation='bottom') b_axis.setLabel('Date') plot = PlotWidget(axisItems={'bottom': b_axis}) target_time = datetime.combine(target_date, datetime.min.time()) plot.addLegend() plot.plot(x=hdf_dates, y=hdf_data, name=f'Historical {model.window.target_lbl}') plot.plot(x=[target_time.timestamp()], y=prediction, pen=None, symbol='o', name=f'Predicted Value: {prediction[0]}') model_name = self._model.currentText() self._plot_window.setWindowTitle(f'{model_name} Prediction') self._plot_window.setCentralWidget(plot) self._plot_window.show() def _prediction_historical_error(self, prediction: list) -> None: """Displays a message for when historical target is unavalable such that a graph can't be made.""" QMessageBox.information( self, self.tr("Information"), f'Prediction was: {prediction}. \n ' 'Unable to display graph due to missing historical data.', QtWidgets.QMessageBox.Ok) def _error_event( self, error: str, choice: bool = False, btn: QMessageBox = QMessageBox.Abort ) -> Union[QMessageBox.Ignore, QMessageBox.Abort, None]: """Displays an error message with the given error.""" if choice: response = QMessageBox.critical(self, self.tr("Error"), error, btn, QMessageBox.Ignore) return response else: QMessageBox.critical(self, self.tr("Error"), error, QMessageBox.Ok) return None
class VideoFinderAddLink(AddLinkWindow): running_thread = None threadPool = {} def __init__(self, parent, receiver_slot, settings, video_dict={}): super().__init__(parent, receiver_slot, settings, video_dict) self.setWindowTitle( QCoreApplication.translate("ytaddlink_src_ui_tr", 'Video Finder')) self.size_label.hide() # empty lists for no_audio and no_video and video_audio files self.no_audio_list = [] self.no_video_list = [] self.video_audio_list = [] self.media_title = '' # add support for other languages locale = str(self.persepolis_setting.value('settings/locale')) QLocale.setDefault(QLocale(locale)) self.translator = QTranslator() if self.translator.load(':/translations/locales/ui_' + locale, 'ts'): QCoreApplication.installTranslator(self.translator) # extension_label self.extension_label = QLabel(self.link_frame) self.change_name_horizontalLayout.addWidget(self.extension_label) # Fetch Button self.url_submit_pushButtontton = QPushButton(self.link_frame) self.link_horizontalLayout.addWidget(self.url_submit_pushButtontton) # Status Box self.status_box_textEdit = QTextEdit(self.link_frame) self.status_box_textEdit.setMaximumHeight(150) self.link_verticalLayout.addWidget(self.status_box_textEdit) # Select format horizontal layout select_format_horizontalLayout = QHBoxLayout() # Selection Label self.select_format_label = QLabel(self.link_frame) select_format_horizontalLayout.addWidget(self.select_format_label) # Selection combobox self.media_comboBox = QComboBox(self.link_frame) self.media_comboBox.setMinimumWidth(200) select_format_horizontalLayout.addWidget(self.media_comboBox) # Duration label self.duration_label = QLabel(self.link_frame) select_format_horizontalLayout.addWidget(self.duration_label) self.format_selection_frame = QFrame(self) self.format_selection_frame.setLayout(select_format_horizontalLayout) self.link_verticalLayout.addWidget(self.format_selection_frame) # advanced_format_selection_checkBox self.advanced_format_selection_checkBox = QCheckBox(self) self.link_verticalLayout.addWidget( self.advanced_format_selection_checkBox) # advanced_format_selection_frame self.advanced_format_selection_frame = QFrame(self) self.link_verticalLayout.addWidget( self.advanced_format_selection_frame) advanced_format_selection_horizontalLayout = QHBoxLayout( self.advanced_format_selection_frame) # video_format_selection self.video_format_selection_label = QLabel( self.advanced_format_selection_frame) self.video_format_selection_comboBox = QComboBox( self.advanced_format_selection_frame) # audio_format_selection self.audio_format_selection_label = QLabel( self.advanced_format_selection_frame) self.audio_format_selection_comboBox = QComboBox( self.advanced_format_selection_frame) for widget in [ self.video_format_selection_label, self.video_format_selection_comboBox, self.audio_format_selection_label, self.audio_format_selection_comboBox ]: advanced_format_selection_horizontalLayout.addWidget(widget) # Set Texts self.url_submit_pushButtontton.setText( QCoreApplication.translate("ytaddlink_src_ui_tr", 'Fetch Media List')) self.select_format_label.setText( QCoreApplication.translate("ytaddlink_src_ui_tr", 'Select a format')) self.video_format_selection_label.setText( QCoreApplication.translate("ytaddlink_src_ui_tr", 'Video format:')) self.audio_format_selection_label.setText( QCoreApplication.translate("ytaddlink_src_ui_tr", 'Audio format:')) self.advanced_format_selection_checkBox.setText( QCoreApplication.translate("ytaddlink_src_ui_tr", 'Advanced options')) # Add Slot Connections self.url_submit_pushButtontton.setEnabled(False) self.change_name_lineEdit.setEnabled(False) self.ok_pushButton.setEnabled(False) self.download_later_pushButton.setEnabled(False) self.format_selection_frame.setEnabled(True) self.advanced_format_selection_frame.setEnabled(False) self.advanced_format_selection_checkBox.toggled.connect( self.advancedFormatFrame) self.url_submit_pushButtontton.clicked.connect(self.submitClicked) self.media_comboBox.activated.connect( partial(self.mediaSelectionChanged, 'video_audio')) self.video_format_selection_comboBox.activated.connect( partial(self.mediaSelectionChanged, 'video')) self.audio_format_selection_comboBox.activated.connect( partial(self.mediaSelectionChanged, 'audio')) self.link_lineEdit.textChanged.disconnect( super().linkLineChanged) # Should be disconnected. self.link_lineEdit.textChanged.connect(self.linkLineChangedHere) self.setMinimumSize(650, 480) self.status_box_textEdit.hide() self.format_selection_frame.hide() self.advanced_format_selection_frame.hide() self.advanced_format_selection_checkBox.hide() if 'link' in video_dict.keys() and video_dict['link']: self.link_lineEdit.setText(video_dict['link']) self.url_submit_pushButtontton.setEnabled(True) else: # check clipboard clipboard = QApplication.clipboard() text = clipboard.text() if (("tp:/" in text[2:6]) or ("tps:/" in text[2:7])): self.link_lineEdit.setText(str(text)) self.url_submit_pushButtontton.setEnabled(True) def advancedFormatFrame(self, button): if self.advanced_format_selection_checkBox.isChecked(): self.advanced_format_selection_frame.setEnabled(True) self.format_selection_frame.setEnabled(False) self.mediaSelectionChanged( 'video', int(self.video_format_selection_comboBox.currentIndex())) else: self.advanced_format_selection_frame.setEnabled(False) self.format_selection_frame.setEnabled(True) self.mediaSelectionChanged('video_audio', int(self.media_comboBox.currentIndex())) def getReadableSize(self, size): try: return '{:1.2f} MB'.format(int(size) / 1048576) except: return str(size) def getReadableDuration(self, seconds): try: seconds = int(seconds) hours = seconds // 3600 seconds = seconds % 3600 minutes = seconds // 60 seconds = seconds % 60 return '{:02d}:{:02d}:{:02d}'.format(hours, minutes, seconds) except: return str(seconds) # Define native slots def urlChanged(self, value): if ' ' in value or value == '': self.url_submit_pushButtontton.setEnabled(False) self.url_submit_pushButtontton.setToolTip( QCoreApplication.translate("ytaddlink_src_ui_tr", 'Please enter a valid video link')) else: self.url_submit_pushButtontton.setEnabled(True) self.url_submit_pushButtontton.setToolTip('') def submitClicked(self, button=None): # Clear media list self.media_comboBox.clear() self.format_selection_frame.hide() self.advanced_format_selection_checkBox.hide() self.advanced_format_selection_frame.hide() self.video_format_selection_comboBox.clear() self.audio_format_selection_comboBox.clear() self.change_name_lineEdit.clear() self.threadPool.clear() self.change_name_checkBox.setChecked(False) self.video_audio_list.clear() self.no_video_list.clear() self.no_audio_list.clear() self.url_submit_pushButtontton.setEnabled(False) self.status_box_textEdit.setText( QCoreApplication.translate("ytaddlink_src_ui_tr", 'Fetching Media Info...')) self.status_box_textEdit.show() self.ok_pushButton.setEnabled(False) self.download_later_pushButton.setEnabled(False) dictionary_to_send = deepcopy(self.plugin_add_link_dictionary) # More options more_options = self.collectMoreOptions() for k in more_options.keys(): dictionary_to_send[k] = more_options[k] dictionary_to_send['link'] = self.link_lineEdit.text() fetcher_thread = MediaListFetcherThread(self.fetchedResult, dictionary_to_send, self) self.parent.threadPool.append(fetcher_thread) self.parent.threadPool[len(self.parent.threadPool) - 1].start() def fileNameChanged(self, value): if value.strip() == '': self.ok_pushButton.setEnabled(False) def mediaSelectionChanged(self, combobox, index): try: if combobox == 'video_audio': if self.media_comboBox.currentText() == 'Best quality': self.change_name_lineEdit.setText(self.media_title) self.extension_label.setText('.' + self.no_audio_list[-1]['ext']) else: self.change_name_lineEdit.setText(self.media_title) self.extension_label.setText( '.' + self.video_audio_list[index]['ext']) self.change_name_checkBox.setChecked(True) elif combobox == 'video': if self.video_format_selection_comboBox.currentText( ) != 'No video': self.change_name_lineEdit.setText(self.media_title) self.extension_label.setText('.' + self.no_audio_list[index - 1]['ext']) self.change_name_checkBox.setChecked(True) else: if self.audio_format_selection_comboBox.currentText( ) != 'No audio': self.change_name_lineEdit.setText(self.media_title) self.extension_label.setText('.' + self.no_video_list[ int(self.audio_format_selection_comboBox. currentIndex()) - 1]['ext']) self.change_name_checkBox.setChecked(True) else: self.change_name_lineEdit.setChecked(False) elif combobox == 'audio': if self.audio_format_selection_comboBox.currentText( ) != 'No audio' and self.video_format_selection_comboBox.currentText( ) == 'No video': self.change_name_lineEdit.setText(self.media_title) self.extension_label.setText('.' + self.no_video_list[index - 1]['ext']) self.change_name_checkBox.setChecked(True) elif (self.audio_format_selection_comboBox.currentText() == 'No audio' and self.video_format_selection_comboBox.currentText() != 'No video') or ( self.audio_format_selection_comboBox.currentText() != 'No audio' and self.video_format_selection_comboBox.currentText() != 'No video'): self.change_name_lineEdit.setText(self.media_title) self.extension_label.setText('.' + self.no_audio_list[ int(self.video_format_selection_comboBox.currentIndex( )) - 1]['ext']) self.change_name_checkBox.setChecked(True) elif self.audio_format_selection_comboBox.currentText( ) == 'No audio' and self.video_format_selection_comboBox.currentText( ) == 'No video': self.change_name_checkBox.setChecked(False) except Exception as ex: logger.sendToLog(ex, "ERROR") def fetchedResult(self, media_dict): self.url_submit_pushButtontton.setEnabled(True) if 'error' in media_dict.keys(): self.status_box_textEdit.setText('<font color="#f11">' + str(media_dict['error']) + '</font>') self.status_box_textEdit.show() else: # Show the media list # add no audio and no video options to the comboboxes self.video_format_selection_comboBox.addItem('No video') self.audio_format_selection_comboBox.addItem('No audio') self.media_title = media_dict['title'] if 'formats' not in media_dict.keys( ) and 'entries' in media_dict.keys(): formats = media_dict['entries'] formats = formats[0] media_dict['formats'] = formats['formats'] elif 'formats' not in media_dict.keys( ) and 'format' in media_dict.keys(): media_dict['formats'] = [media_dict.copy()] try: i = 0 for f in media_dict['formats']: no_audio = False no_video = False text = '' if 'acodec' in f.keys(): # only video, no audio if f['acodec'] == 'none': no_audio = True # resolution if 'height' in f.keys(): text = text + ' ' + '{}p'.format(f['height']) if 'vcodec' in f.keys(): # if f['vcodec'] == 'none' and f['acodec'] != 'none': # continue # No video, show audio bit rate if f['vcodec'] == 'none': text = text + '{}kbps'.format(f['abr']) no_video = True if 'ext' in f.keys(): text = text + ' ' + '.{}'.format(f['ext']) if 'filesize' in f.keys() and f['filesize']: # Youtube api does not supply file size for some formats, so check it. text = text + ' ' + '{}'.format( self.getReadableSize(f['filesize'])) else: # Start spider to find file size input_dict = deepcopy(self.plugin_add_link_dictionary) input_dict['link'] = f['url'] more_options = self.collectMoreOptions() for key in more_options.keys(): input_dict[key] = more_options[key] size_fetcher = FileSizeFetcherThread(input_dict, i) self.threadPool[str(i)] = { 'thread': size_fetcher, 'item_id': i } self.parent.threadPool.append(size_fetcher) self.parent.threadPool[len(self.parent.threadPool) - 1].start() self.parent.threadPool[len(self.parent.threadPool) - 1].FOUND.connect( self.findFileSize) # Add current format to the related comboboxes if no_audio: self.no_audio_list.append(f) self.video_format_selection_comboBox.addItem(text) elif no_video: self.no_video_list.append(f) self.audio_format_selection_comboBox.addItem(text) else: self.video_audio_list.append(f) self.media_comboBox.addItem(text) i = i + 1 self.status_box_textEdit.hide() if 'duration' in media_dict.keys(): self.duration_label.setText( 'Duration ' + self.getReadableDuration(media_dict['duration'])) self.format_selection_frame.show() self.advanced_format_selection_checkBox.show() self.advanced_format_selection_frame.show() self.ok_pushButton.setEnabled(True) self.download_later_pushButton.setEnabled(True) # if we have no options for separate audio and video, then hide advanced_format_selection... if len(self.no_audio_list) == 0 and len( self.no_video_list) == 0: self.advanced_format_selection_checkBox.hide() self.advanced_format_selection_frame.hide() # set index of comboboxes on best available quality. # we have both audio and video if len(self.no_audio_list) != 0 and len( self.no_video_list) != 0: self.media_comboBox.addItem('Best quality') self.media_comboBox.setCurrentIndex( len(self.video_audio_list)) self.change_name_lineEdit.setText(self.media_title) self.extension_label.setText('.' + self.no_audio_list[-1]['ext']) self.change_name_checkBox.setChecked(True) # video and audio are not separate elif len(self.video_audio_list) != 0: self.media_comboBox.setCurrentIndex( len(self.video_audio_list) - 1) if len(self.no_audio_list) != 0: self.video_format_selection_comboBox.setCurrentIndex( len(self.no_audio_list)) if len(self.no_video_list) != 0: self.audio_format_selection_comboBox.setCurrentIndex( len(self.no_video_list)) # if we have only audio or we have only video then hide media_comboBox if len(self.video_audio_list) == 0: self.media_comboBox.hide() self.select_format_label.hide() # only video if len(self.no_video_list) != 0 and len( self.no_audio_list) == 0: self.mediaSelectionChanged( 'video', int(self.video_format_selection_comboBox. currentIndex())) self.advanced_format_selection_checkBox.setChecked( True) self.advanced_format_selection_checkBox.hide() # only audio elif len(self.no_video_list) == 0 and len( self.no_audio_list) != 0: self.mediaSelectionChanged( 'audio', int(self.audio_format_selection_comboBox. currentIndex())) self.advanced_format_selection_checkBox.setChecked( True) self.advanced_format_selection_checkBox.hide() # audio and video else: self.mediaSelectionChanged( 'video_audio', int(self.media_comboBox.currentIndex())) except Exception as ex: logger.sendToLog(ex, "ERROR") def findFileSize(self, result): try: item_id = self.threadPool[str(result['thread_key'])]['item_id'] if result['file_size'] and result['file_size'] != '0': text = self.media_comboBox.itemText(item_id) self.media_comboBox.setItemText( item_id, '{} - {}'.format(text, result['file_size'])) except Exception as ex: logger.sendToLog(ex, "ERROR") def linkLineChangedHere(self, lineEdit): if str(lineEdit) == '': self.url_submit_pushButtontton.setEnabled(False) else: self.url_submit_pushButtontton.setEnabled(True) # This method collects additional information like proxy ip, user, password etc. def collectMoreOptions(self): options = { 'ip': None, 'port': None, 'proxy_user': None, 'proxy_passwd': None, 'download_user': None, 'download_passwd': None } if self.proxy_checkBox.isChecked(): options['ip'] = self.ip_lineEdit.text() options['port'] = self.port_spinBox.value() options['proxy_user'] = self.proxy_user_lineEdit.text() options['proxy_passwd'] = self.proxy_pass_lineEdit.text() if self.download_checkBox.isChecked(): options['download_user'] = self.download_user_lineEdit.text() options['download_passwd'] = self.download_pass_lineEdit.text() # These info (keys) are required for spider to find file size, because spider() does not check if key exists. additional_info = [ 'header', 'load_cookies', 'user_agent', 'referer', 'out' ] for i in additional_info: if i not in self.plugin_add_link_dictionary.keys(): options[i] = None return options # user submitted information by pressing ok_pushButton, so get information # from VideoFinderAddLink window and return them to the mainwindow with callback! def okButtonPressed(self, download_later, button=None): link_list = [] # separate audio format and video format is selected. if self.advanced_format_selection_checkBox.isChecked(): if self.video_format_selection_comboBox.currentText( ) == 'No video' and self.audio_format_selection_comboBox.currentText( ) != 'No audio': # only audio link must be added to the link_list audio_link = self.no_video_list[ self.audio_format_selection_comboBox.currentIndex() - 1]['url'] link_list.append(audio_link) elif self.video_format_selection_comboBox.currentText( ) != 'No video' and self.audio_format_selection_comboBox.currentText( ) == 'No audio': # only video link must be added to the link_list video_link = self.no_audio_list[ self.video_format_selection_comboBox.currentIndex() - 1]['url'] link_list.append(video_link) elif self.video_format_selection_comboBox.currentText( ) != 'No video' and self.audio_format_selection_comboBox.currentText( ) != 'No audio': # video and audio links must be added to the link_list audio_link = self.no_video_list[ self.audio_format_selection_comboBox.currentIndex() - 1]['url'] video_link = self.no_audio_list[ self.video_format_selection_comboBox.currentIndex() - 1]['url'] link_list = [video_link, audio_link] elif self.video_format_selection_comboBox.currentText( ) == 'No video' and self.audio_format_selection_comboBox.currentText( ) == 'No audio': # no video and audio is selected! REALLY?!. user is DRUNK! close the window! :)) self.close() else: if self.media_comboBox.currentText() == 'Best quality': # the last item in no_video_list and no_audio_list are the best. video_link = self.no_audio_list[-1]['url'] audio_link = self.no_video_list[-1]['url'] link_list = [video_link, audio_link] else: audio_and_video_link = self.video_audio_list[ self.media_comboBox.currentIndex()]['url'] link_list.append(audio_and_video_link) # write user's new inputs in persepolis_setting for next time :) self.persepolis_setting.setValue('add_link_initialization/ip', self.ip_lineEdit.text()) self.persepolis_setting.setValue('add_link_initialization/port', self.port_spinBox.value()) self.persepolis_setting.setValue('add_link_initialization/proxy_user', self.proxy_user_lineEdit.text()) self.persepolis_setting.setValue( 'add_link_initialization/download_user', self.download_user_lineEdit.text()) # get proxy information if not (self.proxy_checkBox.isChecked()): ip = None port = None proxy_user = None proxy_passwd = None else: ip = self.ip_lineEdit.text() if not (ip): ip = None port = self.port_spinBox.value() if not (port): port = None proxy_user = self.proxy_user_lineEdit.text() if not (proxy_user): proxy_user = None proxy_passwd = self.proxy_pass_lineEdit.text() if not (proxy_passwd): proxy_passwd = None # get download username and password information if not (self.download_checkBox.isChecked()): download_user = None download_passwd = None else: download_user = self.download_user_lineEdit.text() if not (download_user): download_user = None download_passwd = self.download_pass_lineEdit.text() if not (download_passwd): download_passwd = None # check that if user limits download speed. if not (self.limit_checkBox.isChecked()): limit = 0 else: if self.limit_comboBox.currentText() == "KiB/s": limit = str(self.limit_spinBox.value()) + str("K") else: limit = str(self.limit_spinBox.value()) + str("M") # get start time for download if user set that. if not (self.start_checkBox.isChecked()): start_time = None else: start_time = self.start_time_qDataTimeEdit.text() # get end time for download if user set that. if not (self.end_checkBox.isChecked()): end_time = None else: end_time = self.end_time_qDateTimeEdit.text() # set name for file(s) if self.change_name_checkBox.isChecked(): name = str(self.change_name_lineEdit.text()) if name == '': name = 'video_finder_file' else: name = 'video_finder_file' # video finder always finds extension # but if it can't find file extension # use mp4 for extension. if str(self.extension_label.text()) == '': extension = '.mp4' else: extension = str(self.extension_label.text()) # did user select separate audio and video? if len(link_list) == 2: video_name = name + extension audio_name = name + '.' + \ str(self.no_video_list[self.audio_format_selection_comboBox.currentIndex() - 1]['ext']) name_list = [video_name, audio_name] else: name_list = [name + extension] # get number of connections connections = self.connections_spinBox.value() # get download_path download_path = self.download_folder_lineEdit.text() # referer if self.referer_lineEdit.text() != '': referer = self.referer_lineEdit.text() else: referer = None # header if self.header_lineEdit.text() != '': header = self.header_lineEdit.text() else: header = None # user_agent if self.user_agent_lineEdit.text() != '': user_agent = self.user_agent_lineEdit.text() else: user_agent = None # load_cookies if self.load_cookies_lineEdit.text() != '': load_cookies = self.load_cookies_lineEdit.text() else: load_cookies = None add_link_dictionary_list = [] if len(link_list) == 1: # save information in a dictionary(add_link_dictionary). add_link_dictionary = { 'referer': referer, 'header': header, 'user_agent': user_agent, 'load_cookies': load_cookies, 'out': name_list[0], 'start_time': start_time, 'end_time': end_time, 'link': link_list[0], 'ip': ip, 'port': port, 'proxy_user': proxy_user, 'proxy_passwd': proxy_passwd, 'download_user': download_user, 'download_passwd': download_passwd, 'connections': connections, 'limit_value': limit, 'download_path': download_path } add_link_dictionary_list.append(add_link_dictionary) else: video_add_link_dictionary = { 'referer': referer, 'header': header, 'user_agent': user_agent, 'load_cookies': load_cookies, 'out': name_list[0], 'start_time': start_time, 'end_time': end_time, 'link': link_list[0], 'ip': ip, 'port': port, 'proxy_user': proxy_user, 'proxy_passwd': proxy_passwd, 'download_user': download_user, 'download_passwd': download_passwd, 'connections': connections, 'limit_value': limit, 'download_path': download_path } audio_add_link_dictionary = { 'referer': referer, 'header': header, 'user_agent': user_agent, 'load_cookies': load_cookies, 'out': name_list[1], 'start_time': None, 'end_time': end_time, 'link': link_list[1], 'ip': ip, 'port': port, 'proxy_user': proxy_user, 'proxy_passwd': proxy_passwd, 'download_user': download_user, 'download_passwd': download_passwd, 'connections': connections, 'limit_value': limit, 'download_path': download_path } add_link_dictionary_list = [ video_add_link_dictionary, audio_add_link_dictionary ] # get category of download category = str(self.add_queue_comboBox.currentText()) del self.plugin_add_link_dictionary # return information to mainwindow self.callback(add_link_dictionary_list, download_later, category) # close window self.close()
class MainWindow(QMainWindow): def __init__(self): super().__init__() ## declared variables self.dir_path = "None selected" self.filelist = ["Select Folder"] self.filelistindex = None self.setWindowTitle("Ephys-Quick Analysis") layout = QGridLayout() toolbar = QToolBar("Function toolbar") self.addToolBar(toolbar) self.folderbuttonsetup() toolbar.addAction(self.folderbutton) self.setStatusBar(QStatusBar(self)) self.filebox = QComboBox() self.filebox.addItems(self.filelist) layout.addWidget(self.filebox, 0, 0, 1, 2) self.tracelabel = QLabel("Sweep number :") layout.addWidget(self.tracelabel, 0, 2) self.sweepslider = QSpinBox() self.sweepslider.setMinimum(0) self.sweepslider.setSingleStep(1) layout.addWidget(self.sweepslider, 0, 3, 1, 2) self.pw = pg.PlotWidget(name='Clamp') ## giving the plots names allows us to link their axes together layout.addWidget(self.pw, 1, 0, 2, 5) self.pw2 = pg.PlotWidget(name='ClampZoom') ## giving the plots names allows us to link their axes together layout.addWidget(self.pw2, 1, 6, 2, 5) self.pw3 = pg.PlotWidget(name='Stim') layout.addWidget(self.pw3, 6, 0, 2, 5) self.pw3.setXLink(self.pw) self.pw4 = pg.PlotWidget(name='StimZoom') layout.addWidget(self.pw4, 6, 6, 2, 5) self.pw4.setXLink(self.pw2) self.pw.setBackground('w') self.pw2.setBackground('w') self.pw3.setBackground('w') self.pw4.setBackground('w') widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget) def folderbuttonsetup(self): self.folderbutton = QAction("Folder", self) self.folderbutton.setStatusTip(self.dir_path) self.folderbutton.triggered.connect(self.folderselect) def folderselect(self): print("click") print(self.dir_path) self.dir_path = QFileDialog.getExistingDirectory() self.folderbutton.setStatusTip(self.dir_path) print(self.dir_path) self.fileboxlist() def fileboxlist(self): print('Files within experiment date folder') print('ISOLATING ABF FILES...') self.dir_path_1 = self.dir_path[2:] + "/" self.fileinfolder = os.listdir(self.dir_path_1) self.abffiles = [extension for extension in self.fileinfolder if re.search("\.abf$", extension)] self.abffiles.sort() print('*.abf files in folder:') print(self.abffiles) self.filebox.clear() self.filebox.currentTextChanged.connect(self.fileselected) self.filelist = self.abffiles self.filebox.addItems(self.filelist) def fileselected(self, s): print("yo") print(s) self.fileselected_1 = self.dir_path_1 + s print(self.fileselected_1) self.pw.clear() self.pw2.clear() self.pw3.clear() self.pw4.clear() self.loadabf(self.fileselected_1) def loadabf(self, filetoload): print("load file") self.abf = pyabf.ABF(filetoload) self.numsweep = self.abf.sweepCount - 1 self.sweepslider.cleanText() self.sweepslider.setMaximum(self.numsweep) self.sweepslider.valueChanged.connect(self.setsweep) self.pw.setLabel('left', self.abf.sweepLabelY) self.pw.setLabel('bottom', self.abf.sweepLabelX) self.pw2.setLabel('left', self.abf.sweepLabelY) self.pw2.setLabel('bottom', self.abf.sweepLabelX) self.pw3.setLabel('left', self.abf.sweepLabelY) self.pw3.setLabel('bottom', self.abf.sweepLabelX) self.pw4.setLabel('left', self.abf.sweepLabelY) self.pw4.setLabel('bottom', self.abf.sweepLabelX) self.zoomarea = pg.LinearRegionItem([0, 1]) self.zoomarea.setZValue(-10) self.pw.addItem(self.zoomarea) for sweepnum in self.abf.sweepList: self.abf.setSweep(sweepnum, channel=0) self.pw.plot(self.abf.sweepX, self.abf.sweepY, pen=pg.mkPen('black', width=1)) for sweepnum in self.abf.sweepList: self.abf.setSweep(sweepnum, channel=1) self.pw3.plot(self.abf.sweepX, self.abf.sweepC, pen=pg.mkPen('black', width=1)) for sweepnum in self.abf.sweepList: self.abf.setSweep(sweepnum, channel=0) self.pw2.plot(self.abf.sweepX, self.abf.sweepY, pen=pg.mkPen('black', width=1)) for sweepnum in self.abf.sweepList: self.abf.setSweep(sweepnum, channel=1) self.pw4.plot(self.abf.sweepX, self.abf.sweepC, pen=pg.mkPen('black', width=1)) def updatePlot(): self.pw2.setXRange(*self.zoomarea.getRegion(), padding=0) def updateRegion(): self.zoomarea.setRegion(self.pw2.getViewBox().viewRange()[0]) self.zoomarea.sigRegionChanged.connect(updatePlot) self.pw2.sigXRangeChanged.connect(updateRegion) updatePlot() self.currenttrace = self.pw.plot() self.currenttrace.setPen(pg.mkPen('r', width=2.5)) self.currenttrace2 = self.pw2.plot() self.currenttrace2.setPen(pg.mkPen('r', width=2.5)) self.currenttrace3 = self.pw3.plot() self.currenttrace3.setPen(pg.mkPen('r', width=2.5)) self.currenttrace4 = self.pw4.plot() self.currenttrace4.setPen(pg.mkPen('r', width=2.5)) def setsweep(self, numofsweep): print(numofsweep) self.currenttrace.clear() self.currenttrace2.clear() self.currenttrace3.clear() self.currenttrace4.clear() for sweepnum in self.abf.sweepList: self.abf.setSweep(sweepnum, channel=0) if sweepnum == numofsweep: self.currenttrace.setData(self.abf.sweepX, self.abf.sweepY) for sweepnum in self.abf.sweepList: self.abf.setSweep(sweepnum, channel=1) if sweepnum == numofsweep: self.currenttrace3.setData(self.abf.sweepX, self.abf.sweepC) for sweepnum in self.abf.sweepList: self.abf.setSweep(sweepnum, channel=0) if sweepnum == numofsweep: self.currenttrace2.setData(self.abf.sweepX, self.abf.sweepY) for sweepnum in self.abf.sweepList: self.abf.setSweep(sweepnum, channel=1) if sweepnum == numofsweep: self.currenttrace4.setData(self.abf.sweepX, self.abf.sweepC)
class SetQuotaDiskWidget(QWidget): Sg_view_changed = Signal() def __init__(self, model: SettingsModel, parent=None): super(SetQuotaDiskWidget, self).__init__(parent) self._model = model self.setAccessibleName("InfoBox") self.title = QLabel() self.title.setText("Spazio di archiviazione") self.title.setAccessibleName("Title2") self.sottotitolo = QLabel() self.sottotitolo.setAccessibleName('Sottotitolo') self.sottotitolo.setText( "Cambia lo spazio di archiviazione destinato alla cartella sincronizzata" ) # Barra riempimento disco self.progress_label = QLabel() self.progress_label.setText("Spazio occupato:") self.disk_progress = QProgressBar() self.disk_progress.setFormat("") self.disk_quota = QLabel() # Modifica spazio dedicato self.spaceLabel = QLabel(" ") self.dedicated_space = QLineEdit() self.dedicated_space.setValidator(QDoubleValidator()) self.sizes_box = QComboBox() self.sizes_box.wheelEvent = lambda event: None _path_size = bitmath.parse_string(model.convert_size(model.get_size())) _disk_free = bitmath.parse_string( model.convert_size(model.get_free_disk())) self.populate_size_box(_path_size, _disk_free) self.change_quota_button = QPushButton("Cambia quota disco") self.change_quota_button.setMaximumWidth(150) self.change_quota_button.clicked.connect( self.Sl_dedicated_space_changed) self.dedicated_space.returnPressed.connect( self.Sl_dedicated_space_changed) self.buttonLayout = QHBoxLayout() self.buttonLayout.addWidget(self.spaceLabel) self.buttonLayout.addWidget(self.change_quota_button) self.buttonLayout.addWidget(self.spaceLabel) set_space_layout = QHBoxLayout() set_space_layout.addWidget(self.dedicated_space) set_space_layout.addWidget(self.sizes_box) quota_layout = QHBoxLayout() quota_layout.setAlignment(Qt.AlignLeft) quota_layout.addWidget(self.progress_label) quota_layout.addWidget(self.disk_quota) # layout disk_layout = QVBoxLayout() disk_layout.setAlignment(Qt.AlignLeft) disk_layout.addWidget(self.title) disk_layout.addWidget(self.sottotitolo) disk_layout.addWidget(self.spaceLabel) disk_layout.addLayout(quota_layout) disk_layout.addWidget(self.disk_progress) disk_layout.addWidget(self.spaceLabel) disk_layout.addLayout(set_space_layout) disk_layout.addLayout(self.buttonLayout) self.setLayout(disk_layout) self.Sl_model_changed() @Slot() def Sl_dedicated_space_changed(self): self.Sg_view_changed.emit() @Slot() def Sl_model_changed(self): """ Slot collegato ai segnali del model, aggiorna la vista con i nuovi valori :return: None """ # Prendo quota disco con unità e il peso della cartella senza unità (Byte default) new_max_quota = self._model.get_quota_disco() _folder_size = self._model.get_size() # Converto ad oggetto bitmath il peso della cartella e la quota disco folder_size_parsed = bitmath.parse_string( self._model.convert_size(_folder_size)) quota_disco_parsed = bitmath.parse_string(new_max_quota) # Imposto la textbox che mi dice quanto peso ho occupato su quello disponibile self.disk_quota.setText( f"{folder_size_parsed} su {new_max_quota} in uso") free_disk_parsed = bitmath.parse_string( self._model.convert_size(self._model.get_free_disk())) # Imposto la textbox che richiede input if not self.dedicated_space.hasFocus(): self.dedicated_space.setText(str(quota_disco_parsed.value)) # Creo i nuovi valori della combobox if not self.sizes_box.hasFocus(): self.populate_size_box(folder_size_parsed, free_disk_parsed) # Imposto l'item in focus della combobox self.sizes_box.setCurrentText(quota_disco_parsed.unit) # Prendo dimensione corrente della sync folder e della quota disco # e metto in proporzione con quotadisco:100=syncfolder:x _progress_bar_max_value = 100 _tmp = folder_size_parsed.to_Byte().value * _progress_bar_max_value _progress_bar_current_percentage = _tmp / quota_disco_parsed.to_Byte( ).value # Inserisco nuovi valori nella progress bar self.disk_progress.setRange(0, _progress_bar_max_value) self.disk_progress.setValue(_progress_bar_current_percentage) # Se la cartella occupa più spazio di quanto voluto allora la porto a quanto occupa if quota_disco_parsed < folder_size_parsed and not self.dedicated_space.hasFocus( ): self.dedicated_space.setText(str(folder_size_parsed.value)) self.sizes_box.setCurrentText(folder_size_parsed.unit) self.Sg_view_changed.emit() def populate_size_box( self, _min: str, _max: str, ) -> None: """ This method populates the size box with only the available units ex hdd has only <1gb so gb will not be used, the current folder is heavier than 1mb so kb will not be used. :param _min: minimum value with unit ex 10 KiB or just 'KiB' :param _max: maximum value with unit ex 10 KiB or just 'KiB' :return: None """ _sizes = "Byte", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB" # Converto in ogni caso a string, in caso in cui venga passato un oggetto # tipo bitmath _min = str(_min) _max = str(_max) # Rimuovo eventuali numeri e caratteri extra, tengo solo l'unità di misura _min = ''.join(i for i in _min if not i.isdigit() and i != '.') _max = ''.join(i for i in _max if not i.isdigit() and i != '.') # Rimuovo possibili spazi ad inizio e fine stringa _min = _min.strip() _max = _max.strip() # Rimuovo dal vettore di possibili unità di misura tutte le unità sotto il lower bound lower_bound = _sizes[_sizes.index(_min):] # Rimuovo dal vettore di possibili unità di misura tutte le unità sopra l'upper bound upper_bound = lower_bound[:lower_bound.index(_max) + 1] # Pulisco il vecchio combo box self.sizes_box.clear() # Inserisco nuovi valori self.sizes_box.addItems(upper_bound)