class Login(ZDialog): def __init__(self, master=None): ZDialog.__init__(self, master, "Login to Del.icio.us") def body(self, master): master.grid_rowconfigure(0, weight=0, minsize=10, pad=0) master.grid_rowconfigure(2, weight=0, minsize=10, pad=0) master.grid_rowconfigure(4, weight=0, minsize=10, pad=0) self.username = ZEntry(master, label="Username : "******"Password : "******"Error","Username not specified") return 0; elif not self.password.value(): tkMessageBox.showwarning("Error","Password not specified") return 0; else: return 1; def apply(self): config.username = self.username.value() config.password = self.password.value() log.debug(" login...username : %s, password : %s", config.username, config.password)
def create_widgets(self): try: clipboard = self.selection_get(selection="CLIPBOARD") except TclError: clipboard = '' log.debug(" detecting clipboard : %s", clipboard) if clipboard.startswith("http://"): self.url = ZEntry(self, label="Url : ", value=clipboard, width=50, state=DISABLED) self.title = ZEntry(self, label="Title : ", value=get_title(clipboard), width=50) else: self.url = ZEntry(self, label="Url : ", width=50) self.title = ZEntry(self, label="Title : ", width=50) self.url.add_listener("<Double-Button-1>", self.on_url_dbl_click) self.url.grid(row=1, column=1) self.title.grid(row=3, column=1) self.tags = ZEntry(self, label="Tags : ", width=50) self.tags.grid(row=5, column=1) self.tags.focus() box = Frame(self) w = Button(box, text="Save", command=self.save_post, width=10, default=ACTIVE) w.pack(side=LEFT, padx=5, pady=5) w = Button(box, text="Cancel", command=self.quit, width=10) w.pack(side=LEFT, padx=5, pady=5) self.winfo_toplevel().bind("<Return>", self.save_post) box.grid(row=7, column=1) self.tags_suggest = ZSuggestion(self.tags, multi=True)
def body(self, master): master.grid_rowconfigure(0, weight=0, minsize=10, pad=0) master.grid_rowconfigure(2, weight=0, minsize=10, pad=0) master.grid_rowconfigure(4, weight=0, minsize=10, pad=0) self.username = ZEntry(master, label="Username : "******"Password : ", value=config.password) self.password.grid(row=3, column=1) return self.username
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()
class BookmarkDetail(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.winfo_toplevel().title('Fastlink bookmarks: save a bookmark') 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.create_widgets() self.after_idle(center_on_screen, self) 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 : save a bookmark' % config.username) self.winfo_toplevel().bind("<Escape>", self.quit_handler) self.cache = Cache() self.tags_suggest.set_find_func(self.cache.find_tags) def create_widgets(self): try: clipboard = self.selection_get(selection="CLIPBOARD") except TclError: clipboard = '' log.debug(" detecting clipboard : %s", clipboard) if clipboard.startswith("http://"): self.url = ZEntry(self, label="Url : ", value=clipboard, width=50, state=DISABLED) self.title = ZEntry(self, label="Title : ", value=get_title(clipboard), width=50) else: self.url = ZEntry(self, label="Url : ", width=50) self.title = ZEntry(self, label="Title : ", width=50) self.url.add_listener("<Double-Button-1>", self.on_url_dbl_click) self.url.grid(row=1, column=1) self.title.grid(row=3, column=1) self.tags = ZEntry(self, label="Tags : ", width=50) self.tags.grid(row=5, column=1) self.tags.focus() box = Frame(self) w = Button(box, text="Save", command=self.save_post, width=10, default=ACTIVE) w.pack(side=LEFT, padx=5, pady=5) w = Button(box, text="Cancel", command=self.quit, width=10) w.pack(side=LEFT, padx=5, pady=5) self.winfo_toplevel().bind("<Return>", self.save_post) box.grid(row=7, column=1) self.tags_suggest = ZSuggestion(self.tags, multi=True) def on_url_dbl_click(self, event): if self.url["state"] == DISABLED: self.url["state"] = NORMAL def _wait_for_save(self): try: while 1: val = self.queue.get_nowait() if 'ERROR' in val: self.splash.hide() import tkMessageBox tkMessageBox.showerror('Error during saving', val) else: self.splash.hide() self.update_idletasks() self.quit() except Queue.Empty: pass self.after(100, self._wait_for_save) def save_post(self, event=None): self.splash = ZSplashScreen(self, image_file=spinner_image) self.queue = Queue.Queue() self._wait_for_save() Thread(target=run, args=(self.queue, self.url.value(), self.title.value(), self.tags.value())).start() self.splash.show('Saving...') def quit_handler(self, event): self.quit()
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])