def update_locations(self): self.locations_table.setUpdatesEnabled(False) self.locations_table.setRowCount(0) for i in range(2): if i == 0: if self.scope() == QSettings.SystemScope: continue actualScope = QSettings.UserScope else: actualScope = QSettings.SystemScope for j in range(2): if j == 0: if not self.application(): continue actualApplication = self.application() else: actualApplication = '' settings = QSettings(self.format(), actualScope, self.organization(), actualApplication) row = self.locations_table.rowCount() self.locations_table.setRowCount(row + 1) item0 = QTableWidgetItem() item0.setText(settings.fileName()) item1 = QTableWidgetItem() disable = not (settings.childKeys() or settings.childGroups()) if row == 0: if settings.isWritable(): item1.setText("Read-write") disable = False else: item1.setText("Read-only") self.button_box.button(QDialogButtonBox.Ok).setDisabled(disable) else: item1.setText("Read-only fallback") if disable: item0.setFlags(item0.flags() & ~Qt.ItemIsEnabled) item1.setFlags(item1.flags() & ~Qt.ItemIsEnabled) self.locations_table.setItem(row, 0, item0) self.locations_table.setItem(row, 1, item1) self.locations_table.setUpdatesEnabled(True)
class LoadProject(QObject): def __init__(self): QObject.__init__(self) self.name_project = "" self.project_to_load = "" self.path = "" self.settings = QSettings("Nebula") self.signal_path = [] self.signal_value_path = [] @Slot(str, result = 'QString') def get_name_project(self, *args): return self.name_project @Slot(str, result = 'QString') def create(self, name_project): """ :param name_project: Name of the project :return: path of the settings file """ from PySide2.QtCore import QDateTime self.name_project = name_project #print("from python " + self.name_project) self.settings = QSettings("Nebula", self.name_project) self.settings.beginGroup("Project") self.settings.setValue("Path", os.path.join(os.environ['HOME'], '.config/Nebula', self.name_project + '.conf')) self.settings.setValue("Name", self.name_project) self.settings.setValue("Date", QDateTime.currentDateTime().toString()) self.settings.setValue("LastEdit", QDateTime.currentDateTime().toString()) self.settings.endGroup() self.settings.beginGroup("SignalFiles") self.settings.setValue("Path", "None") # Paths of the signals self.settings.setValue("ValuePath", "None") # Value paths of the signals -numpy file self.settings.endGroup() self.settings.beginGroup("Info") self.settings.endGroup() print(self.settings.fileName()) return self.settings.fileName() @Slot(str, result='QString') def settings_dir(self, past_path): return self.settings.fileName() @Slot(str, result='QString') def load(self, project): self.project_to_load = QUrl(project).toLocalFile() print(f'Project path loaded: {self.project_to_load}') self.name_project = extract_name(self.project_to_load) print(f'Project Name loaded: {self.name_project} and the other' f' way is: {QFileInfo(self.project_to_load).fileName()}') self.settings = QSettings("Nebula", self.name_project) self.settings.beginGroup("Project") self.path = self.settings.value("Path") self.name_project = self.settings.value("Name") self.settings.endGroup() self.settings.beginGroup("SignalFiles") self.signal_path = self.settings.value("Path") self.signal_value_path = self.settings.value("ValuePath") self.settings.endGroup() print(f'Organization name: {self.settings.organizationName(), self.settings.fileName()}') self.signal_path = self.signal_path.replace('None,', '') print(f'Loading signal files: {self.signal_path} type {type(self.signal_path)}') return self.signal_path
class Settings(dict): """Object to handle setting and getting settings or info about them. """ def __init__(self, *args, **kwargs): """Create the settings object and set some of its own settings. """ super(Settings, self).__init__(*args, **kwargs) QSettings.setPath(QSettings.IniFormat, QSettings.UserScope, CONFIG_DIR) self.settings = QSettings(CONFIG_FILE_PATH, QSettings.IniFormat) self.read_settings() def read_settings(self): """Reads application settings and restores them. """ settings = self.settings # Retrieve settings and store them in the prefs dict settings.beginGroup("Appearance") self['style'] = settings.value("style", default_style()) self['base_font'] = settings.value("base_font", "Arial,9") self['comments_font'] = settings.value("comments_font", "Courier,9") self['hide_groups'] = int(settings.value("hide_groups", 1) or 1) self['hide_empty_classes'] = int( settings.value("hide_empty_classes", 1) or 1) self['show_ip_units'] = int(settings.value("show_ip_units", 0) or 0) settings.endGroup() settings.beginGroup("Files") self['recent_files'] = list(settings.value("recent_files") or ['']) settings.endGroup() settings.beginGroup("ClassTree") self['class_tree_font'] = settings.value("class_tree_font", "Arial,9") settings.endGroup() settings.beginGroup("ClassTable") self['default_column_width'] = int( settings.value("default_column_width", 120) or 120) self['class_table_font'] = settings.value("class_table_font", "Arial,9") self['show_units_in_headers'] = int( settings.value("show_units_in_headers", 0) or 0) self['show_units_in_cells'] = int( settings.value("show_units_in_cells", 0) or 0) settings.endGroup() settings.beginGroup("Global") self['log_level'] = settings.value("log_level", 'DEBUG') self['sort_order'] = settings.value("sort_order", "SortedOrder") self['special_formatting'] = settings.value("special_formatting", "UseSpecialFormat") self['obey_idf_options'] = int( settings.value("obey_idf_options", 1) or 1) self['save_units'] = int(settings.value("save_units", 0) or 0) self['save_hidden_classes'] = int( settings.value("save_hidden_classes", 0) or 0) self['save_hide_groups'] = int( settings.value("save_hide_groups", 0) or 0) self['default_idd_version'] = settings.value("default_idd_version", DEFAULT_IDD_VERSION) settings.endGroup() self.update_log_level() def write_settings(self): """Writes application settings to QSettings object. """ log.info('Writing settings') settings = self.settings settings.beginGroup("Files") settings.setValue("recent_files", self.get('recent_files', [''])) settings.endGroup() settings.beginGroup("Appearance") settings.setValue("style", self['style']) settings.setValue("base_font", self['base_font']) settings.setValue("comments_font", self['comments_font']) settings.setValue("hide_groups", self['hide_groups']) settings.setValue("hide_empty_classes", self['hide_empty_classes']) settings.setValue("show_ip_units", self['show_ip_units']) settings.endGroup() settings.beginGroup("ClassTree") settings.setValue("class_tree_font", self['class_tree_font']) settings.endGroup() settings.beginGroup("ClassTable") settings.setValue("default_column_width", self['default_column_width']) settings.setValue("class_table_font", self['class_table_font']) settings.setValue("show_units_in_headers", self['show_units_in_headers']) settings.setValue("show_units_in_cells", self['show_units_in_cells']) settings.endGroup() settings.beginGroup("Global") # settings.setValue("file_encoding", self['file_encoding']) settings.setValue("log_level", self['log_level']) settings.setValue("sort_order", self['sort_order']) settings.setValue("special_formatting", self['special_formatting']) settings.setValue("obey_idf_options", self['obey_idf_options']) settings.setValue("save_units", self['save_units']) settings.setValue("save_hidden_classes", self['save_hidden_classes']) settings.setValue("save_hide_groups", self['save_hide_groups']) settings.setValue("default_idd_version", self['default_idd_version']) settings.endGroup() self.update_log_level() def save_state(self, window): """Saves application state to QSettings. :param window: """ log.info('Saving main window state') settings = self.settings settings.beginGroup("MainWindow") settings.setValue("size", window.size()) settings.setValue("pos", window.pos()) settings.setValue("geometry", window.saveGeometry()) settings.setValue("state", window.saveState()) settings.endGroup() def restore_state(self, window): """Restore application state. :param window: """ log.info('Restoring main window state') settings = self.settings settings.beginGroup("MainWindow") self['size'] = settings.value("size", QSize(1024, 768)) self['pos'] = settings.value("pos", QPoint(200, 200)) self['state'] = settings.value("state", QByteArray()) self['geometry'] = settings.value("geometry", QByteArray()) settings.endGroup() settings.beginGroup("Appearance") self['style'] = settings.value("style", default_style()) settings.endGroup() window.resize(self['size']) window.move(self['pos']) window.restoreGeometry(self['geometry']) window.restoreState(self['state']) QApplication.setStyle(QStyleFactory.create(self['style'])) def update_log_level(self): """Refreshes handlers' log level and global variable """ global LOG_LEVEL LOG_LEVEL = self['log_level'] for handler in log.parent.handlers: handler.setLevel(self['log_level']) def get_path(self): """get path """ return self.settings.fileName() def get_file_name(self): """get file name """ import os return os.path.basename(self.settings.fileName()) def get_dir_name(self): """get dir name """ import os return os.path.dirname(self.settings.fileName())
class DDMWindow(QMainWindow): def __init__(self): super().__init__() self.ConfigSettings() self.init_themes_main() self.MainMenuItems() self.MenuCreate() self.WindowSettings() self.show() def download_Cache(self): self.list_widget.clear() for i in getData(): items = QListWidgetItem(i[0], self.list_widget) def download_CacheDelete(self): try: name = self.list_widget.currentItem().text() #print(f"Removing {name}") for i in getData(): if name in i: fname = i break delData(name, fname[1], fname[2]) myfile = Path(f"{fname[1]}/{fname[2]}") print(myfile) if myfile.exists(): if self.sel_lang == "tr": dosya_silme = QMessageBox.warning( self, "Dosyayı Sil", "Dosyayı diskten silmeli miyiz?\n\nDiskten silmek için evete basın!", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) elif self.sel_lang == "en": dosya_silme = QMessageBox.warning( self, "Delete File", "Should we delete file from disk?\n\nTo delete file from disk press yes!", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if dosya_silme == QMessageBox.Yes: try: myfile.unlink() if self.sel_lang == "tr": dosya_silme = QMessageBox.information( self, "Dosya Silindi", "Dosya Başarıyla Silindi!", QMessageBox.Ok, QMessageBox.Ok) elif self.sel_lang == "en": dosya_silme = QMessageBox.information( self, "File Deleted", "File Succesfuly Deleted!", QMessageBox.Ok, QMessageBox.Ok) except Exception as e: print(e) elif dosya_silme == QMessageBox.No: pass self.download_Cache() except Exception as e: print(e) def slideLeftMenu(self): width = self.left_side_menu.width() if width == 50: newWidth = 150 else: newWidth = 50 self.animation = QPropertyAnimation(self.left_side_menu, b"minimumWidth") self.animation.setDuration(250) self.animation.setStartValue(width) self.animation.setEndValue(newWidth) self.animation.setEasingCurve(QtCore.QEasingCurve.InOutQuart) self.animation.start() def Add_Download(self): self.add_download_dialog = QDialog() self.add_download_dialog.setWindowTitle("Add_Download") # self.setWindowIcon(QIcon("logo.png")) self.init_themes_add_dialog() self.add_download_dialog.setFixedSize(325, 275) self.add_download_dialog.setMinimumSize(325, 240) self.isim = QLabel("İndir", self.add_download_dialog) self.isim.setFont(QFont("Hack Nerd Font", 15)) self.isim.setGeometry(124, 13, 125, 34) # İlerleme/Progress # self.progressBar = # URL KUTUSU self.urlbox = QLineEdit("", self.add_download_dialog) # self.urlbox.setFixedSize(100,4) self.urlbox.setGeometry(35, 60, 250, 34) self.urlbox.setPlaceholderText("URL Gir") self.urlbox.setFont(QFont("Hack Nerd Font", 11)) # INDIRME KONUMU self.downdirectory = QLineEdit(str(Path.home()), self.add_download_dialog) self.downdirectory.setGeometry(35, 100, 210, 34) self.downdirectory.setPlaceholderText("İndirilecek Konum") self.downdirectory.setFont(QFont("Hack Nerd Font", 11)) # Dosya İsmi self.enterfilename = QLineEdit("", self.add_download_dialog) # self.filename.setFixedSize(100,4) self.enterfilename.setGeometry(35, 140, 210, 34) self.enterfilename.setPlaceholderText("Dosya İsmi(Opsiyonel)") self.enterfilename.setFont(QFont("Hack Nerd Font", 11)) def connectfilename(): fnameloop = asyncio.get_event_loop() fnameloop.run_until_complete(self.detect_fname()) self.connectfilename = QPushButton(".", self.add_download_dialog) self.connectfilename.setGeometry(249, 140, 36, 34) self.connectfilename.setFont(QFont("Hack Nerd Font", 11)) self.connectfilename.clicked.connect(connectfilename) # KONUM SEÇ BUTONU def download_dir(): if self.sel_lang == "tr": try: self.dirselectdialog = QFileDialog.getExistingDirectory( self.add_download_dialog, 'İndirilecek Konumu Seç') except Exception as e: print(e) elif self.sel_lang == "en": try: self.dirselectdialog = QFileDialog.getExistingDirectory( self.add_download_dialog, 'Select Dir') except Exception as e: print(e) if self.dirselectdialog == "": self.downdirectory.setText(str(Path.home())) else: self.downdirectory.setText(str(self.dirselectdialog)) self.selectdirbutton = QPushButton("...", self.add_download_dialog) self.selectdirbutton.setGeometry(249, 100, 36, 34) self.selectdirbutton.setFont(QFont("Hack Nerd Font", 11)) self.selectdirbutton.clicked.connect(download_dir) # ProgressBar/İlerleme self.progressbar = QProgressBar(self.add_download_dialog) self.progressbar.setGeometry(35, 180, 250, 34) self.progressbar.setValue(0) # self.progressbar.hide() # INDIR BUTONU def start_downloading_process(): url = str(self.urlbox.text()) if url == "": if self.sel_lang == "tr": self.urlboxempty = QMessageBox.warning( self.add_download_dialog, "URL Kutusu Boş", "Lütfen bir url giriniz!", QMessageBox.Ok, QMessageBox.Ok) elif self.sel_lang == "en": self.urlboxempty = QMessageBox.warning( self.add_download_dialog, "URL Box Empty", "Please enter a URL!", QMessageBox.Ok, QMessageBox.Ok) else: # self.add_download_dialog.close() # self.downloading_file() # self.add_download_dialog.close() self.download() self.downloadbutton = QPushButton("İndir", self.add_download_dialog) self.downloadbutton.setGeometry(85, 220, 70, 40) self.downloadbutton.setFont(QFont("Hack Nerd Font", 11)) self.downloadbutton.clicked.connect(start_downloading_process) # self.downloadbutton.setStyleSheet("background-color: #268bd2;") # ÇIKIŞ BUTONU self.iptalbutton = QPushButton("İptal", self.add_download_dialog) self.iptalbutton.setGeometry(160, 220, 70, 40) self.iptalbutton.setFont(QFont("Hack Nerd Font", 11)) self.iptalbutton.clicked.connect(self.add_download_dialog.close) # self.iptalbutton.setStyleSheet("background-color: #ed0b0b;") self.reTranslateAddDownload() self.add_download_dialog.show() # def downloading_file(self): # self.downloading_dialog = QDialog() # self.init_themes_add_dialog() # self.downloading_dialog.setFixedSize(240, 240) # #self.downloading_dialog.setMinimumSize(325, 240) # self.downloading_dialog.exec() def reTranslateAddDownload(self): if self.sel_lang == "en": self.isim.setText("Download") self.isim.setGeometry(110, 13, 125, 34) self.downloadbutton.setText("Download") self.downloadbutton.setGeometry(65, 220, 90, 40) self.iptalbutton.setText("Cancel") self.enterfilename.setPlaceholderText("File Name(Optional)") self.downdirectory.setPlaceholderText("Enter Directory") self.urlbox.setPlaceholderText("Enter the URL") def eventFilter(self, source, event): try: if (event.type() == QtCore.QEvent.ContextMenu and source is self.list_widget): try: self.menu = QMenu() self.menu.addAction('In Future') if self.menu.exec_(event.globalPos()): item = source.itemAt(event.pos()) print(item.text()) return True except Exception as e: print(e) return super().eventFilter(source, event) except Exception as e: print(e) from mainUI import MainMenuItems from mainUI import reTranslateMain from download_script import detect_fname from download_script import detect_fsize from download_script import check_connection from download_script import download # MenuBar things from MenuBar import exitAction from MenuBar import MenuCreate from MenuBar import about from MenuBar import reTranslateAbout from MenuBar import SettingsMenu from MenuBar import SetSettings from MenuBar import restartforsettings from MenuBar import reTranslateSettings # Theming Things from theming import init_themes_main from theming import init_themes_add_dialog from theming import init_themes_settings_dialog from theming import init_themes_about_dialog def WindowSettings(self): self.setWindowTitle("Dream Download Manager") # self.setWindowIcon(QIcon("logo.png")) #self.setFixedSize(485, 375) #self.setMinimumSize(325, 240) def ConfigSettings(self): self.settings = QSettings("DDM", "DreamDownloadManager") print(self.settings.fileName()) if self.settings.contains('theme_selection'): self.selected_theme = self.settings.value('theme_selection') else: self.settings.setValue('theme_selection', 'Dark') if self.settings.contains('selected_lang'): self.sel_lang = self.settings.value('selected_lang') else: self.settings.setValue('selected_lang', 'en')
class Process(QObject): def __init__(self, engine): QObject.__init__(self) self.m_engine = engine self.project_name = '' self.process_name = list() self.process_description = list() self.action_name = list() self.settings = QSettings("Nebula") self.dat = dict() @Slot(str, str, result='QString') def process_settings(self, project_name, action_name): self.project_name = project_name self.action_name.append(action_name) self.settings = QSettings("Nebula", self.project_name) self.settings.beginGroup("ProcessInfo") self.settings.beginWriteArray(action_name) s = [str(i) for i in self.dat[project_name]] res = ",".join(s) for i in range(len(self.process_name)): self.settings.setArrayIndex(i) self.settings.setValue("Name", self.process_name[i]) self.settings.setValue("Description", self.process_description[i]) self.settings.setValue("Value", res) self.settings.endArray() self.settings.endGroup() print(self.settings.fileName()) return self.settings.fileName() def process_info(self, name="", description=""): self.process_name.append(name) self.process_description.append(description) @Slot(str, result=bool) def generate_pdf(self, project_name): self.settings = QSettings("Nebula", project_name) pdf = CustomPDF() pdf.alias_nb_pages() pdf.add_page() pdf.set_font('Times', 'B', 15) pdf.cell(0, 5, 'Project details', ln=1) pdf.set_font('Times', '', 10) self.settings.beginGroup("Project") pdf.cell(0, 10, txt="Name: {}".format(self.settings.value("Name")), ln=1) pdf.cell(0, 10, txt="Project creation date: {}".format( self.settings.value("Date")), ln=1) pdf.cell(0, 10, txt="Inform creation date: {}".format( self.settings.value("LastEdit")), ln=1) pdf.cell(0, 10, txt=" ", ln=1) self.settings.endGroup() pdf.set_font('Times', 'B', 15) pdf.cell(0, 5, 'Signals', ln=1) pdf.set_font('Times', '', 10) self.settings.beginGroup("SignalFiles") pdf.cell(0, 10, txt="Signals path: {}".format(self.settings.value("Path")), ln=1) path = self.settings.value("Path") pdf.cell(0, 10, txt=" ", ln=1) self.settings.endGroup() pdf.set_font('Times', 'B', 15) pdf.cell(0, 5, 'Information', ln=1) pdf.set_font('Times', '', 10) self.settings.beginGroup("Info") size = self.settings.beginReadArray("sfreq") for i in range(size): self.settings.setArrayIndex(i) pdf.cell(0, 10, txt="{}. sfreq: {}".format(i, self.settings.value("sfreq")), ln=1) self.settings.endArray() size = self.settings.beginReadArray("SubjectInfo") for i in range(size): self.settings.setArrayIndex(i) pdf.cell(0, 10, txt="{}. id: {}".format(i, self.settings.value("id")), ln=1) pdf.cell(0, 10, txt="{}. First name: {}".format( i, self.settings.value("first_name")), ln=1) pdf.cell(0, 10, txt="{}. Last name: {}".format( i, self.settings.value("last_name")), ln=1) pdf.cell(0, 10, txt="{}. Hand: {}".format(i, self.settings.value("hand")), ln=1) pdf.cell(0, 10, txt="{}. Sex: {}".format(i, self.settings.value("sex")), ln=1) self.settings.endArray() self.settings.endGroup() pdf.cell(0, 10, txt=" ", ln=1) pdf.set_font('Times', 'B', 15) pdf.cell(0, 5, 'Process', ln=1) pdf.set_font('Times', '', 10) self.settings.beginGroup("ProcessInfo") for action_name in self.action_name: size = self.settings.beginReadArray(action_name) for i in range(size): self.settings.setArrayIndex(i) pdf.cell(0, 10, txt="{}. Name: {}".format( i, self.settings.value("Name")), ln=1) pdf.cell(0, 10, txt="{}. Description: {}".format( i, self.settings.value("Description")), ln=1) pdf.cell(0, 10, txt="{}. Value: {}".format( i, self.settings.value("Value")), ln=1) self.settings.endArray() self.settings.endGroup() pdf.cell(0, 10, txt=" ", ln=1) print(path) pdf.output('{}_report.pdf'.format(project_name)) print(f'PDF: {project_name}') return True @Slot(QObject, result="QVariantList") def add_chart_bar(self, chart_view): # https://stackoverflow.com/questions/57536401/how-to-add-qml-scatterseries-to-existing-qml-defined-chartview context = QQmlContext(self.m_engine.rootContext()) context.setContextProperty("chart_view", chart_view) # context.setContextProperty("type", SeriesType.SeriesTypeBar.value) context.setContextProperty("type", SeriesType.SeriesTypePie.value) script = """chart_view.createSeries(type, "Pie series");""" expression = QQmlExpression(context, chart_view, script) serie = expression.evaluate()[0] if expression.hasError(): print(expression.error()) return print(serie, expression) data = self.dat[self.project_name] print(f'FROM ADD PIE CHART {data} and type {type(data)}') serie.append("a", 10.0) serie.append("b", 80.0) # serie.append("a", data[0] * 1000) # serie.append("b", data[1] * 1000) # serie.append("c", data[2] * 1000) # serie.append("b", data) return data @Slot(QtCharts.QAbstractSeries) def fill_serie(self, serie): import random mx, Mx = 0, 10 my, My = -100, 100 data = self.dat[self.project_name] serie.append(1, data[0] * 1000) serie.append(2, data[1] * 1000) serie.append(3, data[2] * 1000) # for _ in range(100): # x = random.uniform(mx, Mx) # y = random.uniform(my, My) # serie.append(x, y) # https://doc.qt.io/qt-5/qml-qtcharts-scatterseries.html#borderColor-prop serie.setProperty("borderColor", QtGui.QColor("salmon")) # https://doc.qt.io/qt-5/qml-qtcharts-scatterseries.html#brush-prop serie.setProperty("brush", QtGui.QBrush(QtGui.QColor("green"))) # https://doc.qt.io/qt-5/qml-qtcharts-scatterseries.html#borderColor-prop serie.setProperty("borderWidth", 4.0) # Process Example @Slot(str, result="QVariantList") def my_process_1(self, project_name): import statistics self.process_info("process_1", "std, variance and mean from channel 0") data = get_data_path(project_name) print(data, data[0]) data = get_data(data[0]) print(data.shape) var = statistics.variance(data[0, :]) mean = statistics.mean(data[0, :]) std = statistics.stdev(data[0, :]) value = [std * 1000, float(var) * 1000, float(mean) * 1000] self.dat[project_name] = value print(value) return value