-
Notifications
You must be signed in to change notification settings - Fork 0
/
PluginSettingsDialog.py
95 lines (71 loc) · 3.15 KB
/
PluginSettingsDialog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
PluginSettingsDialog.py
MIT License (c) Faure Systems <dev at faure dot systems>
Dialog to configure plugin parameters.
"""
from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot, QSettings, QSize
from PyQt5.QtWidgets import (QDialog, QHBoxLayout, QVBoxLayout, QGridLayout,
QRadioButton, QLabel, QPushButton, QSizePolicy, QGroupBox)
from PyQt5.QtGui import QIcon
class PluginSettingsDialog(QDialog):
# __________________________________________________________________
def __init__(self, logger):
super(PluginSettingsDialog, self).__init__()
self._logger = logger
self.setAttribute(Qt.WA_AlwaysStackOnTop)
self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint | Qt.WindowStaysOnTopHint)
self.setWindowTitle(self.tr("Settings"))
self.setWindowIcon(QIcon('./images/settings.svg'))
self.buildUi()
# __________________________________________________________________
def buildUi(self):
main_layout = QVBoxLayout()
main_layout.setSpacing(12)
param_box = QGroupBox(self.tr("Configuration"))
param_box_layout = QVBoxLayout(param_box)
main_layout.addWidget(param_box)
param1_button = QRadioButton(self.tr("Messages in English"))
param2_button = QRadioButton(self.tr("Messages in French"))
param_box_layout.addWidget(param1_button)
param_box_layout.addWidget(param2_button)
settings = QSettings("settings.ini", QSettings.IniFormat);
settings.setIniCodec("UTF-8");
settings.beginGroup("Parameters")
lang = settings.value('param', 'en')
settings.endGroup()
if lang == 'fr':
param2_button.setChecked(True)
else:
param1_button.setChecked(True)
close_button = QPushButton(self.tr("Close"))
close_button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
button_layout = QHBoxLayout()
button_layout.addStretch()
button_layout.addWidget(close_button)
main_layout.addLayout(button_layout)
self.setLayout(main_layout)
param1_button.pressed.connect(self.setParameters1)
param2_button.pressed.connect(self.setParameters2)
close_button.pressed.connect(self.accept)
# __________________________________________________________________
@pyqtSlot()
def setParameters1(self):
self._logger.info(self.tr("Settings : set English parameters"))
settings = QSettings("settings.ini", QSettings.IniFormat);
settings.setIniCodec("UTF-8");
settings.beginGroup("Parameters")
settings.setValue("param", 'en')
settings.endGroup()
settings.sync()
# __________________________________________________________________
@pyqtSlot()
def setParameters2(self):
self._logger.info(self.tr("Settings : set French parameters"))
settings = QSettings("settings.ini", QSettings.IniFormat);
settings.setIniCodec("UTF-8");
settings.beginGroup("Parameters")
settings.setValue("param", 'fr')
settings.endGroup()
settings.sync()