src/eric7/Preferences/ConfigurationPages/CooperationPage.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2010 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the Cooperation configuration page.
8 """
9
10 from PyQt6.QtCore import pyqtSlot, QRegularExpression
11 from PyQt6.QtGui import QRegularExpressionValidator, QValidator
12
13 from .ConfigurationPageBase import ConfigurationPageBase
14 from .Ui_CooperationPage import Ui_CooperationPage
15
16 import Preferences
17
18
19 class CooperationPage(ConfigurationPageBase, Ui_CooperationPage):
20 """
21 Class implementing the Cooperation configuration page.
22 """
23 def __init__(self):
24 """
25 Constructor
26 """
27 super().__init__()
28 self.setupUi(self)
29 self.setObjectName("CooperationPage")
30
31 self.__bannedUserValidator = QRegularExpressionValidator(
32 QRegularExpression(
33 r"[a-zA-Z0-9.-]+@"
34 r"(?:(?:2(?:[0-4][0-9]|5[0-5])|[01]?[0-9]{1,2})\.){3}"
35 r"(?:2(?:[0-4][0-9]|5[0-5])|[01]?[0-9]{1,2})"),
36 self.bannedUserEdit)
37 self.bannedUserEdit.setValidator(self.__bannedUserValidator)
38
39 # set initial values
40 self.autostartCheckBox.setChecked(
41 Preferences.getCooperation("AutoStartServer"))
42 self.otherPortsCheckBox.setChecked(
43 Preferences.getCooperation("TryOtherPorts"))
44 self.serverPortSpin.setValue(
45 Preferences.getCooperation("ServerPort"))
46 self.portToTrySpin.setValue(
47 Preferences.getCooperation("MaxPortsToTry"))
48 self.autoAcceptCheckBox.setChecked(
49 Preferences.getCooperation("AutoAcceptConnections"))
50
51 self.bannedUsersList.addItems(sorted(
52 Preferences.getCooperation("BannedUsers")))
53
54 def save(self):
55 """
56 Public slot to save the Cooperation configuration.
57 """
58 Preferences.setCooperation(
59 "AutoStartServer",
60 self.autostartCheckBox.isChecked())
61 Preferences.setCooperation(
62 "TryOtherPorts",
63 self.otherPortsCheckBox.isChecked())
64 Preferences.setCooperation(
65 "AutoAcceptConnections",
66 self.autoAcceptCheckBox.isChecked())
67 Preferences.setCooperation(
68 "ServerPort",
69 self.serverPortSpin.value())
70 Preferences.setCooperation(
71 "MaxPortsToTry",
72 self.portToTrySpin.value())
73
74 bannedUsers = []
75 for row in range(self.bannedUsersList.count()):
76 bannedUsers.append(self.bannedUsersList.item(row).text())
77 Preferences.setCooperation("BannedUsers", bannedUsers)
78
79 @pyqtSlot()
80 def on_bannedUsersList_itemSelectionChanged(self):
81 """
82 Private slot to react on changes of selected banned users.
83 """
84 self.deleteBannedUsersButton.setEnabled(
85 len(self.bannedUsersList.selectedItems()) > 0)
86
87 @pyqtSlot(str)
88 def on_bannedUserEdit_textChanged(self, txt):
89 """
90 Private slot to handle the user entering a banned user.
91
92 @param txt text entered by the user (string)
93 """
94 self.addBannedUserButton.setEnabled(
95 self.__bannedUserValidator.validate(txt, len(txt))[0] ==
96 QValidator.State.Acceptable)
97
98 @pyqtSlot()
99 def on_deleteBannedUsersButton_clicked(self):
100 """
101 Private slot to remove the selected users from the list of
102 banned users.
103 """
104 for itm in self.bannedUsersList.selectedItems():
105 row = self.bannedUsersList.row(itm)
106 itm = self.bannedUsersList.takeItem(row)
107 del itm
108
109 @pyqtSlot()
110 def on_addBannedUserButton_clicked(self):
111 """
112 Private slot to add a user to the list of banned users.
113 """
114 self.bannedUsersList.addItem(self.bannedUserEdit.text())
115 self.bannedUserEdit.clear()
116
117
118 def create(dlg):
119 """
120 Module function to create the configuration page.
121
122 @param dlg reference to the configuration dialog
123 @return reference to the instantiated page (ConfigurationPageBase)
124 """
125 page = CooperationPage()
126 return page

eric ide

mercurial