def main(self): """ Run main application """ self.main_tk = Tk.Tk() self.main_tk.title('Trakt.tv Playback Progress Remover') set_icon(self.main_tk) self.busyman = BusyManager(self.main_tk) self.main_win = MainScreen(self.main_tk, self) center_toplevel(self.main_tk) auth_opened = self.show_auth_window() self.busyman.busy() if self.authorization and not auth_opened: try: self.update_user_info(raise_on_error=True) self.refresh_list(raise_on_error=True) except auth.NotAuthenticatedError: self._authorization = None auth.remove(self.auth_filepath) self.main_win.toggle_auth_button(True) self.main_win.lbl_loggedin.set('Not logged in.') tk_messagebox.showwarning('Error', 'Authentication required.') self.busyman.unbusy() self.main_tk.mainloop()
def _mouseWheel(self, event): """ Mouse wheel moved """ # event.num == 4 -> up # event.num == 5 -> down #print "mouse wheel ",event val = self.odf[self.selectedPar.get()] pname = self.selectedPar.get() try: if self.modModus.get() == "add": mf = float(self.modEntryTextAdd.get()) elif self.modModus.get() == "mul": mf = float(self.modEntryTextMul.get()) except ValueError: tkMessageBox.showwarning("Invalid float", "Cannot convert " + self.modEntry.get() + " to float." + \ " Make it a valid value to proceed.") return if event.num == 4: if self.modModus.get() == "mul": self.odf[pname] = val * mf else: self.odf[pname] = val + mf elif event.num == 5: if self.modModus.get() == "mul": self.odf[pname] = val / mf else: self.odf[pname] = val - mf self._parameterValueChanged()
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 ev_displayOPD(self): self._updateFromGUI() if self.inst.pupilopd is None: tkMessageBox.showwarning( message="You currently have selected no OPD file (i.e. perfect telescope) so there's nothing to display.", title="Can't Display") else: if self._enable_opdserver and 'ITM' in self.opd_name: opd = self.inst.pupilopd # will contain the actual OPD loaded in _updateFromGUI just above else: opd = fits.getdata(self.inst.pupilopd[0]) # in this case self.inst.pupilopd is a tuple with a string so we have to load it here. if len(opd.shape) >2: opd = opd[self.opd_i,:,:] # grab correct slice masked_opd = np.ma.masked_equal(opd, 0) # mask out all pixels which are exactly 0, outside the aperture cmap = matplotlib.cm.jet cmap.set_bad('k', 0.8) plt.clf() plt.imshow(masked_opd, cmap=cmap, interpolation='nearest', vmin=-0.5, vmax=0.5) plt.title("OPD from %s, #%d" %( os.path.basename(self.opd_name), self.opd_i)) cb = plt.colorbar(orientation='vertical') cb.set_label('microns') f = plt.gcf() plt.text(0.4, 0.02, "OPD WFE = %6.2f nm RMS" % (masked_opd.std()*1000.), transform=f.transFigure) self._refresh_window()
def _okClicked(self, *args): try: mf = float(self.inputVal.get()) except ValueError: tkMessageBox.showwarning("Invalid float", "Cannot convert " + self.modEntry.get() + " to float." + \ " Make it a valid value to proceed.") return self.newVal = mf self._cancelClicked()
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 _fetch_list(self): if not self.authorization: tk_messagebox.showwarning('Error', 'Authentication required.') raise auth.NotAuthenticatedError() def make_items(data): for obj in itervalues(playback): if isinstance(obj, Show): for (_sk, _ek), episode in obj.episodes(): yield (episode.id, episode) elif isinstance(obj, Movie): yield (obj.id, obj) # Fetch playback try: playback = Trakt['sync/playback'].get(exceptions=True) except ClientError as error: raise_from(auth.NotAuthenticatedError(), error) return list(make_items(playback))
def _onWheel(self, event): val = self.odf[self.selectedPar.get()] pname = self.selectedPar.get() try: if self.modModus.get() == "add": mf = float(self.modEntryTextAdd.get()) elif self.modModus.get() == "mul": mf = float(self.modEntryTextMul.get()) except ValueError: tkMessageBox.showwarning("Invalid float", "Cannot convert " + self.modEntry.get() + " to float." + \ " Make it a valid value to proceed.") return if self.modModus.get() == "mul": if event.delta>0: self.odf[pname] = val * mf else: self.odf[pname] = val / mf else: self.odf[pname] = val + mf * event.delta/2. self._parameterValueChanged()
def ev_launch_ITM_dialog(self): tkMessageBox.showwarning(message="ITM dialog box not yet implemented", title="Can't Display")
def ev_launch_ITM_dialog(self): tkMessageBox.showwarning( message="ITM dialog box not yet implemented", title="Can't Display")