Commits

thijsdezoete committed 6ba6a5d

moar works

Comments (0)

Files changed (3)

     def add_icon(self, file, name='filename'):
             pass
 
+    def reset_menu(self):
+        # del self.menu
+        self.menu.clear()
+        # self.top_icon.setContextMenu(self.menu)
+
     def change_icon(self, element, icon):
         element.setIcon(icon)
         try:
         # self.menu.addAction('Initialise API', self.init_api)
         # self.menu.addAction('New Tray App', self._show_tray_add)
         self.menu.addAction('Quit', self._quit)
-        self.menu.addSeparator()
+        # self.menu.addSeparator()
 
     def _quit(self):
         # for icon in self.favicon.icons:
 
 APP = ['testing.py']
 DATA_FILES = []
-OPTIONS = {'argv_emulation': False, 'includes': ['indicate']}
+OPTIONS = {'argv_emulation': False,
+    'includes': ['indicate'],
+    'excludes': ['QtDeclarative', 'QtHelp']
+    # 'ISBackgroundOnly': True
+}
 
 setup(
     app=APP,
 from urlparse import urlparse
 # import sys
 import os
-# from PyQt4 import QtGui
+from PyQt4 import QtGui
+from PyQt4 import QtCore
+
+
+class ChooseRedditWindow(QtGui.QDialog):
+    def __init__(self, parent=None):
+        super(ChooseRedditWindow, self).__init__()
+
+        self.subreddit = QtGui.QLineEdit("python")
+        self.buttonBox = QtGui.QGroupBox("Subreddit type")
+        self.buttonLayout = QtGui.QVBoxLayout()
+
+        self.hot = QtGui.QRadioButton("Hot")
+        self.hot.setChecked(True)
+        self.new = QtGui.QRadioButton("New")
+        self.ris = QtGui.QRadioButton("Rising")
+        self.top = QtGui.QRadioButton("Top")
+
+        self.buttons = [self.hot, self.new, self.ris, self.top]
+
+        self.buttonLayout.addWidget(self.hot)
+        self.buttonLayout.addWidget(self.new)
+        self.buttonLayout.addWidget(self.ris)
+        self.buttonLayout.addWidget(self.top)
+        self.buttonBox.setLayout(self.buttonLayout)
+
+        self.confirm = QtGui.QPushButton("&Confirm")
+        self.confirm.clicked.connect(self.get_favicon)
+
+        self.parent = parent
+        self.subreddit.selectAll()
+        QtCore.QObject.connect(self.subreddit, QtCore.SIGNAL('returnPressed()'), self.get_favicon)
+        QtCore.QObject.connect(self, QtCore.SIGNAL('focusIn()'), self.subreddit.setFocus)
+
+        self.layout = QtGui.QGridLayout()
+
+        self.layout.addWidget(QtGui.QLabel("What subreddit do you wish to be kept informed about?"), 0, 0)
+        self.layout.addWidget(self.subreddit, 1, 0)
+
+        # self.layout.addWidget(QtGui.QLabel("Which subcategory?"), 2, 0)
+        self.layout.addWidget(self.buttonBox, 2, 0)
+
+        self.layout.addWidget(self.confirm, 3, 2)
+
+        self.setLayout(self.layout)
+        self.subreddit.setFocus()
+        self.setWindowTitle('New subreddit to follow')
+
+    def get_favicon(self):
+        print 'Clickety-click!!!'
+        sub = str(self.subreddit.text())
+        # reddit_type = str(self.subreddit.text())
+        print 'Subreddit value: %s' % sub
+        reddit_type = str([r.text() for r in self.buttons if r.isChecked()][0]).lower()
+        print 'Button checked: %s' % str(reddit_type)
+        self.parent.add_subreddit(sub, reddit_type)
+        return
+
+        # self.parent.add_icon(icon, url)
+        # lbl = QtGui.QLabel("placeholder")
+
+        # lbl.setPixmap(self._icon_pixmap)
+        # self.layout.addWidget(
+        #     lbl, 1, 0
+        # )
+
+        # self.parent.add_icon_to_menu(url, 'Change tray to this image', lambda: self.hello(url))
 
 
 class Reddit(object):
         self.parent.favicon.get('www.reddit.com')
         self.parent.set_top_icon('www.reddit.com')
         self.items = {}
+        self.subreddits = {}
+        self.subredditwindow = ChooseRedditWindow(parent=self)
 
     def click_link(self, link):
         os.system('open %s' % link)
 
     def process_item(self, item, url):
         base_url = str(urlparse(url).netloc)
-        self.parent.favicon.get(base_url)
-        self.items[item] = url
-        self.parent.add_icon_to_menu(base_url,
+        if not item in self.items:
+            self.items[item] = url
+            self.parent.favicon.get(base_url)
+
+        self.parent.add_icon_to_menu(
+            base_url,
             item,
             lambda: self.click_link(self.items[item])
         )
+        print 'Processed item...'
+
+    def add_refresh_btn(self):
+        self.parent.add_to_menu('Renew entries', self.renew_entries)
+
+    def add_new_reddit_btn(self):
+        self.parent.add_to_menu('New subreddit', self._show_subreddit)
+
+    def add_subreddit(self, subreddit, subreddit_type='hot'):
+        if not subreddit in self.subreddits:
+            self.subreddits[subreddit] = subreddit_type
 
-    def get_subreddit(self, sub):
-        url = '{0}r/{1}/{2}.json?sort={2}&limit={3}'.format(self.url, sub, 'hot', '10')
-        posts = requests.get(url).json()
+    def renew_entries(self):
+        print 'Renewing itemlist'
+        self.parent.reset_menu()
+        self.add_refresh_btn()
+        self.add_new_reddit_btn()
+        self.parent.add_separator()
+
+        for sub in self.subreddits:
+            self.get_subreddit(sub, self.subreddits[sub])
+            self.parent.add_separator()
+
+        self.parent.add_quit_btn()
+
+    def get_subreddit(self, sub, reddit_type='hot'):
+        json_url = '{0}r/{1}/{2}.json?sort={2}&limit={3}'.format(self.url, sub, reddit_type, '10')
+        posts = requests.get(json_url).json()
         links = [(x['data']['title'][:20] + '...', str(x['data']['url'])) for x in posts['data']['children'] if x['kind'] == u't3']
+        # print links
 
         [self.process_item(item, url) for (item, url) in links]
 
+    def _show_subreddit(self):
+        print 'Show that window!'
+        self.subredditwindow.raise_()
+        self.subredditwindow.activateWindow()
+        self.parent.app.setActiveWindow(self.subredditwindow)
+        self.parent.app.restoreOverrideCursor()
+        self.subredditwindow.show()
+
     def run(self, subreddit="python"):
-        self.get_subreddit(subreddit)
-        self.parent.add_separator()
-        self.get_subreddit('php')
+        self.parent.reset_menu()
+        # self.add_subreddit('python')
+        # self.add_subreddit('php')
+        self.renew_entries()
+        # self.get_subreddit(subreddit)
+        # self.parent.add_separator()
+        # self.get_subreddit('php')
 
         self.parent.run()