def saveAsScriptFile(self, index=None): tabWidget = self.tabEditorWidget.currentWidget() if not index: index = self.tabEditorWidget.currentIndex() if not tabWidget.path: fileName = self.tabEditorWidget.tabText(index) + '.py' folder = self.settings.value("pythonConsole/lastDirPath", QDir.home()) pathFileName = os.path.join(folder, fileName) fileNone = True else: pathFileName = tabWidget.path fileNone = False saveAsFileTr = QCoreApplication.translate("PythonConsole", "Save File As") filename = QFileDialog.getSaveFileName(self, saveAsFileTr, pathFileName, "Script file (*.py)") if filename: try: tabWidget.save(filename) except (IOError, OSError) as error: msgText = QCoreApplication.translate('PythonConsole', 'The file <b>{0}</b> could not be saved. Error: {1}').format(tabWidget.path, error.strerror) self.callWidgetMessageBarEditor(msgText, 2, False) if fileNone: tabWidget.path = None else: tabWidget.path = pathFileName return if not fileNone: self.updateTabListScript(pathFileName, action='remove')
def add_map(self): (level,ok) = QInputDialog.getInt(self, QCA.translate('AdminHomeMap' ,'Agregar plano'), QCA.translate('AdminHomeMap' ,'Nivel:'), 0,-10,100) if ok : overwrite = True if self.home_map_scene.has_map(level) : ret = QMessageBox.question(self, QCA.translate('AdminHomeMap' ,'Mapa existente'), QCA.translate('AdminHomeMap' ,'El mapa ya existe desea sobrescribirlo'), QMessageBox.Yes| QMessageBox.No, QMessageBox.No) overwrite = (ret == QMessageBox.Yes) if overwrite : file = QFileDialog.getOpenFileName(self, QCA.translate('AdminHomeMap', "Seleccione la imagen del mapa"), QDir.home().absolutePath(), QCA.translate('AdminHomeMap', "Imagenes (*.bmp *.gif *.jpg *.jpeg *.png *.pbm *.pgm *.ppm *.xbm *.xpm)")) if file: self.home_map_scene.set_map(QPixmap(file),level) self.home_map_view.update()
def saveAsScriptFile(self, index=None): tabWidget = self.tabEditorWidget.currentWidget() if not index: index = self.tabEditorWidget.currentIndex() if not tabWidget.path: fileName = self.tabEditorWidget.tabText(index) + '.py' folder = self.settings.value("pythonConsole/lastDirPath", QDir.home()) pathFileName = os.path.join(folder,fileName) fileNone = True else: pathFileName = tabWidget.path fileNone = False saveAsFileTr = QCoreApplication.translate("PythonConsole", "Save File As") filename = QFileDialog.getSaveFileName(self, saveAsFileTr, pathFileName, "Script file (*.py)") if filename: try: tabWidget.save(filename) except (IOError, OSError), error: msgText = QCoreApplication.translate('PythonConsole', 'The file <b>{0}</b> could not be saved. Error: {1}').format(tabWidget.path, error.strerror) self.callWidgetMessageBarEditor(msgText, 2, False) if fileNone: tabWidget.path = None else: tabWidget.path = pathFileName return if not fileNone: self.updateTabListScript(pathFileName, action='remove')
def _menu_main_window_open_file(self): """ Action to open a file in the main window. Used the QFileDialog to open the file. """ #clear old list/tree self.tree_main.clear() self.signal_wrapper.signal_editor_of_tree1_clear.emit() file_name = QFileDialog.getOpenFileName(self, "Open file", QDir.home().dirName(), "All files (*.*)") logging.debug("_menu_main_window_open_file" + file_name) if not file_name.isNull(): remainder_lines = self._importer.read_file( self.main_window.centralWidget(), file_name, self.tree_main) self._conf.data[str(CONFIG_ENUM.LastFilename)] = str(file_name) try: ConfigurationFileWriter.write_config(self._conf) except IOError, exc: logging.exception(exc) QMessageBox.warning(self, "Critical", ''' Configuratino couldn't be written to file. Error:''' + exc.args[0]) gui_helper.change_window_title(file_name, self.main_window) ImportResult(self.main_window, remainder_lines, self._conf)
def check_for_config_folder(self): config_dir = QDir.home() if not config_dir.cd(".dropn900"): if config_dir.mkdir(".dropn900"): print ">> [INFO] Created config dir '.dropn900' to " + str(config_dir.absolutePath()) else: print ">> [ERROR] Could not create config dir '.dropn900' to " + str(config_dir.absolutePath())
def _on_choose_holders_config_file(self): # Slot raised to browse the holders config file holders_config = self.txt_holders_config.text() if not holders_config: holders_config = QDir.home().path() conf_file = QFileDialog.getOpenFileName( self, self.tr('Browse Holders Configuration File'), holders_config, 'Holders INI file (*.ini)') if conf_file: self.txt_holders_config.setText(conf_file)
def __init__(self, controller, logger): self.controller = controller self.logger = logger self.store_auth_to_file = True self.dont_show_dl_dialog = False self.only_sync_on_wlan = True self.user_home = self.to_unicode(str(QDir.home().absolutePath().toUtf8())) self.app_root = self.to_unicode("/opt/dropn900/") self.config_root = self.user_home + self.to_unicode("/.dropn900/") self.data_root = self.user_home + self.to_unicode("/MyDocs/DropN900/") self.default_data_root = self.user_home + self.to_unicode("/MyDocs/DropN900") self.startup_checks()
def _default_file_save(self): """ Action function to save to file. """ file_name = QFileDialog.getSaveFileName(self, "Save file", QDir.home().dirName(), "All files (*.*)") if not file_name.isNull(): _exporter = TextExporter(self._conf) _exporter.write_file_from_data(self.tree_main, file_name) QMessageBox.information(self.main_window, "Info", '''Please ensure the correctness of the output file by comparing (diff) the output file to the original one. See help for further information.''')
def set_settings_to_ui(self, download_data, authentication_data, automate_sync_data): # Download settings dir_check = QDir(download_data["default-folder"]) if dir_check.exists(): self.ui.lineedit_default_download_folder.setText(download_data["default-folder"]) else: self.ui.lineedit_default_download_folder.setText(str(QDir.home().absolutePath()) + "/MyDocs/DropN900/") self.ui.checkbox_no_dl_dialog.setChecked(download_data["no-dialog"]) # Authentication settings self.ui.checkbox_enable_store_auth.setChecked(authentication_data["store-auth"]) # Automated sync self.ui.checkbox_enable_sync.setChecked(automate_sync_data["enabled"]) self.set_sync_widgets_enabled(automate_sync_data["enabled"]) self.ui.checkbox_only_wlan_sync.setChecked(automate_sync_data["only-sync-on-wlan"]) self.ui.spinbox_sync_interval.setValue(automate_sync_data["update-interval"])
def openScriptFile(self): lastDirPath = self.settings.value("pythonConsole/lastDirPath", QDir.home()) openFileTr = QCoreApplication.translate("PythonConsole", "Open File") fileList = QFileDialog.getOpenFileNames( self, openFileTr, lastDirPath, "Script file (*.py)") if fileList: for pyFile in fileList: for i in range(self.tabEditorWidget.count()): tabWidget = self.tabEditorWidget.widget(i) if tabWidget.path == pyFile: self.tabEditorWidget.setCurrentWidget(tabWidget) break else: tabName = QFileInfo(pyFile).fileName() self.tabEditorWidget.newTabEditor(tabName, pyFile) lastDirPath = QFileInfo(pyFile).path() self.settings.setValue("pythonConsole/lastDirPath", pyFile) self.updateTabListScript(pyFile, action='append')
def check_for_data_folder(self): if self.data_root == (self.user_home + "/MyDocs/DropN900/"): data_dir = QDir.home() if data_dir.cd("MyDocs"): if not data_dir.cd("DropN900"): if data_dir.mkdir("DropN900"): print ">> [INFO] Created default data dir " + str(data_dir.absolutePath()) + "/DropN900" else: print ">> [ERROR] Could not create default data dir 'DropN900' to " + str(data_dir.absolutePath()) else: print ">> [ERROR] Could not find 'MyDocs' folder from " + str(data_dir.absolutePath()) else: non_default_data_dir = QDir(self.data_root) if non_default_data_dir.exists(): print ">> [INFO] Default data dir: " + self.data_root else: print ">> [WARNING] User set default data dir " + self.data_root + " does not exist, resetting to default" self.data_root = self.user_home + "/MyDocs/DropN900/" self.check_for_data_folder()
def _menu_second_window_open_file(self): """ Action to open a file in the second window/file. Used the QFileDialog to open the file. """ #clear old list/tree self.tree_second.clear() self.signal_wrapper.signal_editor_of_tree2_clear.emit() file_name = QFileDialog.getOpenFileName(self, "Open file", QDir.home().dirName(), "All files (*.*)") if not file_name.isNull(): remainder_lines = self._importer.read_file( self.main_window.centralWidget(), file_name, self.tree_second) ImportResult(self.main_window, remainder_lines, self._conf)
def _menu_change_label_of_selected_elements(self, tree_instance, is_main_tree): text, ok_response = QInputDialog.getText(self.main_window, "Replace", "Replace checked to:", QLineEdit.Normal, QDir.home().dirName()) logging.debug("Replace / Change label with:" + text) if ok_response is False: return result_list = tree_operations.tree_element_change_label(tree_instance, text) #emit the signal to trigger a click event. That is needed to refresh #the texteditor, that it contains the replaced data. if is_main_tree == self.SECOND_TREE: self.signal_wrapper.signal_treeview2_clicked.emit() else: self.signal_wrapper.signal_treeview1_clicked.emit() QMessageBox.information(self.main_window, "Info", '''The labels of the following tree elements were successfully renamned/changed : ''' + "".join(result_list))
* This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ """ import ConfigParser import os import json from datetime import datetime from PyQt4.QtCore import QDir HOME = QDir.home().path() LOGGER_HOME = HOME + '/.stdm/geoodk' IMPORT_SECTION = 'imports' class ImportLogger: """ Class constructor """ def __init__(self): """ Initialize vairables """ self.config_logger = ConfigParser.RawConfigParser() self.logger_path()
from stdm.ui.wizard.custom_item_model import EntitiesModel from stdm.geoodk.importer import EntityImporter from stdm.settings.projectionSelector import ProjectionSelector from stdm.geoodk.importer import ImportLogger from stdm.geoodk.importer import Save2DB from stdm.third_party.sqlalchemy.exc import SQLAlchemyError from stdm import resources_rc #from stdm.geoodk.importer.geoodkserver import JSONEXTRACTOR from collections import OrderedDict FORM_CLASS, _ = uic.loadUiType(os.path.join( os.path.dirname(__file__), 'ui_geoodk_import.ui')) HOME = QDir.home().path() CONFIG_FILE = HOME + '/.stdm/geoodk/' MSG = 'Error creating log' GEOODK_FORM_HOME = CONFIG_FILE+'instances' class ProfileInstanceRecords(QDialog, FORM_CLASS): """ class constructor The class handles all the instances that the user has collected and saved in the folder and saved in a computer. The class will construct the path to the folder and enumerate all available instances and return the count. It will also rename all the file based on instance unique GUUID for easier management and future updates. """ def __init__(self, parent=None):
set_cmis_atom_pub_url, set_cmis_auth_config_id, set_debug_logging, set_holders_config_path, source_documents_path, QGISRegistryConfig, RegistryConfig, COMPOSER_OUTPUT, COMPOSER_TEMPLATE, NETWORK_DOC_RESOURCE, CONFIG_UPDATED, WIZARD_RUN, SHOW_SHORTCUT_DIALOG) from stdm.security.auth_config import (config_entries) from stdm.network.cmis_manager import (CmisManager) from stdm.utils.util import setComboCurrentIndexWithText, version_from_metadata from stdm.ui.login_dlg import loginDlg from stdm.ui.notification import NotificationBar from stdm.ui.customcontrols.validating_line_edit import INVALIDATESTYLESHEET from stdm.ui.ui_options import Ui_DlgOptions MAX_LIMIT = 500 # Maximum records in a entity browser DEF_HOLDERS_CONFIG_PATH = QDir.home().path() + '/.stdm/holders_config.ini' def pg_profile_names(): """/ :return: List containing tuple of PostgreSQL database connection names and full path stored by QGIS. :rtype: list """ pg_connection_path = "/PostgreSQL/connections" q_config = QGISRegistryConfig(pg_connection_path) pg_connections = q_config.group_children() profiles = [(conn_name, u"{0}/{1}".format(pg_connection_path, conn_name)) for conn_name in pg_connections]
def loadqlr(self): path = QFileDialog.getOpenFileName(self.iface.mainWindow(), "Add QGIS Layer Definition", QDir.home().path(), "*.qlr") if not path: return with open(path, 'r') as f: content = f.read() doc = QDomDocument() doc.setContent(content) layernode = doc.elementsByTagName('maplayer').at(0) layerelm = layernode.toElement() layertype = layerelm.attribute("type") layer = None if layertype == "vector": layer = QgsVectorLayer() elif layertype == 'raster': layer = QgsRasterLayer() ok = layer.readLayerXML(layerelm) if ok: QgsMapLayerRegistry.instance().addMapLayer(layer)
def saveqlr(self): layer = self.iface.activeLayer() if not layer: return path = QFileDialog.getSaveFileName(self.iface.mainWindow(), "Save as QGIS Layer Definition", QDir.home().path(), "*.qlr") if not path: return doc = QDomDocument("qgis-layer-definition") mapnode = doc.createElement("maplayer") layer.writeLayerXML(mapnode, doc) mapnode.removeChild(mapnode.firstChildElement("id")) doc.appendChild(mapnode) with open(path, "w") as f: f.write(doc.toString())