def docomplete(self, data): """Completes the file with the new data""" self.progress.setLabelText(self.tr("Autocomplete running (Step 3/3)")) # self.progress.setCancelButton(0) if isinstance(data, list): # TODO allow multiple values if len(data) == 0: self.progress.hide() return data = data[0] if not isinstance(data, dict): self.progress.hide() raise ValueError("Expected dict found *%s*", type(data)) Collector.get_instance().complete(self.collection.get_id(), self.obj["id"], data) self.progress.hide() self.parent().display_view("fitxa", params={"item": self.obj["id"], "collection": self.collection.get_id()})
def saveandclose(self): """Saves unsaved data and closes""" config = Collector.get_instance().get_manager('config') config.set('lang', self.codes[self.lang_combo.currentIndex()]) config.set('copy', self.copy_dict[self.copy_combo.currentText()]) config.save() self.close()
def __init__(self, parent, flags=None): """ Creates a new dialog to render the application preferences""" if flags is None: flags = QtCore.Qt.WindowFlags(0) super(Ui_Preferences, self).__init__(parent, flags) self.manager = Collector.get_instance().get_manager("plugin") self.current_lang = None self.codes = [":system:", 'ca_ES', 'en_UK', 'es_ES'] self.setupUi()
def setupUi(self): """Creates the ui elements for the preferences. This function overrides the Ui_Form function creating thinks that aren't easy to do with the QT Designer""" super(Ui_Preferences, self).setupUi(self) self.refresh() self.connect( self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), self.saveandclose) self.connect( self.b_disable, QtCore.SIGNAL(_fromUtf8("clicked()")), self.disable) self.connect( self.b_enable, QtCore.SIGNAL(_fromUtf8("clicked()")), self.enable) # Language selector self.current_lang = Collector.get_instance().conf('lang') if not self.current_lang is None: index = 1 try: index = self.codes.index(str(self.current_lang)) except ValueError: index = 1 self.lang_combo.setCurrentIndex(index) # Copy file self.copy = Collector.get_instance().conf('copy') self.copy_dict = { self.tr("Always"): "always", self.tr("Never"): "never", self.tr("Remote only"): "http" } index = 0 for i in self.copy_dict.items(): self.copy_combo.addItem(i[0]) if i[1] == self.copy: self.copy_combo.setCurrentIndex(index) index += 1 self.home.setText(_fromUtf8(Collector.get_instance().conf('home')))
def __init__(self, query, results, parent, collection=None, flags=None): """ Creates a new search view""" if flags is None: flags = QtCore.Qt.WindowFlags(0) super(Ui_Search, self).__init__(parent, flags) self.results = [] self.collection = None collections = Collector.get_instance().get_manager('collection') if collection is not None: self.collection = collections.get_collection(collection) self.pretty = self.collection.schema.default self.query = query if results is None: results = [] self.setupUi(query, results)
def run(self): """The run function""" collector = Collector.get_instance() results = [] while not self.queue.empty(): i = self.queue.get() try: file_ = collector.get_plugin_file( i['id'], i['plugin'], ) results.append(file_) except Exception as e: logging.exception(e) self.queue.task_done() # q.join() self.complete.emit(results)
def run(self): collector = Collector.get_instance() try: results = collector.get_plugin_file( self.uri, self.plugin_id ) self.load_complete.emit(WorkerResult(STATUS_OK, results)) except Exception as e: logging.exception(e) self.load_complete.emit( WorkerResult( STATUS_ERROR, msg="Plugin %s file load failed with uri %s" % (self.plugin_id, self.uri) ) )
def __init__(self, parent=None): super(CSVFileSelector, self).__init__() self.file = None self.collection = None # Creating ui elements self.resize(400, 135) self.setWindowTitle(self.tr("Select a CSV")) self.setObjectName(QStringU8("CSVFileSelector")) self.mainlayout = QtGui.QHBoxLayout(self) self.icon = QtGui.QLabel() self.icon.setPixmap(QtGui.QPixmap(':/csvbgg.png')) self.mainlayout.addWidget(self.icon) self.layout = QtGui.QVBoxLayout() self.label = QtGui.QLabel(self.tr( QStringU8("Select the CSV file to import:"))) self.layout.addWidget(self.label) self.file_selector = FileSelector(self, 'CSV (*.csv)') self.layout.addWidget(self.file_selector) self.label2 = QtGui.QLabel(self.tr( QStringU8("To the folder:"))) self.layout.addWidget(self.label2) self.collections = QtGui.QComboBox() self.layout.addWidget(self.collections) self.mainlayout.addLayout(self.layout) self.options = QtGui.QDialogButtonBox(self) self.options.setOrientation(QtCore.Qt.Horizontal) self.options.setStandardButtons(QtGui.QDialogButtonBox.Cancel | QtGui.QDialogButtonBox.Ok) self.options.setObjectName(QStringU8("options")) self.layout.addWidget(self.options) # Add collections to the combo box man = Collector.get_instance().get_manager('collection') for i in man.collections.values(): self.collections.addItem(i.get_name(), i.get_id()) # Connect things self.options.rejected.connect(self.reject) self.options.accepted.connect(self.accept)
def add_to_my_collection(self): """Add the current plugin file to the user collection""" if self.data is not None: self.progress = QtGui.QProgressDialog( self.tr("Saving"), QtCore.QString(), 0, 0) self.progress.show() collector = Collector.get_instance() result = collector.add( self.data, self.collection, use_mapping=self.plugin.get_id()) self.progress.hide() if result is not None: # Ok case # TODO ask the user if want's to see the # added file or not id_ = result.id self.parent().display_view( 'fitxa', {'item': id_, 'collection': self.collection} ) else: # Error case QtGui.QMessageBox.warning( self, self.tr("Collector"), self.tr("Ooops, an error ocurred" + " and no data couldn't be added.")) else: # Trying to add not ready content. QtGui.QMessageBox.warning( self, self.tr("Collector"), self.tr("The content isn't yet available," + " and no data couldn't be added."))
def run(self): self.stopworking = False #Open file reader = csv.reader(open(self.path)) # Check header and read rows (each row is a collection file) if not self.check_first_row(reader): self.error.emit(self.tr("The CSV isn't from Boardgamegeek")) return files = [] count = 0 # We need the count of rows for the dialog progress for row in reader: files.append(row) count += 1 # Emit end of the first step (read file) self.csvreaded.emit(count) # Add the collections files to the deseired collection i = 1 id = self.bgg_csv_schema.index('objectid') man = Collector.get_instance() for item in files: html = self.provider.get(item[id]) try: data = self.plugin.file_filter(html) data['originalname'] = data['title'] data['title'] = unicode(item[0], 'utf-8') # TODO collection id must be a parameter man.add(data, 'boardgames', 'PluginCsvImport') # TODO add user values and csv-only values # from PyQt4.Qt import qDebug; qDebug(unicode(data)) except Exception as e: logging.exception(e) self.provider.flush() self.filecreated.emit(i) if self.stopworking: return i += 1
def run(self): collector = Collector.get_instance() plugins = collector.get_manager('plugin').filter(PluginCollector) logging.debug("Discover using: " + str(plugins)) # Call discover for all the plugins all_results = [] for plugin in plugins: try: results = collector.discover(self.params['query'], plugin) self.partialResult.emit(results) all_results.extend(results) except Exception as e: logging.debug(e) self.searchComplete.emit( WorkerResult( STATUS_ERROR, msg="Plugin %s has failed" % plugin ) ) # TODO continue when a plugin has failed return # Launch the complete self.searchComplete.emit(WorkerResult(STATUS_OK, all_results))
def run(self): self.error = None collector = Collector.get_instance() self.results = collector.filter(self.params['collection'], [self.params['filter']]) self.searchComplete.emit(WorkerResult(STATUS_OK, self.results))