def export_db(self): # TODO path = str( QFileDialog.getExistingDirectory(self, _('Select Directory'))) if path: self.show_msg_on_status_bar( _(F'Loaded DB from {self.config.db_path}'))
def __init__(self, file_path): self.file_path = file_path self.all_entries = list() if os.path.isfile(self.file_path): try: with open(self.file_path, 'rb') as the_file: data = the_file.read() self.all_entries = self.load(data) except EOFError as e: logger.error( _(F'Failed to load entries data, runtime error is: {e}')) logger.info( _('Created empty database, previous file renamed for safety' )) os.rename( self.file_path, F'{self.file_path}_{datetime.now().strftime("%Y-%m-%d_%H-%M-%S")}' ) with open(self.file_path, 'wb') as f: f.write(self.dump()) except Exception as e: print(e) else: # no data with open(file_path, 'wb') as f: f.write(self.dump())
def init_menu_bar(self): menu_bar = self.menuBar() file_menu = menu_bar.addMenu(_('File')) entry_menu = menu_bar.addMenu(_('Entry')) filter_menu = menu_bar.addMenu(_('Filter')) view_menu = menu_bar.addMenu(_('View')) redraw_on_release_grid_action = QAction(_('Refresh on slider release'), self) redraw_on_release_grid_action.setCheckable(True) redraw_on_release_grid_action.setChecked(True) view_menu.addAction(redraw_on_release_grid_action) redraw_on_release_grid_action.triggered.connect( lambda: self.change_redraw_on_release(redraw_on_release_grid_action .isChecked())) redraw_on_release_grid_action.setChecked(self.config.redraw_on_release) self.change_redraw_on_release(self.config.redraw_on_release) imp_act = QAction(_('Import db'), self) imp_act.triggered.connect(self.import_db) file_menu.addAction(imp_act) exp_act = QAction(_('Export db'), self) exp_act.triggered.connect(self.export_db) file_menu.addAction(exp_act) aot_menu = QAction(_('Stay on top'), self) aot_menu.setCheckable(True) aot_menu.triggered.connect( lambda: self.change_sot(aot_menu.isChecked())) view_menu.addAction(aot_menu) aot_menu.setChecked(self.config.stay_on_top) dark_mode = QAction(_('Dark mode'), self) dark_mode.setCheckable(True) dark_mode.triggered.connect( lambda: self.redraw_palette(dark_mode.isChecked())) view_menu.addAction(dark_mode) dark_mode.setChecked(self.config.dark_mode) new_entry = QAction(_('Add new entry'), self) new_entry.triggered.connect(self.add_new_entry) entry_menu.addAction(new_entry) filter_menu.addSection('Entry type') for entry_type in EntryType: self.add_filter(entry_type.value, filter_menu, self.filter_type_changed) filter_menu.addSeparator() filter_menu.addSection('Progress status') for entry_status in ProgressStatus: self.add_filter(entry_status.value, filter_menu, self.filter_status_changed)
def add_filter(self, name, filter_menu, function): a = QAction(_(name), self) a.setCheckable(True) a.triggered.connect(lambda: function(name, a.isChecked())) filter_menu.addAction(a) a.setChecked(not getattr(self.config, name.lower())) a.trigger()
def __init__(self, cwd): path = os.path.join(cwd, PROJECT_NAME_SHORT) if not os.path.isdir(path): os.mkdir(path) self.config_path = os.path.join(path, F'{PROJECT_NAME_SHORT}.ini') self.config = configparser.ConfigParser() try: self.config.read(self.config_path) for section in ConfigSection: if not self.config.has_section(section.value): self.config.add_section(section.value) except Exception as e: logger.error(_(F'Could not open config file due to: {e}')) for property_to_add in ConfigManager.PROPERTIES: ConfigManager.add_property(*property_to_add) for progress_status_type in ProgressStatus: name = progress_status_type.value.lower() ConfigManager.add_property(name, ProgressStatus.__name__, bool, True) for entry_type in EntryType: name = entry_type.value.lower() ConfigManager.add_property(name, EntryType.__name__, bool, True) self.read_config()
def start_gui(config): return_code = -1 try: return_code = Application(config, sys.argv).exec_() except Exception as e: logger.critical(_(F'Application failed due to an error: {e}')) finally: sys.exit(return_code)
def __init__(self, default_string=_('No Items')): QListWidget.__init__(self) self.default_string = default_string
def __init__(self, parent): QDialog.__init__(self, parent) self.submitted = False self.cover_bytes = b'' self.setWindowTitle('Add new entry') self.container = QWidget() self.horizontal_layout = QHBoxLayout() self.container_left_layout = QVBoxLayout() self.container_right_layout = QVBoxLayout() self.horizontal_layout.addLayout(self.container_left_layout) self.horizontal_layout.addLayout(self.container_right_layout) label_type = QLabel(_('Entry type:')) self.combo_type = QComboBox() label_type.setBuddy(self.combo_type) for entry in EntryType: self.combo_type.addItem(entry.value, entry) label_status = QLabel(_('Entry status:')) self.combo_status = QComboBox() label_status.setBuddy(self.combo_status) for entry in EntryStatus: self.combo_status.addItem(entry.value, entry) label_progress = QLabel(_('Progress status:')) self.combo_progress = QComboBox() label_progress.setBuddy(self.combo_progress) for entry in ProgressStatus: self.combo_progress.addItem(entry.value, entry) label_org_name = QLabel(_('Entry original name:')) self.line_org_name = QLineEdit() label_org_name.setBuddy(self.line_org_name) label_eng_name = QLabel(_('Entry english name:')) self.line_eng_name = QLineEdit() label_eng_name.setBuddy(self.line_eng_name) label_synonyms = QLabel(_('Synonym names:')) self.line_synonyms = QLineEdit() label_synonyms.setBuddy(self.line_synonyms) label_description = QLabel(_('Description:')) self.description_textbox = QPlainTextEdit() label_description.setBuddy(self.description_textbox) self.nsfw = QCheckBox(_('NSFW')) only_int = QIntValidator(bottom=0) label_current_progress = QLabel(_('Current progress:')) self.current_progress_textbox = QLineEdit() label_current_progress.setBuddy(self.current_progress_textbox) self.current_progress_textbox.setValidator(only_int) label_current_progress.setBuddy(self.current_progress_textbox) label_max_progress = QLabel(_('Max progress:')) self.max_progress_textbox = QLineEdit() label_max_progress.setBuddy(self.max_progress_textbox) self.max_progress_textbox.setValidator(only_int) label_max_progress.setBuddy(self.max_progress_textbox) label_release_date = QLabel(_('Release date:')) self.release_date1 = QDateEdit() self.release_date2 = QDateEdit() label_release_date.setBuddy(self.release_date1) label_release_date.setBuddy(self.release_date2) self.cover = QLabel("Cover:") self.load_cover_button = QPushButton(_('Load cover')) self.load_cover_button.clicked.connect(self.load_image) self.accept_button = QPushButton(_('Add')) self.container_left_layout.addWidget(self.cover) self.container_left_layout.addWidget(self.load_cover_button) self.container_right_layout.addWidget(label_type) self.container_right_layout.addWidget(self.combo_type) self.container_right_layout.addWidget(label_status) self.container_right_layout.addWidget(self.combo_status) self.container_right_layout.addWidget(label_progress) self.container_right_layout.addWidget(self.combo_progress) self.container_right_layout.addWidget(label_org_name) self.container_right_layout.addWidget(self.line_org_name) self.container_right_layout.addWidget(label_eng_name) self.container_right_layout.addWidget(self.line_eng_name) self.container_right_layout.addWidget(label_synonyms) self.container_right_layout.addWidget(self.line_synonyms) self.container_right_layout.addWidget(label_description) self.container_right_layout.addWidget(self.description_textbox) self.container_right_layout.addWidget(self.nsfw) self.container_right_layout.addWidget(label_current_progress) self.container_right_layout.addWidget(self.current_progress_textbox) self.container_right_layout.addWidget(label_max_progress) self.container_right_layout.addWidget(self.max_progress_textbox) self.container_right_layout.addWidget(label_release_date) date_layout = QHBoxLayout() date_layout.addWidget(self.release_date1) date_layout.addWidget(self.release_date2) self.container_right_layout.addLayout(date_layout) self.container_right_layout.addWidget(self.accept_button) self.root_layout = QVBoxLayout(self) self.main_layout = QVBoxLayout(self) self.root_layout.addLayout(self.main_layout) self.container.setLayout(self.horizontal_layout) self.main_layout.addWidget(self.container) self.setLayout(self.root_layout) self.accept_button.clicked.connect(self.submit)