-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gui] Add dialog to overwrite/create new pg_service entries
- Loading branch information
1 parent
ff52c23
commit 7f38682
Showing
7 changed files
with
235 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |