src/eric7/MicroPython/NtpParametersDialog.py

branch
mpy_network
changeset 9868
467288cffee2
child 10439
21c28b0f9e41
equal deleted inserted replaced
9867:e69788b71c00 9868:467288cffee2
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2023 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to enter the NTP parameters.
8 """
9
10 from PyQt6.QtCore import pyqtSlot
11 from PyQt6.QtWidgets import QAbstractButton, QDialog, QDialogButtonBox
12
13 from eric7 import Preferences
14
15 from .Ui_NtpParametersDialog import Ui_NtpParametersDialog
16
17
18 class NtpParametersDialog(QDialog, Ui_NtpParametersDialog):
19 """
20 Class implementing a dialog to enter the NTP parameters.
21 """
22
23 def __init__(self, parent=None):
24 """
25 Constructor
26
27 @param parent reference to the parent widget (defaults to None)
28 @type QWidget (optional)
29 """
30 super().__init__(parent)
31 self.setupUi(self)
32
33 self.serverEdit.textChanged.connect(self.__updateOk)
34
35 self.serverEdit.setText(Preferences.getMicroPython("NtpServer"))
36 self.tzOffsetSpinBox.setValue(Preferences.getMicroPython("NtpOffset"))
37 self.dstCheckBox.setChecked(Preferences.getMicroPython("NtpDaylight"))
38 self.timeoutSpinBox.setValue(Preferences.getMicroPython("NtpTimeout"))
39
40 msh = self.minimumSizeHint()
41 self.resize(max(self.width(), msh.width()), msh.height())
42
43 @pyqtSlot()
44 def __updateOk(self):
45 """
46 Private slot to update the enabled stat of the OK button.
47 """
48 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(
49 bool(self.serverEdit.text())
50 )
51
52 @pyqtSlot(QAbstractButton)
53 def on_buttonBox_clicked(self, button):
54 """
55 Private slot handling the selection of a dialog button.
56
57 @param button reference to the clicked button
58 @type QAbstractButton
59 """
60 if button == self.buttonBox.button(
61 QDialogButtonBox.StandardButton.RestoreDefaults
62 ):
63 self.serverEdit.setText(Preferences.Prefs.microPythonDefaults["NtpServer"])
64 self.tzOffsetSpinBox.setValue(
65 Preferences.Prefs.microPythonDefaults["NtpOffset"]
66 )
67 self.dstCheckBox.setChecked(
68 Preferences.Prefs.microPythonDefaults["NtpDaylight"]
69 )
70 self.timeoutSpinBox.setValue(
71 Preferences.Prefs.microPythonDefaults["NtpTimeout"]
72 )
73
74 @pyqtSlot()
75 def accept(self):
76 """
77 Public slot accepting the dialog.
78 """
79 if self.rememberCheckBox.isChecked():
80 Preferences.setMicroPython("NtpServer", self.serverEdit.text())
81 Preferences.setMicroPython("NtpOffset", self.tzOffsetSpinBox.value())
82 Preferences.setMicroPython("NtpDaylight", self.dstCheckBox.isChecked())
83 Preferences.setMicroPython("NtpTimeout", self.timeoutSpinBox.value())
84
85 super().accept()
86
87 def getParameters(self):
88 """
89 Public method to get the entered NTP parameters.
90
91 @return tuple containing the NTP server name, the timezone offset in hours,
92 a flag indicating daylight savings is in effect and a timeout value in
93 seconds
94 @rtype tuple of (str, int, bool, int)
95 """
96 return (
97 self.serverEdit.text(),
98 self.tzOffsetSpinBox.value(),
99 self.dstCheckBox.isChecked(),
100 self.timeoutSpinBox.value(),
101 )

eric ide

mercurial