|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to edit feed data. |
|
8 """ |
|
9 |
|
10 from PyQt5.QtCore import pyqtSlot, QUrl |
|
11 from PyQt5.QtWidgets 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 urlString feed URL (string) |
|
25 @param title feed title (string) |
|
26 @param parent reference to the parent widget (QWidget) |
|
27 """ |
|
28 super().__init__(parent) |
|
29 self.setupUi(self) |
|
30 |
|
31 self.buttonBox.button( |
|
32 QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
|
33 |
|
34 self.titleEdit.setText(title) |
|
35 self.urlEdit.setText(urlString) |
|
36 |
|
37 msh = self.minimumSizeHint() |
|
38 self.resize(max(self.width(), msh.width()), msh.height()) |
|
39 |
|
40 def __setOkButton(self): |
|
41 """ |
|
42 Private slot to enable or disable the OK button. |
|
43 """ |
|
44 enable = True |
|
45 |
|
46 enable = enable and bool(self.titleEdit.text()) |
|
47 |
|
48 urlString = self.urlEdit.text() |
|
49 enable = enable and bool(urlString) |
|
50 if urlString: |
|
51 url = QUrl(urlString) |
|
52 enable = enable and bool(url.scheme()) |
|
53 enable = enable and bool(url.host()) |
|
54 |
|
55 self.buttonBox.button( |
|
56 QDialogButtonBox.StandardButton.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()) |