-
Notifications
You must be signed in to change notification settings - Fork 0
/
SettingsDialogue.py
60 lines (54 loc) · 2.2 KB
/
SettingsDialogue.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
""" Dialogue for entering user settings into the app """
import diag
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from Settings import Settings
class SettingsDialogue(QDialog, diag.Ui_Dialog):
""" this should pop up a settings window """
def __init__(self, settings, parent=None):
super(SettingsDialogue, self).__init__(parent)
self.setupUi(self)
self.pushAddButton.clicked.connect(self._slotAddClicked)
self.settings = settings
self.settings.load_settings()
self.lineEditRefresh.setText(str(self.settings.refresh_time))
self.lineEditAlertAt.setText(str(self.settings.alert_time))
for u in self.settings.uri_list:
self.listWidgetUrls.addItem(QListWidgetItem(u))
self.listWidgetUrls.itemClicked.connect(self._slotItemClicked)
self.lineEditUrl.setFocus()
def _slotItemClicked(self):
""" clicked on an item in the list widget """
item = self.listWidgetUrls.takeItem(self.listWidgetUrls.currentRow())
item = None
def _slotAddClicked(self):
""" clicked on the add button """
text = self.lineEditUrl.text()
self.listWidgetUrls.addItem(QListWidgetItem(text))
text = str(text)
self.settings.uri_list.append(text)
self.lineEditUrl.clear()
def accept(self, *args, **kwargs):
""" Runs when the OK button is pressed and exits the dialogue """
self.settings.refresh_time = int(self.lineEditRefresh.text())
self.settings.alert_time = int(self.lineEditAlertAt.text())
self.settings.uri_list = []
items = self.return_items()
for i in items:
item_text = str(i.text()).strip()
if item_text == '':
pass
else:
self.settings.uri_list.append(str(i.text()))
self.settings.save_settings()
return QDialog.accept(self, *args, **kwargs)
def return_items(self):
""" Fetch all the items in the list widget """
for i in xrange(self.listWidgetUrls.count()):
yield self.listWidgetUrls.item(i)
if __name__=='__main__':
app = QApplication(sys.argv)
MA = SettingsDialogue()
MA.show()
app.exec_()