eric6/Preferences/ConfigurationPages/CooperationPage.py

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

eric ide

mercurial