class BookmarkDetail(QMainWindow, Ui_BookmarkDetail): """ classdocs """ def __init__(self, parent=None): """ Constructor """ QMainWindow.__init__(self, parent) self.setupUi(self) if not config.username or not config.password: login = Login(self) login.setModal(True) login.show() self.setWindowTitle("Delicious bookmarks : %s : save a bookmark" % config.username) clipboard = unicode(QApplication.clipboard().text()) log.debug(" detecting clipboard : %s", clipboard) if clipboard.startswith("http://"): self.url.setText(clipboard) self.url.setDisabled(True) self.show_url.setEnabled(True) self.title.setText(get_title(clipboard)) self.tags.setFocus() @pyqtSignature("") def on_show_url_clicked(self): self.url.setEnabled(True) self.show_url.setDisabled(True) @pyqtSignature("") def on_buttonBox_accepted(self): self.cache = Cache() self.cache.save_post(unicode(self.url.text()), unicode(self.title.text()), unicode(self.tags.text())) QApplication.instance().quit() @pyqtSignature("") def on_buttonBox_rejected(self): QApplication.instance().quit() def keyPressEvent(self, event): if event.key() == QtCore.Qt.Key_Escape: QApplication.instance().quit()
def fill(self): self.setWindowTitle("Delicious bookmarks : %s" % config.username) self.cache = Cache() self.refresh_tags() self.refresh_posts()
class BookmarkList(QMainWindow, Ui_BookmarkList): ''' classdocs ''' def __init__(self, parent = None): """ Constructor """ QMainWindow.__init__(self, parent) self.setupUi(self) self.login() def login(self): if not config.username or not config.password: login = Login(self) ret = login.exec_() if ret != 0: self.fill() else: sys.exit() else: self.fill() def fill(self): self.setWindowTitle("Delicious bookmarks : %s" % config.username) self.cache = Cache() self.refresh_tags() self.refresh_posts() def refresh_tags(self, tag=""): tags = self.cache.find_tags(tag, self.tags_order.currentIndex()) self.tagList.clear() for item in tags: self.tagList.addItem(item[0]) self.tags_count.setText(str(len(tags))) def refresh_posts(self, tag="", exact=False): self.posts = self.cache.find_posts_by_tag(tag, exact, self.posts_order.currentIndex()) self.postList.clear() for item in self.posts: self.postList.addItem(item[0]) self.posts_count.setText(str(len(self.posts))) @pyqtSignature("QString") def on_search_textEdited(self, new_text): self.refresh_tags(unicode(self.search.text())) self.refresh_posts(unicode(self.search.text())) @pyqtSignature("") def on_tagList_itemSelectionChanged(self): if self.tagList.count() != 0: tag = str(self.tagList.currentItem().text()) self.refresh_posts(tag) @pyqtSignature("int") def on_tags_order_currentIndexChanged(self, index): self.refresh_tags(unicode(self.search.text())) @pyqtSignature("int") def on_posts_order_currentIndexChanged(self, index): if self.tagList.currentItem(): tag = unicode(self.tagList.currentItem().text()) self.refresh_posts(tag, True) else: self.refresh_posts(unicode(self.search.text())) @pyqtSignature("QListWidgetItem*") def on_postList_itemDoubleClicked(self, item): index = self.postList.currentRow() post = self.posts[index] log.debug("selected post : %s", post) log.debug("goto url : %s", post[1]) webbrowser.open_new_tab(post[1]) @pyqtSignature("") def on_sign_out_triggered(self): config.username = None config.password = None self.login() @pyqtSignature("") def on_about_qt_triggered(self): QtGui.QMessageBox.aboutQt(self) def keyPressEvent(self, event): if event.key() == QtCore.Qt.Key_Escape: QApplication.instance().quit()
def on_buttonBox_accepted(self): self.cache = Cache() self.cache.save_post(unicode(self.url.text()), unicode(self.title.text()), unicode(self.tags.text())) QApplication.instance().quit()
def fill(self): self.winfo_toplevel().title('Fastlink bookmarks : %s' % config.username) self.cache = Cache() self.refresh_tags() self.refresh_posts() self.start_cache_refresh()
class BoormarkList(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.winfo_toplevel().title("Fastlink bookmarks") self.winfo_toplevel().bind("<Escape>", self.quit_handler) self.grid() self.grid_rowconfigure(0, weight=0, minsize=10, pad=0) self.grid_rowconfigure(2, weight=0, minsize=10, pad=0) self.grid_rowconfigure(4, weight=0, minsize=10, pad=0) self.grid_rowconfigure(6, weight=0, minsize=10, pad=0) self.grid_rowconfigure(8, weight=0, minsize=10, pad=0) self.grid_columnconfigure(0, weight=0, minsize=20, pad=0) self.grid_columnconfigure(2, weight=0, minsize=20, pad=0) self.createWidgets() self.cache = None self.login() def login(self): if not config.username or not config.password: Login(self) if config.username and config.password: self.fill() else: sys.exit() else: self.fill() def fill(self): self.winfo_toplevel().title('Fastlink bookmarks : %s' % config.username) self.cache = Cache() self.refresh_tags() self.refresh_posts() self.start_cache_refresh() def start_cache_refresh(self): self.queue = Queue.Queue() self.refresh() self.spinner.show('Synchronizing...') Thread(target=run_cache_refresh, args=(self.queue,)).start() def refresh(self): try: while 1: val = self.queue.get_nowait() if val: self.refresh_tags() self.refresh_posts() self.spinner.hide() self.update_idletasks() except Queue.Empty: pass self.after(100, self.refresh) def createWidgets(self): self.search = ZEntry(self) self.search.add_listener("<KeyRelease>", self.on_search_changed) self.search.grid(row=1, column=1, sticky=W) self.search.focus() #tag list frame self.tagList = ZListBox(self) self.tagList.grid(row=3, column=1, sticky=W) self.tagList.on_row_click(self.on_tag_clicked) #post list frame self.postList = ZListBox(self, width=60, height=25) self.postList.grid(row=5, column=1, sticky=W) self.postList.on_row_click(self.tagList.clear_selection) self.postList.on_row_dbl_click(self.on_post_dbl_clicked) #status bar self.status = ZStatusBar(self.master) self.status.grid(sticky=W+E) #spinner self.spinner = ZSpinner(self.status, spinner_image) self.spinner.grid() def quit(self): if self.cache: del self.cache Frame.quit(self) def quit_handler(self, event): self.quit() def refresh_tags(self, tag=""): tags = self.cache.find_tags(tag) self.tagList.set_data(tags, lambda item: item[0]) def refresh_posts(self, pattern="", exact=False): if exact: self.posts = self.cache.find_posts_by_tag(pattern, exact) else: self.posts = self.cache.find_posts_by_pattern(pattern) self.postList.set_data(self.posts, lambda item: item[0]) def on_search_changed(self, event): self.refresh_tags(self.search.value()) self.refresh_posts(self.search.value()) def on_tag_clicked(self, event): tag = self.tagList.get_current_row() self.refresh_posts(tag, exact=True) def on_post_dbl_clicked(self, event): index = self.postList.get_current_index() post = self.posts[index] log.debug("selected post : %s", post) log.debug("goto url : %s", post[1]) webbrowser.open_new_tab(post[1])