def button_done_command(self): """ When user has clicked 'Done' after completing auth process """ # Exchange `code` for `access_token` pin = self.pin_code.get() if len(pin) != 8: tk_messagebox.showwarning('Warning', 'The PIN code is invalid.', parent=self.parent) return False self.root.authorization = Trakt['oauth'].token_exchange( pin, 'urn:ietf:wg:oauth:2.0:oob') if not self.root.authorization: tk_messagebox.showwarning('Warning', 'Login unsuccessful.', parent=self.parent) self.destroy() else: tk_messagebox.showinfo('Message', 'Login successful.', parent=self.parent) self.destroy() self.root.update_user_info() self.root.refresh_list()
def dump_log(self): """Dumps the contents of the text widget to a text file""" destination = tkFileDialog.asksaveasfilename(defaultextension='.txt') text = self.text_box.get(1.0,Tk.END) if destination: with open(destination,'w') as log: log.write(text) tkMessageBox.showinfo('Success','Log saved successfully!')
def support_ask_ordered_files(self, arg, **kwargs): if arg is self.root_node.constants.ASK_ORDERED_FILES: file_list = [] while True: filename = askopenfilename(**kwargs) if filename: file_list.append(filename) kwargs['initialdir'] = os.path.split(filename)[0] if not askyesno('Continue?', 'Continue selecting files?'): break arg = file_list showinfo('File List', 'The following files are selected:\n' + '\n'.join(arg)) self._print_actual_value(self.root_node.constants.ASK_ORDERED_FILES, arg) return arg
def _btn_remove_selected_command(self): if not self.root.authorization: tk_messagebox.showwarning('Error', 'Authentication required.') return False listbox = self._listbox selection = listbox.curselection() count = len(selection) if not count: return False confirm = tk_messagebox.askyesno( 'Confirm action', 'Are you sure you want to remove {many}the' ' selected item{plural} from your Trakt database?'.format( many='all of ' if count > 1 else '', plural='s' if count > 1 else '')) if not confirm: return False self.root.busyman.busy() failed_at = None removed_count = 0 for list_index in reversed(selection): current = self.root.playback_ids[list_index] response = Trakt['sync/playback'].delete(current[0]) if not response: failed_at = current break self.root.playback_ids.pop(list_index) removed_count += 1 if failed_at is not None: tk_messagebox.showwarning( 'Warning', 'Something went wrong with {id}:\n{item}'.format( id=failed_at[0], item=failed_at[1])) else: tk_messagebox.showinfo( 'Success', '{count} item{plural} removed.'.format( count=removed_count, plural='s' if removed_count > 1 else '')) self.root.refresh_list(local=True) self.root.update_info([]) self.root.busyman.unbusy()
def stop_currently_playing(self): playing = Trakt.http.get('users/me/watching') if playing.status_code == 401: tk_messagebox.showwarning('Error', 'Authentication required.') return False if playing.status_code != 200: tk_messagebox.showinfo('Message', 'Nothing is playing right now.') return False playing = playing.json() def progress(): expires = arrow.get(playing['expires_at']).timestamp started = arrow.get(playing['started_at']).timestamp now = arrow.utcnow().timestamp watched = now - started total = expires - started return (watched / total) * 100 itemType = playing['type'] params = { 'progress': progress(), itemType: { 'ids': { 'trakt': playing[itemType]['ids']['trakt'], } } } Trakt['scrobble'].pause(**params) if playing['type'] == 'episode': itemInfo = '{0[show][title]} {0[episode][season]}x{0[episode][number]} "{0[episode][title]}"'.format( playing) elif playing['type'] == 'movie': itemInfo = '{0[movie][title]} ({0[movie][year]})'.format(playing) else: itemInfo = '(Unknown)' tk_messagebox.showinfo( 'Message', 'Ok. Current playing {0}:\n{1}\nstopped at {2}%.'.format( itemType, itemInfo, int(params['progress'])))
def refresh_list(self, local=False, raise_on_error=False): """ Refreshes the Listbox with items, source depends on the value of `local` :param local: if False, uses Trakt.tv's database, otherwise uses the playback_ids array """ self.main_win.listbox_clear_all() # Clear if not local: try: self.playback_ids = self._fetch_list() except auth.NotAuthenticatedError as error: if raise_on_error: raise error self.playback_ids = [] return False if not self.playback_ids: if not local: tk_messagebox.showinfo('Message', 'There are no items to remove.') return True def make_list_item(idx, item): if isinstance(item, Episode): return '{id:03d}. {show}: S{se:02d}E{ep:02d} ({title})'.format( id=idx, show=item.show.title, se=item.pk[0], ep=item.pk[1], title=item.title) elif isinstance(item, Movie): return '{id:03d}. {title} ({year})'.format(id=idx, title=item.title, year=item.year) else: return None # populate list generator = map(itemgetter(1), self.playback_ids) list_items = filter(None, [ make_list_item(idx, item) for idx, item in enumerate(generator, 1) ]) self.main_win.listbox_insert(Tk.END, list_items)
def open(self): self.button_save.config(state=tk.DISABLED) fp = tkinter_tkfiledialog.askopenfile(mode='rb', initialdir=self.dirname, **self.file_type_opt) if fp is None: return with fp: self.button_save.config(state=tk.DISABLED) self.dirname = os.path.dirname(fp.name) try: s = BytesIO() with zipfile.ZipFile(fp, 'r') as zipin, \ zipfile.ZipFile(s, 'w') as zipout: xlsx_remove_protections(zipin, zipout) self.output = s.getvalue() assert (len(self.output) > 0) except Exception as e: logging.exception(e) tkinter_messagebox.showinfo(title='Error', message='Format not supported.') return self.button_save.config(state=tk.NORMAL)
def about(self): tkMessageBox.showinfo( title="About PINTk", message="A Tkinter based graphical interface to PINT")
def on_finished(self): showinfo(title=_("Generation completed").get(), message=_("No errors were reported.").get()) self.__finalize()
def searchid13(): global aa2 aaa9 = aa2.get() if aaa9.find('?;600764') > 0: aaa = aaa9[aaa9.find('?;600764')+8:aaa9.find('?;600764')+21] print(aaa) aa2.delete(0,250) # aa8.destroy() to delete block aa8 aa2.insert(0,aaa) else: aaa = aaa9 print(aaa) if aaa.isdigit(): print("is number") else: print("is not number") sv1 = StringVar(root,value="ต้องใส่ตัวเลขเท่านั้น") aa=Entry(root,textvariable=sv1) #creating entry box aa.grid(row=5,column=6) initkri() return if len(aaa)!= 13: print("ใส่เลขไม่ครบ 13 หลัก") sv1 = StringVar(root,value="ใส่เลขไม่ครบ 13 หลัก") aa=Entry(root,textvariable=sv1) #creating entry box aa.grid(row=5,column=6) return khn2 = "" try: print(db_config) print('Connecting to MySQL database...') conn = MySQLConnection(**db_config) #conn = MySQLdb.connect(charset='utf8', init_command='SET NAMES UTF8') print('Connection Successful!!!') cursor = conn.cursor () cursor.execute ("SELECT hn,name,surname,xn,brdate,id13 FROM krieng where trim(xn)<>'old' and id13='"+aaa.strip()+"';") acount = 0 while True: rows = cursor.fetchmany () if not rows: cursor.close () conn.close () if acount == 0: print("ไม่พบid13 นี้") sv1 = StringVar(root,value="ไม่พบid13 นี้") aa=Entry(root,textvariable=sv1) #creating entry box aa.grid(row=5,column=6) initkri() if acount >= 2: print("มีid13 จำนวน"+str(acount)) sv1 = StringVar(root,value="มีid13 จำนวน"+str(acount)) aa=Entry(root,textvariable=sv1) #creating entry box aa.grid(row=5,column=6) messagebox.showinfo("Information","มี id13 ซ้ำกันจำนวน "+str(acount)+" ให้แก้ไขด้วย") # An information box break for row in rows: khn = row[0] khn2 = khn2+","+str(khn) print("HN =:", row[0]) sv1 = StringVar(root,value=khn) aa=Entry(root,textvariable=sv1) #creating entry box aa.grid(row=5,column=6) # Label(root,text=aaa.strip()).grid(row=5,column=4) #Creating label Label(root,text=row[5]).grid(row=12,column=6) #Creating label sv3 = StringVar(root,value=khn2) aa3=Entry(root,textvariable=sv3) #creating entry box aa3.grid(row=6,column=6) sv4 = StringVar(root,value=row[1]+" "+row[2]) aa4=Entry(root,textvariable=sv4) #creating entry box aa4.grid(row=7,column=1) sv5 = StringVar(root,value='XN:'+row[3]) aa5=Entry(root,textvariable=sv5) #creating entry box aa5.grid(row=7,column=4) sv6 = StringVar(root,value=str(row[4])) aa6=Entry(root,textvariable=sv6) #creating entry box aa6.grid(row=7,column=6) print(khn) print(row[1]+" "+row[2]) acount += 1 print(acount) except Exception as e: print (e) sv1 = StringVar(root,value="ไม่สามารถเชื่อม mysql ได้") aa=Entry(root,textvariable=sv1) #creating entry box aa.grid(row=5,column=6) print("ไม่สามารถเชื่อม mysql ได้") except : print("Unknow error occured")
def cancel(self, action): message = 'Library {} operation cancelled'.format(action.lower()) print(message) tkMessageBox.showinfo(message=message) sys.exit(0)
def success(self, action): message = 'Library {} operation succesful'.format(action.lower()) print(message) tkMessageBox.showinfo(message=message)
def info(self, text, trace): messagebox.showinfo('Info', text)
def cancel(self, action): message = addon_import_cancel_message.format(action.lower()) print(message) if self.args.addon_path is None: tkMessageBox.showinfo(message=message) sys.exit(0)
def success(self, action): message = addon_import_success_message.format(action.lower()) print(message) if self.args.addon_path is None: tkMessageBox.showinfo(message=message)