def open_images(self): self.clear_thumb_images() data_len = len(self.DATA) if self.NUM_DATA_BEGIN >= data_len: # Sono già state visualizzate tutte le immagini self.NUM_DATA_BEGIN = 0 self.NUM_DATA_END = 25 elif self.NUM_DATA_BEGIN <= data_len: # indica che non sono state visualizzate tutte le immagini data = self.DATA[self.NUM_DATA_BEGIN:self.NUM_DATA_END] for i in range(len(data)): item = QListWidgetItem(str(data[i].id_media)) # data_for_thumb = self.db_search_check(self.MAPPER_TABLE_CLASS_thumb, 'id_media', id_media) # recupera i valori della thumb in base al valore id_media del file originale thumb_path = data[i].filepath # QMessageBox.warning(self, "Errore",str(thumb_path), QMessageBox.Ok) item.setData(Qt.UserRole, str(data[i].media_filename)) icon = QIcon( thumb_path ) # os.path.join('%s/%s' % (directory.toUtf8(), image))) item.setIcon(icon) self.iconListWidget.addItem(item)
def loadColumns(self, table): # Load textual and spatial (if available) columns # Get spatial columns first spColumns = table_column_names(table, True, creation_order=True) self.cboSpatialCols_2.clear() self.cboSpatialCols_2.addItems(spColumns) # Textual Columns self.lstSrcCols_2.clear() self.allCols = table_column_names(table, creation_order=True) for sc in spColumns: colIndex = getIndex(self.allCols, sc) if colIndex != -1: self.allCols.remove(sc) for col in self.allCols: if ' ' in col: col = '"{}"'.format(col) tabItem = QListWidgetItem(col, self.lstSrcCols_2) tabItem.setCheckState(Qt.Unchecked) tabItem.setIcon(GuiUtils.get_icon("column.png")) self.lstSrcCols_2.addItem(tabItem) if len(spColumns) > 0: self.cboSpatialCols_2.setEnabled(True)
def assignCols(self): # Load source and target columns respectively srcCols = self._source_columns() for c in srcCols: srcItem = QListWidgetItem(c, self.lstSrcFields) srcItem.setCheckState(Qt.Unchecked) srcItem.setIcon(GuiUtils.get_icon("column.png")) self.lstSrcFields.addItem(srcItem) # Destination Columns tabIndex = int(self.field("tabIndex")) self.targetTab = self.destCheckedItem.text() targetCols = table_column_names(self.targetTab, False, True) # Remove geometry columns in the target columns list for gc in self.geomcols: colIndex = getIndex(targetCols, gc) if colIndex != -1: targetCols.remove(gc) # Remove 'id' column if there id_idx = getIndex(targetCols, 'id') if id_idx != -1: targetCols.remove('id') self._add_target_table_columns(targetCols)
def add_item(self, title, icon): """ Add item to the dialog's list of options """ item = QListWidgetItem(title) item.setIcon(QIcon(icon)) self.dlg.uListOptions.addItem(item)
def loadSourceTables(self): # Load all STDM tables self.lstSrcTab.clear() # tables = pg_tables() tables = profile_user_tables(self.curr_profile, True, True, sort=True) for t in tables.keys(): tabItem = QListWidgetItem(t, self.lstSrcTab) tabItem.setIcon(GuiUtils.get_icon("table.png")) self.lstSrcTab.addItem(tabItem)
def init(self, lesson): self.listSteps.clear() self.lesson = lesson bulletIcon = QIcon(os.path.dirname(__file__) + '/bullet.png') for step in lesson.steps: item = QListWidgetItem(step.name) self.listSteps.addItem(item) item.setHidden(step.steptype == Step.AUTOMATEDSTEP) item.setIcon(bulletIcon) self.currentStep = 0 self.lessonNameLabel.setText("<b>Current lesson:</b> %s" % lesson.name) self.moveToNextStep()
def refresh_available(self): ''' Method for refreshing dialog list widget with available GooGIS layers ''' self.myDrive.configure_service() self.available_sheets = self.myDrive.list_files( orderBy=self.dlg.orderByCombo.itemData( self.dlg.orderByCombo.currentIndex())) logger("refreshing panel") try: self.dlg.listWidget.currentItemChanged.disconnect( self.viewMetadata) except: pass self.dlg.listWidget.clear() self.dlg.writeListTextBox.clear() self.dlg.readListTextBox.clear() sharedIconOwner = QIcon(os.path.join(self.plugin_dir, 'shared.png')) anyoneIconOwner = QIcon(os.path.join(self.plugin_dir, 'globe.png')) sharedIcon = QIcon(os.path.join(self.plugin_dir, 'shared_gray.png')) anyoneIcon = QIcon(os.path.join(self.plugin_dir, 'globe_gray.png')) nullIcon = QIcon(os.path.join(self.plugin_dir, 'null.png')) for sheet_name, sheet_metadata in self.available_sheets.items(): if sheet_metadata["id"] != self.myDrive.credentials.pubDbId: newItem = QListWidgetItem(QIcon(), sheet_name, self.dlg.listWidget, QListWidgetItem.UserType) if not sheet_metadata["capabilities"]["canEdit"]: font = newItem.font() font.setItalic(True) newItem.setFont(font) #if sheet in shared_sheets.keys(): permissions = self.get_permissions(sheet_metadata) owners_list = [ owner["emailAddress"] for owner in sheet_metadata['owners'] ] if 'anyone' in permissions: if self.client_id in owners_list: newItem.setIcon(anyoneIconOwner) else: newItem.setIcon(anyoneIcon) elif permissions != {}: if self.client_id in owners_list: newItem.setIcon(sharedIconOwner) else: newItem.setIcon(sharedIcon) else: newItem.setIcon(nullIcon) #newItem.setIcon(QIcon(os.path.join(self.plugin_dir,'shared.png'))) #newItem.setText(sheet) self.dlg.listWidget.addItem(newItem) self.dlg.listWidget.currentItemChanged.connect(self.viewMetadata)
def loadTables(self, type): # Load textual or spatial tables self.lstDestTables.clear() tables = None if type == "textual": tables = profile_user_tables(self.curr_profile, False, True) elif type == "spatial": tables = profile_spatial_tables(self.curr_profile) if tables is not None: for t in tables: tabItem = QListWidgetItem(t, self.lstDestTables) tabItem.setCheckState(Qt.Unchecked) tabItem.setIcon(GuiUtils.get_icon("table.png")) self.lstDestTables.addItem(tabItem)
def init(self, lesson): self.resetGui() self.listSteps.clear() self.lesson = lesson bulletIcon = QIcon(os.path.dirname(__file__) + "/bullet.png") for step in lesson.steps: item = QListWidgetItem(step.name) self.listSteps.addItem(item) item.setHidden(step.steptype == Step.AUTOMATEDSTEP) item.setIcon(bulletIcon) self.currentStep = 0 self.lessonNameLabel.setText("<b>Current lesson:</b> {}".format(lesson.name)) self.btnMove.setText(self.tr("Next step")) self.btnMove.setToolTip(self.tr("Move to next step")) self.moveToNextStep()
def set_layer(self, layer: QgsVectorLayer): self.layer = layer self.clear() for field in self.layer.fields(): cell = QListWidgetItem() alias = field.alias() if not alias: cell.setText(field.name()) else: cell.setText("{} ({})".format(field.name(), alias)) cell.setData(Qt.UserRole, field.name()) index = layer.fields().indexFromName(field.name()) if index >= 0: cell.setIcon(self.layer.fields().iconForField(index)) self.addItem(cell)
def set_project(self, project: QgsProject) -> None: self.project = project self.clear() for layer in self.project.mapLayers().values(): if layer.type() != QgsMapLayer.VectorLayer: continue if not layer.isSpatial(): continue cell = QListWidgetItem() cell.setText(layer.name()) cell.setData(Qt.UserRole, layer.id()) cell.setIcon(QgsMapLayerModel.iconForLayer(layer)) self.addItem(cell)
def assignCols(self): # Load source and target columns respectively source_columns = self._source_columns() # Destination Columns self.targetTab = self.selected_destination_table() target_columns = table_column_names(self.targetTab, False, True) # Remove geometry columns and 'id' column in the target columns list target_columns = [c for c in target_columns if c not in self.geom_cols and c != 'id'] # now synchronize the lists, as much as possible # this consists of moving columns with matching names in the source and target lists to the same # placement at the top of the lists, and filtering out lists of remaining unmatched columns matched_source_columns = [] unmatched_source_columns = source_columns[:] matched_target_columns = [] unmatched_target_columns = target_columns[:] for source in source_columns: for target in unmatched_target_columns: if ImportData.names_are_matching(source, target): matched_source_columns.append(source) unmatched_source_columns = [c for c in unmatched_source_columns if c != source] matched_target_columns.append(target) unmatched_target_columns = [c for c in unmatched_target_columns if c != target] break # any matching columns get added to the start of the lists, and unmatched get added # to the end of the list for c in matched_source_columns + unmatched_source_columns: src_item = QListWidgetItem(c, self.lstSrcFields) # automatically check any columns we could match src_item.setCheckState(Qt.Checked if c in matched_source_columns else Qt.Unchecked) src_item.setIcon(GuiUtils.get_icon("column.png")) self.lstSrcFields.addItem(src_item) self._add_target_table_columns(matched_target_columns + unmatched_target_columns)
def load_tables_of_type(self, type: str, initial_selection: Optional[str] = None): """ Load textual or spatial tables If initial_selection is specified then that table will be initially checked """ self.lstDestTables.clear() tables = None if type == "textual": tables = profile_user_tables(self.curr_profile, False, True, include_read_only=False) elif type == "spatial": tables = profile_spatial_tables(self.curr_profile, include_read_only=False) if tables is not None: for table_name, table_label in tables.items(): table_item = QListWidgetItem(table_label, self.lstDestTables) table_item.setData(ImportData.ROLE_TABLE_NAME, table_name) if initial_selection: table_item.setCheckState( Qt.Checked if ImportData.names_are_matching(table_name, initial_selection) else Qt.Unchecked) else: table_item.setCheckState(Qt.Unchecked) table_item.setIcon(GuiUtils.get_icon("table.png")) self.lstDestTables.addItem(table_item)
def getDirectory(self): directory = QFileDialog.getExistingDirectory( self, "Scegli una directory", "Seleziona una directory:", QFileDialog.ShowDirsOnly) if not directory: return QMessageBox.warning(self, "Alert", str(dir(directory)), QMessageBox.Ok) for image in sorted(os.listdir(directory)): if image.endswith(".png") or image.endswith( ".PNG") or image.endswith(".JPG") or image.endswith( ".jpg") or image.endswith(".jpeg") or image.endswith( ".JPEG") or image.endswith( ".tif") or image.endswith( ".TIF") or image.endswith( ".tiff") or image.endswith(".TIFF"): filename, filetype = image.split(".")[0], image.split(".")[ 1] # db definisce nome immagine originale filepath = directory + '/' + filename + "." + filetype # db definisce il path immagine originale idunique_image_check = self.db_search_check( self.MAPPER_TABLE_CLASS, 'filepath', filepath ) # controlla che l'immagine non sia già presente nel db sulla base del suo path if not bool(idunique_image_check): mediatype = 'image' # db definisce il tipo di immagine originale self.insert_record_media( mediatype, filename, filetype, filepath ) # db inserisce i dati nella tabella media originali MU = Media_utility() conn = Connection() media_max_num_id = self.DB_MANAGER.max_num_id( self.MAPPER_TABLE_CLASS, self.ID_TABLE ) # db recupera il valore più alto ovvero l'ultimo immesso per l'immagine originale thumb_path = conn.thumb_path() thumb_path_str = thumb_path['thumb_path'] media_thumb_suffix = '_pay.png' filenameorig = filename filename_thumb = str( media_max_num_id) + "_" + filename + media_thumb_suffix filepath_thumb = thumb_path_str + filename_thumb # crea la thumbnail try: MU.resample_images(media_max_num_id, filepath, filenameorig, thumb_path_str, media_thumb_suffix) except Exception as e: QMessageBox.warning(self, "Cucu", str(e), QMessageBox.Ok) # inserisce i dati nel DB self.insert_record_mediathumb(media_max_num_id, mediatype, filename, filename_thumb, filetype, filepath_thumb) # visualizza le immagini nella ui item = QListWidgetItem(str(media_max_num_id)) item.setData(Qt.UserRole, str(media_max_num_id)) icon = QIcon( filepath_thumb ) # os.path.join('%s/%s' % (directory.toUtf8(), image))) item.setIcon(icon) self.iconListWidget.addItem(item) elif bool(idunique_image_check): # recupero il valore id_media basato sul path dell'immagine data = idunique_image_check id_media = data[0].id_media # visualizza le immagini nella ui item = QListWidgetItem(str(id_media)) data_for_thumb = self.db_search_check( self.MAPPER_TABLE_CLASS_thumb, 'id_media', id_media ) # recupera i valori della thumb in base al valore id_media del file originale thumb_path = data_for_thumb[0].filepath item.setData(Qt.UserRole, thumb_path) icon = QIcon( thumb_path ) # os.path.join('%s/%s' % (directory.toUtf8(), image))) item.setIcon(icon) self.iconListWidget.addItem(item)
def __init__(self, parent=None): """Constructor. :param parent: Optional widget to use as parent :type parent: QWidget :param iface: An instance of QGisInterface :type iface: QGisInterface """ super(ResourceSharingDialog, self).__init__(parent) self.setupUi(self) # Reconfigure UI self.setWindowTitle(f"{__title__} - {__version__}") self.setModal(True) self.button_edit.setEnabled(False) self.button_delete.setEnabled(False) self.button_install.setEnabled(False) self.button_open.setEnabled(False) self.button_uninstall.setEnabled(False) # Set up the "main menu" - QListWidgetItem # All collections icon_all = QIcon() icon_all.addFile(str(resources_path("img", "plugin.svg")), QSize(), QIcon.Normal, QIcon.Off) item_all = QListWidgetItem() item_all.setIcon(icon_all) item_all.setText(self.tr("All collections")) # Installed collections icon_installed = QIcon() icon_installed.addFile( str(resources_path("img", "plugin-installed.svg")), QSize(), QIcon.Normal, QIcon.Off, ) item_installed = QListWidgetItem() item_installed.setIcon(icon_installed) item_installed.setText(self.tr("Installed collections")) item_all.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) # Settings / repositories icon_settings = QIcon() icon_settings.addFile(str(resources_path("img", "settings.svg")), QSize(), QIcon.Normal, QIcon.Off) item_settings = QListWidgetItem() item_settings.setIcon(icon_settings) item_settings.setText(self.tr("Settings")) item_all.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) # Add the items to the list widget self.menu_list_widget.addItem(item_all) self.menu_list_widget.addItem(item_installed) self.menu_list_widget.addItem(item_settings) # Init the message bar self.message_bar = QgsMessageBar(self) self.message_bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) self.vlayoutRightColumn.insertWidget(0, self.message_bar) # Progress dialog for long running processes self.progress_dialog = None # Init the repository manager dialog self.repository_manager = RepositoryManager() self.collection_manager = CollectionManager() # Collections list view self.collections_model = QStandardItemModel(0, 1) self.collections_model.sort(0, Qt.AscendingOrder) self.collection_proxy = CustomSortFilterProxyModel(self) self.collection_proxy.setSourceModel(self.collections_model) self.list_view_collections.setModel(self.collection_proxy) # Active selected collection self._sel_coll_id = None # Slots self.button_add.clicked.connect(self.add_repository) self.button_edit.clicked.connect(self.edit_repository) self.button_delete.clicked.connect(self.delete_repository) self.button_reload.clicked.connect(self.reload_repositories) self.button_reload_dir.clicked.connect(self.reload_off_res_directory) self.menu_list_widget.currentRowChanged.connect(self.set_current_tab) self.list_view_collections.selectionModel().currentChanged.connect( self.on_list_view_collections_clicked) self.line_edit_filter.textChanged.connect(self.filter_collections) self.button_install.clicked.connect(self.install_collection) self.button_open.clicked.connect(self.open_collection) self.button_uninstall.clicked.connect(self.uninstall_collection) self.button_box.button(QDialogButtonBox.Help).clicked.connect( self.open_help) # Populate the repositories widget and collections list view self.populate_repositories_widget() self.reload_collections_model()
def run(self): """Run method that loads and starts the plugin""" if not iface.building_toolbar: # Set up toolbar iface.building_toolbar = QToolBar(u"Building Tools") iface.addToolBar(iface.building_toolbar, Qt.RightToolBarArea) # Create the dockwidget and dialog and keep reference if not self.dockwidget: self.dockwidget = BuildingsDockwidget() # Connect with close self.dockwidget.closed.connect(self.on_dockwidget_closed) # Show the dockwidget as a tab layerdock = iface.mainWindow().findChild(QDockWidget, "Layers") iface.addDockWidget(Qt.LeftDockWidgetArea, self.dockwidget) iface.mainWindow().tabifyDockWidget(layerdock, self.dockwidget) self.setup_main_toolbar() dw = self.dockwidget # no base layers self.menu_frame = MenuFrame(self.dockwidget) dw.insert_into_frames("menu_frame", self.menu_frame) home_dir = os.path.dirname(__file__) if dw.lst_options.item(0) is None: icon_path = os.path.join(home_dir, "icons", "buildings_plugin.png") item = QListWidgetItem("Buildings") item.setIcon(QIcon(icon_path)) dw.lst_options.addItem(item) dw.lst_options.setCurrentItem(item) icon_path = os.path.join(home_dir, "icons", "capture_source.png") item = QListWidgetItem("Capture Sources") item.setIcon(QIcon(icon_path)) dw.lst_sub_menu.addItem(item) icon_path = os.path.join(home_dir, "icons", "bulk_load.png") item = QListWidgetItem("Bulk Load") item.setIcon(QIcon(icon_path)) dw.lst_sub_menu.addItem(item) icon_path = os.path.join(home_dir, "icons", "edit.png") item = QListWidgetItem("Edit Outlines") item.setIcon(QIcon(icon_path)) dw.lst_sub_menu.addItem(item) icon_path = os.path.join(home_dir, "icons", "settings.png") item = QListWidgetItem("Settings") item.setIcon(QIcon(icon_path)) dw.lst_sub_menu.addItem(item) icon_path = os.path.join(home_dir, "icons", "reference.png") item = QListWidgetItem("Reference Data") item.setIcon(QIcon(icon_path)) dw.lst_sub_menu.addItem(item) canvas = iface.mapCanvas() selectedcrs = "EPSG:2193" target_crs = QgsCoordinateReferenceSystem() target_crs.createFromUserInput(selectedcrs) canvas.setDestinationCrs(target_crs) self.on_click() self.dockwidget.show() self.dockwidget.raise_()