def __init__(self, image_list, parent=None): super(TabWidget, self).__init__(parent) self.app = QtWidgets.QApplication.instance() self.app.aboutToQuit.connect(self.stop_copy) if gp and self.app.options.test: self.gp_log = gp.check_result(gp.use_python_logging()) self.config_store = self.app.config_store self.image_list = image_list self.setLayout(QtWidgets.QGridLayout()) form = QtWidgets.QFormLayout() form.setFieldGrowthPolicy(QtWidgets.QFormLayout.AllNonFixedFieldsGrow) self.nm = NameMangler() self.file_data = {} self.file_list = [] self.source = None self.file_copier = None self.updating = QtCore.QMutex() # source selector box = QtWidgets.QHBoxLayout() box.setContentsMargins(0, 0, 0, 0) self.source_selector = QtWidgets.QComboBox() self.source_selector.currentIndexChanged.connect(self.new_source) self.source_selector.setContextMenuPolicy(Qt.CustomContextMenu) self.source_selector.customContextMenuRequested.connect( self.remove_folder) box.addWidget(self.source_selector) refresh_button = QtWidgets.QPushButton( translate('ImporterTab', 'refresh')) refresh_button.clicked.connect(self.refresh) box.addWidget(refresh_button) box.setStretch(0, 1) form.addRow(translate('ImporterTab', 'Source'), box) # update config self.config_store.delete('importer', 'folders') for section in self.config_store.config.sections(): if not section.startswith('importer'): continue path_format = self.config_store.get(section, 'path_format') if not (path_format and '(' in path_format): continue path_format = path_format.replace('(', '{').replace(')', '}') self.config_store.set(section, 'path_format', path_format) # path format self.path_format = QtWidgets.QLineEdit() self.path_format.setValidator(PathFormatValidator()) self.path_format.textChanged.connect(self.nm.new_format) self.path_format.editingFinished.connect(self.path_format_finished) form.addRow(translate('ImporterTab', 'Target format'), self.path_format) # path example self.path_example = QtWidgets.QLabel() self.nm.new_example.connect(self.path_example.setText) form.addRow('=>', self.path_example) self.layout().addLayout(form, 0, 0) # file list self.file_list_widget = QtWidgets.QListWidget() self.file_list_widget.setSelectionMode( QtWidgets.QAbstractItemView.ExtendedSelection) self.file_list_widget.itemSelectionChanged.connect( self.selection_changed) self.layout().addWidget(self.file_list_widget, 1, 0) # selection buttons buttons = QtWidgets.QVBoxLayout() buttons.addStretch(1) self.selected_count = QtWidgets.QLabel() buttons.addWidget(self.selected_count) select_all = QtWidgets.QPushButton( translate('ImporterTab', 'Select\nall')) select_all.clicked.connect(self.select_all) buttons.addWidget(select_all) select_new = QtWidgets.QPushButton( translate('ImporterTab', 'Select\nnew')) select_new.clicked.connect(self.select_new) buttons.addWidget(select_new) # copy buttons self.move_button = StartStopButton( translate('ImporterTab', 'Move\nphotos'), translate('ImporterTab', 'Stop\nmove')) self.move_button.click_start.connect(self.move_selected) self.move_button.click_stop.connect(self.stop_copy) buttons.addWidget(self.move_button) self.copy_button = StartStopButton( translate('ImporterTab', 'Copy\nphotos'), translate('ImporterTab', 'Stop\ncopy')) self.copy_button.click_start.connect(self.copy_selected) self.copy_button.click_stop.connect(self.stop_copy) buttons.addWidget(self.copy_button) self.layout().addLayout(buttons, 0, 1, 2, 1) self.selection_changed() # final initialisation self.image_list.sort_order_changed.connect(self.sort_file_list) path = QtCore.QStandardPaths.writableLocation( QtCore.QStandardPaths.PicturesLocation) self.path_format.setText(os.path.join(path, '%Y', '%Y_%m_%d', '{name}'))
def __init__(self, image_list, parent=None): super(TabWidget, self).__init__(parent) app = QtWidgets.QApplication.instance() app.aboutToQuit.connect(self.shutdown) if gp and app.test_mode: self.gp_log = gp.check_result(gp.use_python_logging()) self.config_store = app.config_store self.image_list = image_list self.setLayout(QtWidgets.QGridLayout()) form = QtWidgets.QFormLayout() form.setFieldGrowthPolicy(QtWidgets.QFormLayout.AllNonFixedFieldsGrow) self.nm = NameMangler() self.file_data = {} self.file_list = [] self.source = None self.file_reader = None self.file_writer = None # source selector box = QtWidgets.QHBoxLayout() box.setContentsMargins(0, 0, 0, 0) self.source_selector = QtWidgets.QComboBox() self.source_selector.currentIndexChanged.connect(self.new_source) box.addWidget(self.source_selector) refresh_button = QtWidgets.QPushButton(self.tr('refresh')) refresh_button.clicked.connect(self.refresh) box.addWidget(refresh_button) box.setStretch(0, 1) form.addRow(self.tr('Source'), box) # path format self.path_format = QtWidgets.QLineEdit() self.path_format.setValidator(PathFormatValidator()) self.path_format.textChanged.connect(self.nm.new_format) self.path_format.editingFinished.connect(self.path_format_finished) form.addRow(self.tr('Target format'), self.path_format) # path example self.path_example = QtWidgets.QLabel() self.nm.new_example.connect(self.path_example.setText) form.addRow('=>', self.path_example) self.layout().addLayout(form, 0, 0) # file list self.file_list_widget = QtWidgets.QListWidget() self.file_list_widget.setSelectionMode( QtWidgets.QAbstractItemView.ExtendedSelection) self.file_list_widget.itemSelectionChanged.connect(self.selection_changed) self.layout().addWidget(self.file_list_widget, 1, 0) # selection buttons buttons = QtWidgets.QVBoxLayout() buttons.addStretch(1) self.selected_count = QtWidgets.QLabel() self.selection_changed() buttons.addWidget(self.selected_count) select_all = QtWidgets.QPushButton(self.tr('Select\nall')) select_all.clicked.connect(self.select_all) buttons.addWidget(select_all) select_new = QtWidgets.QPushButton(self.tr('Select\nnew')) select_new.clicked.connect(self.select_new) buttons.addWidget(select_new) self.copy_button = StartStopButton(self.tr('Copy\nphotos'), self.tr('Stop\nimport')) self.copy_button.click_start.connect(self.copy_selected) self.copy_button.click_stop.connect(self.stop_copy) buttons.addWidget(self.copy_button) self.layout().addLayout(buttons, 0, 1, 2, 1) # final initialisation self.image_list.sort_order_changed.connect(self.sort_file_list) path = os.path.expanduser('~/Pictures') if not os.path.isdir(path) and sys.platform == 'win32': try: import win32com.shell as ws path = ws.shell.SHGetFolderPath( 0, ws.shellcon.CSIDL_MYPICTURES, None, 0) except ImportError: pass self.path_format.setText( os.path.join(path, '%Y', '%Y_%m_%d', '{name}')) self.refresh() self.list_files()
def __init__(self, image_list, parent=None): super(TabWidget, self).__init__(parent) app = QtWidgets.QApplication.instance() app.aboutToQuit.connect(self.shutdown) if gp and app.test_mode: self.gp_log = gp.check_result(gp.use_python_logging()) self.config_store = app.config_store self.image_list = image_list self.setLayout(QtWidgets.QGridLayout()) form = QtWidgets.QFormLayout() form.setFieldGrowthPolicy(QtWidgets.QFormLayout.AllNonFixedFieldsGrow) self.nm = NameMangler() self.file_data = {} self.file_list = [] self.source = None self.file_copier = None # source selector box = QtWidgets.QHBoxLayout() box.setContentsMargins(0, 0, 0, 0) self.source_selector = QtWidgets.QComboBox() self.source_selector.currentIndexChanged.connect(self.new_source) box.addWidget(self.source_selector) refresh_button = QtWidgets.QPushButton(self.tr('refresh')) refresh_button.clicked.connect(self.refresh) box.addWidget(refresh_button) box.setStretch(0, 1) form.addRow(self.tr('Source'), box) # path format self.path_format = QtWidgets.QLineEdit() self.path_format.setValidator(PathFormatValidator()) self.path_format.textChanged.connect(self.nm.new_format) self.path_format.editingFinished.connect(self.path_format_finished) form.addRow(self.tr('Target format'), self.path_format) # path example self.path_example = QtWidgets.QLabel() self.nm.new_example.connect(self.path_example.setText) form.addRow('=>', self.path_example) self.layout().addLayout(form, 0, 0) # file list self.file_list_widget = QtWidgets.QListWidget() self.file_list_widget.setSelectionMode( QtWidgets.QAbstractItemView.ExtendedSelection) self.file_list_widget.itemSelectionChanged.connect( self.selection_changed) self.layout().addWidget(self.file_list_widget, 1, 0) # selection buttons buttons = QtWidgets.QVBoxLayout() buttons.addStretch(1) self.selected_count = QtWidgets.QLabel() buttons.addWidget(self.selected_count) select_all = QtWidgets.QPushButton(self.tr('Select\nall')) select_all.clicked.connect(self.select_all) buttons.addWidget(select_all) select_new = QtWidgets.QPushButton(self.tr('Select\nnew')) select_new.clicked.connect(self.select_new) buttons.addWidget(select_new) # copy buttons self.move_button = StartStopButton(self.tr('Move\nphotos'), self.tr('Stop\nmove')) self.move_button.click_start.connect(self.move_selected) self.move_button.click_stop.connect(self.stop_copy) buttons.addWidget(self.move_button) self.copy_button = StartStopButton(self.tr('Copy\nphotos'), self.tr('Stop\ncopy')) self.copy_button.click_start.connect(self.copy_selected) self.copy_button.click_stop.connect(self.stop_copy) buttons.addWidget(self.copy_button) self.layout().addLayout(buttons, 0, 1, 2, 1) self.selection_changed() # final initialisation self.image_list.sort_order_changed.connect(self.sort_file_list) if qt_version_info >= (5, 0): path = QtCore.QStandardPaths.writableLocation( QtCore.QStandardPaths.PicturesLocation) else: path = QtGui.QDesktopServices.storageLocation( QtGui.QDesktopServices.PicturesLocation) self.path_format.setText(os.path.join(path, '%Y', '%Y_%m_%d', '{name}')) self.refresh() self.list_files()