Skip to content

Commit

Permalink
feat: use editable combobox for instance in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
gounux committed Jul 25, 2024
1 parent fc847ca commit 270f7d0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
35 changes: 22 additions & 13 deletions qtribu/gui/dlg_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pathlib import Path

# PyQGIS
from qgis.core import QgsApplication
from qgis.core import Qgis, QgsApplication
from qgis.gui import QgsOptionsPageWidget, QgsOptionsWidgetFactory
from qgis.PyQt import uic
from qgis.PyQt.QtCore import Qt
Expand Down Expand Up @@ -105,7 +105,7 @@ def apply(self):
settings.license_global_accept = self.chb_license_global_accept.isChecked()

# qchat
settings.qchat_instance_uri = self.lne_qchat_instance_uri.text()
settings.qchat_instance_uri = self.cbb_qchat_instance_uri.currentText()
settings.qchat_activate_cheatcode = self.ckb_cheatcodes.isChecked()
settings.qchat_display_admin_messages = (
self.ckb_display_admin_messages.isChecked()
Expand Down Expand Up @@ -143,7 +143,13 @@ def load_settings(self) -> None:
self.chb_license_global_accept.setChecked(settings.license_global_accept)

# qchat
self.lne_qchat_instance_uri.setText(settings.qchat_instance_uri)
instance_index = self.cbb_qchat_instance_uri.findText(
settings.qchat_instance_uri, Qt.MatchFixedString
)
if instance_index >= 0:
self.cbb_qchat_instance_uri.setCurrentIndex(instance_index)
else:
self.cbb_qchat_instance_uri.setCurrentText(settings.qchat_instance_uri)
self.ckb_cheatcodes.setChecked(settings.qchat_activate_cheatcode)
self.ckb_display_admin_messages.setChecked(
settings.qchat_display_admin_messages
Expand All @@ -162,16 +168,19 @@ def load_settings(self) -> None:
self.lbl_version_saved_value.setText(settings.version)

def show_instance_rules(self) -> None:
instance_url = self.lne_qchat_instance_uri.text()
client = QChatApiClient(instance_url)
rules = client.get_rules()
QMessageBox.information(
self,
self.tr("Instance rules"),
self.tr("Instance rules ({instance_url}):\n\n{rules}").format(
instance_url=instance_url, rules=rules["rules"]
),
)
instance_url = self.cbb_qchat_instance_uri.currentText()
try:
client = QChatApiClient(instance_url)
rules = client.get_rules()
QMessageBox.information(
self,
self.tr("Instance rules"),
self.tr("Instance rules ({instance_url}):\n\n{rules}").format(
instance_url=instance_url, rules=rules["rules"]
),
)
except Exception as e:
self.log(message=str(e), log_level=Qgis.Critical)

def on_ring_tone_changed(self) -> None:
"""
Expand Down
30 changes: 29 additions & 1 deletion qtribu/gui/dlg_settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,30 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lne_qchat_instance_uri"/>
<widget class="QgsSymbolButton" name="mSymbolButton"/>
</item>
<item>
<widget class="QComboBox" name="cbb_qchat_instance_uri">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
<item>
<property name="text">
<string>https://gischat.geotribu.net</string>
</property>
</item>
<item>
<property name="text">
<string>https://gischat.geotribu.fr</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_rules">
Expand Down Expand Up @@ -653,6 +676,11 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsSymbolButton</class>
<extends>QToolButton</extends>
<header>qgssymbolbutton.h</header>
</customwidget>
<customwidget>
<class>AuthoringWidget</class>
<extends>QWidget</extends>
Expand Down

0 comments on commit 270f7d0

Please sign in to comment.