Helpviewer/Feeds/FeedsDialog.py

Thu, 10 Oct 2013 18:35:45 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 10 Oct 2013 18:35:45 +0200
changeset 3002
6ffc581f00f1
parent 2403
e3d7a861547c
child 3020
542e97d4ecb3
child 3057
10516539f238
permissions
-rw-r--r--

Continued to shorten the code lines to max. 79 characters.

1415
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
2302
f29e9405c851 Updated copyright for 2013.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2192
diff changeset
3 # Copyright (c) 2011 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>
1415
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to add RSS feeds.
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from PyQt4.QtCore import QUrl
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 from PyQt4.QtGui import QDialog, QPushButton, QLabel
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from E5Gui import E5MessageBox
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from .Ui_FeedsDialog import Ui_FeedsDialog
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import UI.PixmapCache
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 class FeedsDialog(QDialog, Ui_FeedsDialog):
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Class documentation goes here.
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 def __init__(self, availableFeeds, browser, parent=None):
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Constructor
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
28 @param availableFeeds list of available RSS feeds (list of tuple of
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
29 two strings)
1415
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @param browser reference to the browser widget (HelpBrowser)
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 @param parent reference to the parent widget (QWidget)
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 super().__init__(parent)
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.setupUi(self)
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 self.iconLabel.setPixmap(UI.PixmapCache.getPixmap("rss48.png"))
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 self.__browser = browser
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 self.__availableFeeds = availableFeeds[:]
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 for row in range(len(self.__availableFeeds)):
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 feed = self.__availableFeeds[row]
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 button = QPushButton(self)
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 button.setText(self.trUtf8("Add"))
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 button.feed = feed
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 label = QLabel(self)
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 label.setText(feed[0])
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.feedsLayout.addWidget(label, row, 0)
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 self.feedsLayout.addWidget(button, row, 1)
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 button.clicked[()].connect(self.__addFeed)
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 def __addFeed(self):
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 """
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 Private slot to add a RSS feed.
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 button = self.sender()
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 urlString = button.feed[1]
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 url = QUrl(urlString)
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 if not url.host():
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 if not urlString.startswith("/"):
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 urlString = "/" + urlString
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 urlString = self.__browser.url().host() + urlString
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 tmpUrl = QUrl(urlString)
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 if not tmpUrl.scheme():
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 urlString = "http://" + urlString
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 tmpUrl = QUrl(urlString)
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 if not tmpUrl.scheme() or not tmpUrl.host():
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 return
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 if not url.isValid():
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 return
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 if button.feed[0]:
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 title = button.feed[0]
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 else:
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 title = self.__browser.url().host()
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
77 import Helpviewer.HelpWindow
1415
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 feedsManager = Helpviewer.HelpWindow.HelpWindow.feedsManager()
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 if feedsManager.addFeed(urlString, title, self.__browser.icon()):
2192
61b3849df76d Changed a few places to use the new notification system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
80 if Helpviewer.HelpWindow.HelpWindow.notificationsEnabled():
61b3849df76d Changed a few places to use the new notification system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
81 Helpviewer.HelpWindow.HelpWindow.showNotification(
61b3849df76d Changed a few places to use the new notification system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
82 UI.PixmapCache.getPixmap("rss48.png"),
61b3849df76d Changed a few places to use the new notification system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
83 self.trUtf8("Add RSS Feed"),
61b3849df76d Changed a few places to use the new notification system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
84 self.trUtf8("""The feed was added successfully."""))
61b3849df76d Changed a few places to use the new notification system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
85 else:
61b3849df76d Changed a few places to use the new notification system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
86 E5MessageBox.information(self,
61b3849df76d Changed a few places to use the new notification system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
87 self.trUtf8("Add RSS Feed"),
61b3849df76d Changed a few places to use the new notification system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
88 self.trUtf8("""The feed was added successfully."""))
1415
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 else:
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 E5MessageBox.warning(self,
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 self.trUtf8("Add RSS Feed"),
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 self.trUtf8("""The feed was already added before."""))
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 self.close()

eric ide

mercurial