diff --git a/StyleManager/stylemanager.py b/StyleManager/stylemanager.py index ae36a0f..5fb2160 100644 --- a/StyleManager/stylemanager.py +++ b/StyleManager/stylemanager.py @@ -3,6 +3,7 @@ from qgis.PyQt.QtWidgets import QDialog, QFileDialog, QInputDialog, QMessageBox from qgis.PyQt.QtCore import Qt, QCoreApplication from ..utils import tr +from ..utils import DEFAULT_STYLE FORM_CLASS, _ = uic.loadUiType(os.path.join( os.path.dirname(__file__), 'ui_stylemanager.ui')) @@ -57,7 +58,7 @@ def delete_style(self): def set_default(self): """Set default qgis style""" - res, msg = self.mn.activate_style('default') + res, msg = self.mn.activate_style(DEFAULT_STYLE) def change_style(self): """Change style to user selected""" diff --git a/config.json b/config.json deleted file mode 100644 index d028b85..0000000 --- a/config.json +++ /dev/null @@ -1 +0,0 @@ -[{"org_toolbars": ["mFileToolBar", "mLayerToolBar", "mDigitizeToolBar", "mMapNavToolBar", "mAttributesToolBar", "mPluginToolBar", "mLabelToolBar", "mSnappingToolBar", "mSelectionToolBar"], "styles": {"GIAP": "giap.qss", "ciemny": "wombat.qss"}, "ribbons_config": [{"tab_name": "Main", "sections": [{"label": "Project", "btn_size": 30, "btns": [["mActionOpenProject", 0, 0], ["mActionNewProject", 0, 1], ["mActionSaveProject", 1, 0], ["mActionSaveProjectAs", 1, 1]]}, {"label": "Navigation", "btn_size": 30, "btns": [["mActionPan", 0, 0], ["mActionZoomIn", 0, 1], ["mActionZoomOut", 0, 2], ["mActionZoomFullExtent", 0, 3], ["mActionZoomToLayer", 1, 0], ["mActionZoomToSelected", 1, 1], ["mActionZoomLast", 1, 2], ["mActionZoomNext", 1, 3]]}, {"label": "Attributes", "btn_size": 30, "btns": [["mActionIdentify", 0, 0], ["mActionSelectFeatures", 0, 1], ["mActionDeselectAll", 1, 0], ["mActionOpenTable", 1, 1]]}, {"label": "Measures", "btn_size": 30, "btns": [["mActionMeasure", 0, 0], ["mActionMeasureArea", 0, 1], ["mActionMeasureAngle", 1, 0]]}, {"label": "Layers", "btn_size": 30, "btns": [["mActionAddOgrLayer", 0, 0], ["mActionAddWmsLayer", 0, 1], ["mActionAddPgLayer", 0, 2], ["mActionAddMeshLayer", 0, 3], ["mActionAddWcsLayer", 0, 4], ["mActionAddDelimitedText", 0, 5], ["mActionAddRasterLayer", 1, 0], ["mActionAddWfsLayer", 1, 1], ["mActionAddSpatiaLiteLayer", 1, 2], ["mActionAddVirtualLayer", 1, 3], ["mActionNewMemoryLayer", 1, 4]]}, {"label": "Prints", "btn_size": 30, "btns": [["mActionNewPrintLayout", 0, 0], ["giapMyPrints", 0, 1], ["mActionShowLayoutManager", 1, 0]]}]}, {"tab_name": "Tools", "sections": [{"label": "Adv. Attributes", "btn_size": 30, "btns": [["mActionIdentify", 0, 0], ["mActionSelectFeatures", 0, 1], ["mActionSelectPolygon", 0, 2], ["mActionSelectByExpression", 0, 3], ["mActionInvertSelection", 0, 4], ["mActionDeselectAll", 0, 5], ["mActionOpenTable", 1, 0], ["mActionStatisticalSummary", 1, 1], ["mActionOpenFieldCalc", 1, 2], ["mActionMapTips", 1, 3], ["mActionNewBookmark", 1, 4], ["mActionShowBookmarks", 1, 5]]}, {"label": "Labels", "btn_size": 30, "btns": [["mActionLabeling", 0, 0], ["mActionChangeLabelProperties", 0, 1], ["mActionPinLabels", 0, 2], ["mActionShowPinnedLabels", 0, 3], ["mActionShowHideLabels", 0, 4], ["mActionMoveLabel", 1, 0], ["mActionRotateLabel", 1, 1], ["mActionDiagramProperties", 1, 2], ["mActionShowUnplacedLabels", 1, 3]]}, {"label": "Vector", "btn_size": 30, "btns": [["mActionToggleEditing", 0, 0], ["mActionSaveLayerEdits", 0, 1], ["mActionVertexTool", 0, 2], ["mActionUndo", 0, 3], ["mActionRedo", 0, 4], ["mActionAddFeature", 1, 0], ["mActionMoveFeature", 1, 1], ["mActionDeleteSelected", 1, 2], ["mActionCutFeatures", 1, 3], ["mActionCopyFeatures", 1, 4], ["mActionPasteFeatures", 1, 5]]}, {"label": "Digitalization", "btn_size": 30, "btns": [["EnableSnappingAction", 0, 0], ["EnableTracingAction", 0, 1], ["mActionRotateFeature", 0, 2], ["mActionSimplifyFeature", 0, 3], ["mActionAddRing", 0, 4], ["mActionAddPart", 0, 5], ["mActionFillRing", 0, 6], ["mActionOffsetCurve", 0, 7], ["mActionCircularStringCurvePoint", 0, 8], ["mActionDeleteRing", 1, 0], ["mActionDeletePart", 1, 1], ["mActionReshapeFeatures", 1, 2], ["mActionSplitParts", 1, 3], ["mActionSplitFeatures", 1, 4], ["mActionMergeFeatureAttributes", 1, 5], ["mActionMergeFeatures", 1, 6], ["mActionReverseLine", 1, 7], ["mActionTrimExtendFeature", 1, 8]]}]}, {"tab_name": "Vector", "sections": [{"label": "Geoprocessing", "btn_size": 30, "btns": [["mProcessingUserMenu_native:buffer", 0, 0], ["mProcessingUserMenu_native:convexhull", 0, 1], ["mProcessingUserMenu_native:difference", 0, 2], ["mProcessingUserMenu_native:dissolve", 0, 3], ["mProcessingUserMenu_qgis:eliminateselectedpolygons", 0, 4], ["mProcessingUserMenu_native:clip", 1, 0], ["mProcessingUserMenu_native:intersection", 1, 1], ["mProcessingUserMenu_native:symmetricaldifference", 1, 2], ["mProcessingUserMenu_native:union", 1, 3]]}, {"label": "Geometry", "btn_size": 30, "btns": [["mProcessingUserMenu_native:centroids", 0, 0], ["mProcessingUserMenu_native:collect", 0, 1], ["mProcessingUserMenu_native:densifygeometries", 0, 2], ["mProcessingUserMenu_native:extractvertices", 0, 3], ["mProcessingUserMenu_native:multiparttosingleparts", 0, 4], ["mProcessingUserMenu_native:polygonstolines", 0, 5], ["mProcessingUserMenu_native:simplifygeometries", 1, 0], ["mProcessingUserMenu_qgis:checkvalidity", 1, 1], ["mProcessingUserMenu_qgis:delaunaytriangulation", 1, 2], ["mProcessingUserMenu_qgis:exportaddgeometrycolumns", 1, 3], ["mProcessingUserMenu_qgis:linestopolygons", 1, 4], ["mProcessingUserMenu_qgis:voronoipolygons", 1, 5]]}, {"label": "Analysis", "btn_size": 30, "btns": [["mProcessingUserMenu_native:countpointsinpolygon", 0, 0], ["mProcessingUserMenu_native:lineintersections", 0, 1], ["mProcessingUserMenu_native:meancoordinates", 0, 2], ["mProcessingUserMenu_native:nearestneighbouranalysis", 0, 3], ["mProcessingUserMenu_native:sumlinelengths", 1, 0], ["mProcessingUserMenu_qgis:basicstatisticsforfields", 1, 1], ["mProcessingUserMenu_qgis:distancematrix", 1, 2], ["mProcessingUserMenu_qgis:listuniquevalues", 1, 3]]}, {"label": "Research", "btn_size": 30, "btns": [["mProcessingUserMenu_native:creategrid", 0, 0], ["mProcessingUserMenu_native:polygonfromlayerextent", 0, 1], ["mProcessingUserMenu_native:randompointsinextent", 0, 2], ["mProcessingUserMenu_native:randompointsinpolygons", 0, 3], ["mProcessingUserMenu_native:randompointsonlines", 0, 4], ["mProcessingUserMenu_native:selectbylocation", 0, 5], ["mProcessingUserMenu_qgis:randompointsinlayerbounds", 1, 0], ["mProcessingUserMenu_qgis:randompointsinsidepolygons", 1, 1], ["mProcessingUserMenu_qgis:randomselection", 1, 2], ["mProcessingUserMenu_qgis:randomselectionwithinsubsets", 1, 3], ["mProcessingUserMenu_qgis:regularpoints", 1, 4]]}, {"label": "Data tools", "btn_size": 30, "btns": [["mProcessingUserMenu_native:createspatialindex", 0, 0], ["mProcessingUserMenu_native:joinattributesbylocation", 0, 1], ["mProcessingUserMenu_native:mergevectorlayers", 0, 2], ["mProcessingUserMenu_native:reprojectlayer", 1, 0], ["mProcessingUserMenu_native:splitvectorlayer", 1, 1]]}]}, {"tab_name": "Raster", "sections": [{"label": "Raster", "btn_size": 60, "btns": [["mActionShowRasterCalculator", 0, 0], ["mActionShowGeoreferencer", 0, 1], ["mActionShowAlignRasterTool", 0, 2]]}, {"label": "Raster analysis", "btn_size": 30, "btns": [["mProcessingUserMenu_gdal:aspect", 0, 0], ["mProcessingUserMenu_gdal:fillnodata", 0, 1], ["mProcessingUserMenu_gdal:gridaverage", 0, 2], ["mProcessingUserMenu_gdal:griddatametrics", 0, 3], ["mProcessingUserMenu_gdal:gridinversedistance", 0, 4], ["mProcessingUserMenu_gdal:gridnearestneighbor", 0, 5], ["mProcessingUserMenu_gdal:hillshade", 0, 6], ["mProcessingUserMenu_gdal:nearblack", 1, 0], ["mProcessingUserMenu_gdal:proximity", 1, 1], ["mProcessingUserMenu_gdal:roughness", 1, 2], ["mProcessingUserMenu_gdal:sieve", 1, 3], ["mProcessingUserMenu_gdal:slope", 1, 4], ["mProcessingUserMenu_gdal:tpitopographicpositionindex", 1, 5], ["mProcessingUserMenu_gdal:triterrainruggednessindex", 1, 6]]}, {"label": "Projections", "btn_size": 60, "btns": [["mProcessingUserMenu_gdal:warpreproject", 0, 0], ["mProcessingUserMenu_gdal:assignprojection", 0, 1], ["mProcessingUserMenu_gdal:extractprojection", 0, 2]]}, {"label": "Miscellaneous", "btn_size": 30, "btns": [["mProcessingUserMenu_gdal:buildvirtualraster", 0, 0], ["mProcessingUserMenu_gdal:gdalinfo", 0, 1], ["mProcessingUserMenu_gdal:merge", 0, 2], ["mProcessingUserMenu_gdal:overviews", 1, 0], ["mProcessingUserMenu_gdal:tileindex", 1, 1]]}, {"label": "Extract", "btn_size": 30, "btns": [["mProcessingUserMenu_gdal:cliprasterbyextent", 0, 0], ["mProcessingUserMenu_gdal:cliprasterbymasklayer", 0, 1], ["mProcessingUserMenu_gdal:contour", 1, 0]]}, {"label": "Conversion", "btn_size": 30, "btns": [["mProcessingUserMenu_gdal:pcttorgb", 0, 0], ["mProcessingUserMenu_gdal:rgbtopct", 0, 1], ["mProcessingUserMenu_gdal:polygonize", 0, 2], ["mProcessingUserMenu_gdal:rasterize", 1, 0], ["mProcessingUserMenu_gdal:translate", 1, 1]]}]}], "active_style": "GIAP"}] \ No newline at end of file diff --git a/config.py b/config.py index 48c9c69..d07e235 100644 --- a/config.py +++ b/config.py @@ -1,16 +1,23 @@ import os import json +from qgis._core import QgsMessageLog +from .utils import DEFAULT_STYLE class Config: def __init__(self): """Constructor""" # load config from file + self.setts = {} self.conf_dir = os.path.dirname(__file__) - fl = open(os.path.join(self.conf_dir, 'config.json'), 'r') - conf = fl.read() - fl.close() - self.setts = json.loads(conf)[0] + config_path = os.path.join(self.conf_dir, 'config.json') + if os.path.exists(config_path): + with open(config_path, 'r') as fl: + conf = fl.read() + try: + self.setts = json.loads(conf)[0] + except ValueError: + QgsMessageLog.logMessage('Failed to load config from config.json') def save_config(self): """ @@ -154,6 +161,13 @@ def set_style(self, style, path): """ self.setts['styles'][style] = path + def set_default_style(self, dic_styles): + if 'styles' not in self.setts: + self.setts['styles'] = dic_styles + if 'active_style' not in self.setts: + self.setts['active_style'] = DEFAULT_STYLE + self.save_config() + def set_active_style(self, style): """ set name of active style in config diff --git a/giap_layout.py b/giap_layout.py index d31dcca..8f374b5 100644 --- a/giap_layout.py +++ b/giap_layout.py @@ -67,6 +67,10 @@ def __init__(self, iface): self.iface.initializationCompleted.connect(self.load_ribbons) def initGui(self): + # set default style and active style if config.json doesn't extists + dic_style = self.style_manager.get_style_dictionary() + self.config.set_default_style(dic_style) + style = self.main_widget.styleSheet() self.iface.mainWindow().statusBar().setStyleSheet(style + """ QSpinBox { diff --git a/i18n/giap_pl.ts b/i18n/giap_pl.ts index e89fa24..a587396 100644 --- a/i18n/giap_pl.ts +++ b/i18n/giap_pl.ts @@ -3,6 +3,11 @@ @default + + + Failed to load config from config.json + Wystąpił błąd podczas wczytywania pliku konfiguracyjnego config.json + New Tab diff --git a/tools.py b/tools.py index bf5dbe6..3d83813 100644 --- a/tools.py +++ b/tools.py @@ -5,6 +5,7 @@ from qgis.PyQt.QtCore import QFileSystemWatcher from .utils import tr +from .utils import DEFAULT_STYLE class StyleManager: @@ -35,6 +36,9 @@ def __init__(self, parent): def get_style_list(self): return [x for x in self.styles.keys()] + def get_style_dictionary(self): + return self.styles + def run_last_style(self): """ load active style on stratup""" try: @@ -86,14 +90,14 @@ def activate_style(self, name): # if path to style not found set default style if pth in ['', None]: - self.app.setStyleSheet('') + self.app.setStyleSheet(DEFAULT_STYLE) pth = '' # check if file exist if not os.path.exists(pth): - self.app.setStyleSheet('') # return do default, and save it in con + self.app.setStyleSheet(DEFAULT_STYLE) # return do default, and save it in con if name == 'default': - self.config.set_active_style('') + self.config.set_active_style(DEFAULT_STYLE) return False, tr('Default style set') else: return False, tr('Path to *.qss not found, load default style') diff --git a/utils.py b/utils.py index cfef105..17a8ab4 100644 --- a/utils.py +++ b/utils.py @@ -480,4 +480,5 @@ def get_project_config(parameter, key, default=''): ] +DEFAULT_STYLE = "GIAP" DEFAULT_TABS = ['Main', 'Tools', 'Vector', 'Raster']