|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to edit feed data. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import pyqtSlot, QUrl |
|
11 from PyQt4.QtGui import QDialog, QDialogButtonBox |
|
12 |
|
13 from .Ui_FeedEditDialog import Ui_FeedEditDialog |
|
14 |
|
15 |
|
16 class FeedEditDialog(QDialog, Ui_FeedEditDialog): |
|
17 """ |
|
18 Class implementing a dialog to edit feed data. |
|
19 """ |
|
20 def __init__(self, urlString, title, parent=None): |
|
21 """ |
|
22 Constructor |
|
23 |
|
24 @param parent reference to the parent widget (QWidget) |
|
25 """ |
|
26 super().__init__(parent) |
|
27 self.setupUi(self) |
|
28 |
|
29 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
|
30 |
|
31 self.titleEdit.setText(title) |
|
32 self.urlEdit.setText(urlString) |
|
33 |
|
34 def __setOkButton(self): |
|
35 """ |
|
36 Private slot to enable or disable the OK button. |
|
37 """ |
|
38 enable = True |
|
39 |
|
40 enable = enable and bool(self.titleEdit.text()) |
|
41 |
|
42 urlString = self.urlEdit.text() |
|
43 enable = enable and bool(urlString) |
|
44 if urlString: |
|
45 url = QUrl(urlString) |
|
46 enable = enable and bool(url.scheme()) |
|
47 enable = enable and bool(url.host()) |
|
48 |
|
49 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable) |
|
50 |
|
51 @pyqtSlot(str) |
|
52 def on_titleEdit_textChanged(self, txt): |
|
53 """ |
|
54 Private slot to handle changes of the feed title. |
|
55 |
|
56 @param txt new feed title (string) |
|
57 """ |
|
58 self.__setOkButton() |
|
59 |
|
60 @pyqtSlot(str) |
|
61 def on_urlEdit_textChanged(self, p0): |
|
62 """ |
|
63 Private slot to handle changes of the feed URL. |
|
64 |
|
65 @param txt new feed URL (string) |
|
66 """ |
|
67 self.__setOkButton() |
|
68 |
|
69 def getData(self): |
|
70 """ |
|
71 Public method to get the entered feed data. |
|
72 |
|
73 @return tuple of two strings giving the feed URL and feed title |
|
74 (string, string) |
|
75 """ |
|
76 return (self.urlEdit.text(), self.titleEdit.text()) |