def _init_ui(self): """Initializes the UI""" logging.debug('Initializing AboutDialog defaults') self.grid = QGridLayout() self.grid.setSpacing(10) self.label_empty = QLabel(' ') self.label_author = QLabel(translate('GUI.ABOUT.LABEL.AUTHOR')) self.label_author.setFont(self.font_label) self.label_author_val = QLabel(app_conf_get('author')) self.label_copyright = QLabel(translate('GUI.ABOUT.LABEL.COPYRIGHT')) self.label_copyright.setFont(self.font_label) self.label_copyright_val = QLabel(app_conf_get('copyright')) self.label_version = QLabel(translate('GUI.ABOUT.LABEL.VERSION')) self.label_version.setFont(self.font_label) self.label_version_val = QLabel(app_conf_get('version')) self.label_build = QLabel(translate('GUI.ABOUT.LABEL.BUILD')) self.label_build.setFont(self.font_label) self.label_build_val = QLabel(app_conf_get('build')) if app_conf_get('img_logo_app') is not None: self.label_img = QLabel() self.label_img.setPixmap( app_conf_get('img_logo_app').scaled(280, 80, Qt.KeepAspectRatio, Qt.SmoothTransformation)) curr_gridid = 1 self.grid.addWidget(self.label_img, curr_gridid, 1, 1, 2) curr_gridid += 1 self.grid.addWidget(self.label_empty, curr_gridid, 0, 1, 3) else: curr_gridid = 0 curr_gridid += 1 self.grid.addWidget(self.label_author, curr_gridid, 0) self.grid.addWidget(self.label_author_val, curr_gridid, 1, 1, 3) curr_gridid += 1 self.grid.addWidget(self.label_copyright, curr_gridid, 0) self.grid.addWidget(self.label_copyright_val, curr_gridid, 1, 1, 3) curr_gridid += 1 self.grid.addWidget(self.label_version, curr_gridid, 0) self.grid.addWidget(self.label_version_val, curr_gridid, 1, 1, 3) curr_gridid += 1 self.grid.addWidget(self.label_build, curr_gridid, 0) self.grid.addWidget(self.label_build_val, curr_gridid, 1, 1, 3) self.setLayout(self.grid)
def _select_output_dir(self): """Selects an output directory""" logging.debug('Selecting output directory') self.log(translate('GUI.MAIN.LOG.SELECT_OUTPUT_DIR')) dirname = QFileDialog.getExistingDirectory(self, "Select Directory") if dirname: self.log( translate('GUI.MAIN.LOG.SELECT_OUTPUT_DIR_SUCCESS').format( dirname)) logging.debug('Selected output directory: "{}"'.format(dirname)) self.output_dir = dirname self.edit_output_dir.setText(self.output_dir) else: self.log(translate('GUI.MAIN.LOG.SELECT_OUTPUT_DIR_CANCEL')) logging.debug('Cancelled selecting output directory')
def _select_images(self): """Selects images""" logging.debug('Selecting images') self.log(translate('GUI.MAIN.LOG.SELECT_IMAGES')) filter_mask = 'Image Files (*.jpeg *.jpg *.png)' filenames = QFileDialog.getOpenFileNames( self, translate('GUI.MAIN.DIALOG.SELECT'), './', filter_mask)[0] if filenames: self.log( translate('GUI.MAIN.LOG.SELECT_IMAGES_SUCCESS').format( len(filenames))) for fname in filenames: logging.debug('Selected file name: "{}"'.format(fname)) self._add_to_list(fname) else: self.log(translate('GUI.MAIN.LOG.SELECT_IMAGES_CANCEL').format(0)) logging.debug('Cancelled selecting files')
def _callback_processing_finished(self, img_processed, img_cnt): """The processing callback, on finished :param img_processed: Number of processed images :param img_cnt: Number of images """ logging.debug('Callback: Processing finished') self.log( translate('GUI.MAIN.LOG.DONE_PROCESSING').format( img_processed, img_cnt)) self._reset_enabled()
def init_ui(self): """Initiates about dialog UI""" logging.debug('Initializing AboutDialog GUI') self.setWindowTitle(translate('GUI.ABOUT.TITLE')) self.resize(450, 250) self.font_label = QFont() self.font_label.setBold(True) self.font_label.setPointSize(10) self._center() self._init_ui()
def _init_menu(self): """Initializes the menu bar""" logging.debug('Initializing the menu bar') if platform.uname().system.startswith('Darw'): logging.debug('Platform is Mac OS') self.menu_bar = QMenuBar() else: logging.debug('Platform is not Mac OS') self.menu_bar = self.menuBar() menu_application = self.menu_bar.addMenu( translate('GUI.MAIN.MENU.APPNAME')) action_about = QAction(translate('GUI.MAIN.MENU.ITEM.ABOUT'), self) action_about.setShortcut('Ctrl+A') action_about.triggered.connect(self._show_about_dialog) action_quit = QAction(translate('GUI.MAIN.MENU.ITEM.QUIT'), self) action_quit.setShortcut('Ctrl+Q') action_quit.triggered.connect(self._quit_application) menu_application.addAction(action_about) menu_application.addAction(action_quit)
def init_ui(self): """Initiates application UI""" logging.debug('Initializing MainWindow GUI') self._init_menu() self.setWindowTitle(translate('GUI.MAIN.WINDOW.TITLE')) self.statusbar = self.statusBar() self.mainwidget = MainWidget(log=self.show_message) self.mainwidget.init_ui() self.setCentralWidget(self.mainwidget) self.resize(800, 500) self._center() self._init()
def _start_processing(self): """Starts processing""" logging.debug('Start processing') err = [] if not self.edit_image_size_height.text( ) and not self.edit_image_size_width.text(): err.append(translate('GUI.MAIN.ERROR.IMAGE_SIZE')) if not self.output_dir: err.append(translate('GUI.MAIN.ERROR.NO_OUTPUT_DIR_SELECTED')) if not self.widget_list.current_images: err.append(translate('GUI.MAIN.ERROR.NO_IMAGES_SELECTED')) if err: logging.debug('Errors: {}'.format(err)) msg = '<ul>' for e in err: msg += '<li>{}</li>'.format(e) msg += '</ul>' msgbox = QMessageBox() msgbox.setIcon(QMessageBox.Critical) msgbox.setText(translate('GUI.MAIN.ERROR.START_PROCESSING')) msgbox.setInformativeText(msg) msgbox.setWindowTitle(translate('GUI.MAIN.ERROR.ERROR')) msgbox.exec_() else: self._disable() try: logging.debug('Starting processing') self.log(translate('GUI.MAIN.LOG.START_PROCESSING')) images = self.widget_list.current_images width = int(self.edit_image_size_width.text() ) if self.edit_image_size_width.text() else None height = int(self.edit_image_size_height.text() ) if self.edit_image_size_height.text() else None outdir = self.output_dir thread = ScalerThread( images=images, width=width, height=height, outdir=outdir, createpdf=self.checkbox_create_pdf.isChecked()) thread.signals.scalingresult.connect( self._callback_processing_result) thread.signals.scalingerror.connect( self._callback_processing_error) thread.signals.scalingfinished.connect( self._callback_processing_finished) self.threadpool.start(thread) except Exception as e: logging.debug('Error while scaling: {}'.format(e)) self.log('GUI.MAIN.LOG.ERROR_PROCESSING') self._reset_enabled()
def _get_scaled_img_path(self, path_img): """returns the image name of the scaled image :param path_img: The image path """ try: with open(path_img) as f: fname = os.path.basename(f.name) lindex = fname.rfind('.') newname = fname[:lindex] + translate('SCALED_IMAGE_SUFFIX') suffix = fname[lindex:] logging.debug( 'Output image path: "{}"'.format(self.outdir + "/" + newname + suffix)) return self.outdir + "/" + newname + suffix except Exception as e: logging.error('Error getting path for image "{}": {}'.format( path_img, e)) return None
def __init__(self, path_img, img, widget_list, parent=None): """Initializes the component :param path_img: The image path :param img: The image name :param widget_list: The list widget :param parent: The parent component """ super(ListWidget, self).__init__(parent) self.widget_list = widget_list self.id = str(uuid.uuid4()) self.path_img = path_img label = QLabel("{}".format(img)) button = QPushButton(translate('GUI.MAIN.WIDGET.REMOVE')) button.clicked[bool].connect(self._remove) layout = QHBoxLayout() layout.addWidget(label) layout.addStretch() layout.addWidget(button) self.setLayout(layout)
def _init(self): """Initializes the window""" logging.debug('Initializing MainWindow defaults') self.show_message(translate('GUI.MAIN.LOG.WELCOME_MESSAGE'))
def init_ui(self): """Initiates application UI""" logging.debug('Initializing MainWidget GUI') self.font_label_header = QFont() self.font_label_header.setBold(True) self.font_label_header.setPointSize(10) self.font_label_info = QFont() self.font_label_info.setBold(False) self.font_label_info.setPointSize(9) self.line_css = 'background-color: #c0c0c0;' self.max_img_size_digits = 5 # Components self.label_select_images = QLabel(translate('GUI.MAIN.LABEL.INPUT')) self.label_select_images.setFont(self.font_label_header) self.label_select_images.setAlignment(Qt.AlignCenter) self.line_select_images_1 = QWidget() self.line_select_images_1.setFixedHeight(1) self.line_select_images_1.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.line_select_images_1.setStyleSheet(self.line_css) self.line_select_images_2 = QWidget() self.line_select_images_2.setFixedHeight(1) self.line_select_images_2.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.line_select_images_2.setStyleSheet(self.line_css) self.button_select_images = QPushButton( translate('GUI.MAIN.BUTTON.SELECT_IMAGES')) self.button_select_images.clicked[bool].connect(self._select_images) self.components.append(self.button_select_images) self.label_selected_images = QLabel( translate('GUI.MAIN.LABEL.SELECTED_IMAGES')) self.widget_list = QListWidget() self.widget_list.current_images = [] self.label_settings = QLabel(translate('GUI.MAIN.LABEL.SETTINGS')) self.label_settings.setFont(self.font_label_header) self.label_settings.setAlignment(Qt.AlignCenter) self.line_settings_1 = QWidget() self.line_settings_1.setFixedHeight(1) self.line_settings_1.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.line_settings_1.setStyleSheet(self.line_css) self.line_settings_2 = QWidget() self.line_settings_2.setFixedHeight(1) self.line_settings_2.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.line_settings_2.setStyleSheet(self.line_css) self.label_image_size = QLabel(translate('GUI.MAIN.LABEL.IMAGE_SIZE')) self.label_image_size_width = QLabel( translate('GUI.MAIN.LABEL.IMAGE_SIZE_WIDTH')) self.label_image_size_times = QLabel( translate('GUI.MAIN.LABEL.IMAGE_SIZE_TIMES')) self.label_image_size_height = QLabel( translate('GUI.MAIN.LABEL.IMAGE_SIZE_HEIGHT')) self.edit_image_size_width = QLineEdit() self.edit_image_size_width.setValidator(QIntValidator()) self.edit_image_size_width.setMaxLength(self.max_img_size_digits) self.edit_image_size_width.setText('') self.components.append(self.edit_image_size_width) self.edit_image_size_height = QLineEdit() self.edit_image_size_height.setValidator(QIntValidator()) self.edit_image_size_height.setMaxLength(self.max_img_size_digits) self.edit_image_size_height.setText('') self.components.append(self.edit_image_size_height) self.label_image_size_info = QLabel( translate('GUI.MAIN.LABEL.IMAGE_SIZE_INFO')) self.label_image_size_info.setFont(self.font_label_info) self.label_output_dir = QLabel(translate('GUI.MAIN.LABEL.OUTPUT_DIR')) self.edit_output_dir = QLineEdit() self.edit_output_dir.setText(self.output_dir) self.edit_output_dir.setEnabled(False) self.button_output_dir = QPushButton( translate('GUI.MAIN.BUTTON.SELECT_OUTPUT_DIR')) self.button_output_dir.clicked[bool].connect(self._select_output_dir) self.components.append(self.button_output_dir) self.label_pdf = QLabel(translate('GUI.MAIN.LABEL.PDF')) self.checkbox_create_pdf = QCheckBox( translate('GUI.MAIN.CHECKBOX.CHECKBOX_CREATE_PDF')) self.checkbox_create_pdf.setChecked(True) self.components.append(self.checkbox_create_pdf) self.label_process = QLabel(translate('GUI.MAIN.LABEL.PROCESS')) self.label_process.setFont(self.font_label_header) self.label_process.setAlignment(Qt.AlignCenter) self.line_process_1 = QWidget() self.line_process_1.setFixedHeight(1) self.line_process_1.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.line_process_1.setStyleSheet(self.line_css) self.line_process_2 = QWidget() self.line_process_2.setFixedHeight(1) self.line_process_2.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.line_process_2.setStyleSheet(self.line_css) self.button_process = QPushButton(translate('GUI.MAIN.BUTTON.PROCESS')) self.button_process.clicked[bool].connect(self._start_processing) self.components.append(self.button_process) # Layout self.grid = QGridLayout() self.grid.setSpacing(10) # self.grid.addWidget(widget, row, column, rowspan, columnspan) curr_gridid = 1 self.grid.addWidget(self.line_select_images_1, curr_gridid, 0, 1, 4) self.grid.addWidget(self.label_select_images, curr_gridid, 4, 1, 2) self.grid.addWidget(self.line_select_images_2, curr_gridid, 6, 1, 4) curr_gridid += 1 self.grid.addWidget(self.button_select_images, curr_gridid, 0, 1, 10) curr_gridid += 1 self.grid.addWidget(self.label_selected_images, curr_gridid, 0, 1, 10) curr_gridid += 1 self.grid.addWidget(self.widget_list, curr_gridid, 0, 1, 10) curr_gridid += 1 self.grid.addWidget(self.line_settings_1, curr_gridid, 0, 1, 4) self.grid.addWidget(self.label_settings, curr_gridid, 4, 1, 2) self.grid.addWidget(self.line_settings_2, curr_gridid, 6, 1, 4) curr_gridid += 1 self.grid.addWidget(self.label_image_size, curr_gridid, 0, 1, 1) self.grid.addWidget(self.edit_image_size_width, curr_gridid, 1, 1, 3) self.grid.addWidget(self.label_image_size_width, curr_gridid, 4, 1, 1) self.grid.addWidget(self.label_image_size_times, curr_gridid, 5, 1, 1) self.grid.addWidget(self.edit_image_size_height, curr_gridid, 6, 1, 3) self.grid.addWidget(self.label_image_size_height, curr_gridid, 9, 1, 1) curr_gridid += 1 self.grid.addWidget(self.label_image_size_info, curr_gridid, 1, 1, 9) curr_gridid += 1 self.grid.addWidget(self.label_output_dir, curr_gridid, 0, 1, 1) self.grid.addWidget(self.edit_output_dir, curr_gridid, 1, 1, 7) self.grid.addWidget(self.button_output_dir, curr_gridid, 8, 1, 2) curr_gridid += 1 self.grid.addWidget(self.label_pdf, curr_gridid, 0, 1, 1) self.grid.addWidget(self.checkbox_create_pdf, curr_gridid, 1, 1, 9) curr_gridid += 1 self.grid.addWidget(self.line_process_1, curr_gridid, 0, 1, 4) self.grid.addWidget(self.label_process, curr_gridid, 4, 1, 2) self.grid.addWidget(self.line_process_2, curr_gridid, 6, 1, 4) curr_gridid += 1 self.grid.addWidget(self.button_process, curr_gridid, 0, 1, 10) self.setLayout(self.grid) self._reset_enabled()