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