Skip to content

Commit

Permalink
[gui] Add dialog to overwrite/create new pg_service entries
Browse files Browse the repository at this point in the history
  • Loading branch information
gacarrillor committed Apr 8, 2024
1 parent ff52c23 commit 7f38682
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pg_service_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .pg_service_parser_plugin import PGServiceParserPlugin
from .pg_service_parser_plugin import PgServiceParserPlugin


def classFactory(iface):
return PGServiceParserPlugin(iface)
return PgServiceParserPlugin(iface)
4 changes: 4 additions & 0 deletions pg_service_parser/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os.path


DEFAULT_PG_SERVICE_PATH = os.path.expanduser("~/.pg_service.conf")
Empty file.
34 changes: 34 additions & 0 deletions pg_service_parser/gui/dlg_pg_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from qgis.PyQt.QtCore import pyqtSlot
from qgis.PyQt.QtWidgets import QDialog

from pg_service_parser.pg_service_parser_wrapper import (copy_service_settings,
service_names)
from pg_service_parser.utils import get_ui_class

DIALOG_UI = get_ui_class('pg_service_dialog.ui')


class PgServiceDialog(QDialog, DIALOG_UI):

def __init__(self, parent):
QDialog.__init__(self, parent)
self.setupUi(self)

self.cboSourceService.addItems(service_names())
self.cboTargetService.addItems(service_names())

self.radOverwrite.toggled.connect(self.__update_target_controls)
self.buttonBox.accepted.connect(self.__accepted)

self.__update_target_controls(True)

@pyqtSlot(bool)
def __update_target_controls(self, checked):
self.cboTargetService.setEnabled(self.radOverwrite.isChecked())
self.txtNewService.setEnabled(not self.radOverwrite.isChecked())

def __accepted(self):
target_service = self.cboTargetService.currentText() if self.radOverwrite.isChecked() else self.txtNewService.text()

res = copy_service_settings(self.cboSourceService.currentText(), target_service)
print(res)
6 changes: 5 additions & 1 deletion pg_service_parser/pg_service_parser_plugin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from qgis.PyQt.QtWidgets import QAction

from pg_service_parser.gui.dlg_pg_service import PgServiceDialog

class PGServiceParserPlugin():

class PgServiceParserPlugin():
def __init__(self, iface):
self.iface = iface
self.action = None
Expand All @@ -17,3 +19,5 @@ def unload(self):

def run(self):
print("Eureka!")
dlg = PgServiceDialog(self.iface.mainWindow())
dlg.exec_()
153 changes: 153 additions & 0 deletions pg_service_parser/ui/pg_service_dialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>dlgPGService</class>
<widget class="QDialog" name="dlgPGService">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>489</width>
<height>208</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item row="0" column="2">
<widget class="QComboBox" name="cboTargetService">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="radOverwrite">
<property name="text">
<string>Overwrite</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QRadioButton" name="radCreate">
<property name="text">
<string>Create new</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QComboBox" name="cboSourceService">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="txtNewService">
<property name="placeholderText">
<string>New service name</string>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>dlgPGService</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>dlgPGService</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
37 changes: 37 additions & 0 deletions pg_service_parser/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
from qgis.PyQt.uic import (loadUiType,
loadUi)

from pg_service_parser.config import DEFAULT_PG_SERVICE_PATH


def get_ui_class(ui_file):
"""Get UI Python class from .ui file.
Can be filename.ui or subdirectory/filename.ui
:param ui_file: The file of the ui in svir.ui
:type ui_file: str
"""
ui_file_path = get_ui_file_path(ui_file)
return loadUiType(ui_file_path)[0]


def get_ui_file_path(ui_file) -> str:
os.path.sep.join(ui_file.split('/'))
ui_file_path = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
'ui',
ui_file
)
)

return ui_file_path


def get_pg_service_path() -> str:
"""
Path to pg_service.conf file, where data will be read from.
:return: String. pg_service file path.
"""
return DEFAULT_PG_SERVICE_PATH

0 comments on commit 7f38682

Please sign in to comment.