class TokenInputGUI(object):
    def show_entry_fields(self, event=None):
        self.code = self.e1.get()
        self.master.withdraw()
        self.master.quit()

    def quit(self):
        self.master.quit()
        self.code = None

    def doGUI(self, hostname=None):
        self.master = Tk()
        self.master.title('Blessclient - MFA')
        textmsg = 'Enter your AWS MFA code: '
        if hostname:
            textmsg = 'Enter your AWS MFA code to connect to {}: '.format(
                hostname)
        Label(self.master, text=textmsg).grid(row=0)
        self.e1 = Entry(self.master)
        self.e1.grid(row=0, column=1, padx=4)
        Button(self.master,
               text='OK',
               command=self.show_entry_fields,
               default=ACTIVE).grid(row=3, column=0, sticky=W, pady=4)
        Button(self.master, text='Cancel', command=self.quit).grid(row=3,
                                                                   column=1,
                                                                   sticky=W,
                                                                   pady=4)

        self.center()
        self.master.bind('<Return>', self.show_entry_fields)
        self.master.lift()
        self.master.attributes('-topmost', True)
        self.master.focus_force()
        self.e1.focus_set()

        if platform.system() == 'Darwin':
            # Hack to get the GUI dialog focused in OSX
            # https://stackoverflow.com/questions/1892339/how-to-make-a-tkinter-window-jump-to-the-front/37235492#37235492
            tmpl = 'tell application "System Events" to set frontmost of every process whose unix id is {} to true'
            script = tmpl.format(os.getpid())
            subprocess.check_call(['/usr/bin/osascript', '-e', script])

        mainloop()

    # http://stackoverflow.com/questions/3352918/how-to-center-a-window-on-the-screen-in-tkinter
    def center(self):
        self.master.update_idletasks()
        w = self.master.winfo_screenwidth()
        h = self.master.winfo_screenheight()
        size = tuple(
            int(_) for _ in self.master.geometry().split('+')[0].split('x'))
        x = w / 2 - size[0] / 2
        y = h / 2 - size[1] / 2
        self.master.geometry("%dx%d+%d+%d" % (size + (x, y)))
Esempio n. 2
0
class LoginDialog(object):
    def __init__(self, host):
        self.__interna_init()
        self.__host = host
        self.__initialized = False
        if TKTk is not None:
            self.__create_content()
            self.__initialized = True

    def __interna_init(self):
        self.__rootFrame = None
        self.__top = None
        self.__usrEntry = None
        self.__pwdEntry = None
        self.__accepted = False
        self.__host = None
        self.__usr = None
        self.__pwd = None

    def __cancel_action(self):
        self.__accepted = False
        self.__rootFrame.destroy()

    def __login_action(self):
        self.__accepted = True
        self.__usr = self.__usrEntry.get()
        self.__pwd = self.__pwdEntry.get()
        self.__rootFrame.destroy()

    def __enter_action(self, event):
        self.__login_action()

    def __create_content(self):
        self.__rootFrame = TKTk()
        self.__rootFrame.withdraw()

        self.__top = TKToplevel(self.__rootFrame)
        self.__top.title("Login")
        self.__top.protocol("WM_DELETE_WINDOW", self.__rootFrame.destroy)

        self.__top.bind('<Return>', self.__enter_action)

        self.__top.update_idletasks()
        width = self.__top.winfo_width()
        height = self.__top.winfo_height()
        x = (self.__top.winfo_screenwidth() // 2) - (width // 2)
        y = (self.__top.winfo_screenheight() // 2) - (height // 2)

        self.__top.geometry("+%d+%d" % (x, y))

        row = 0
        expLabel = TKLabel(self.__top, text='Login to host:')
        expLabel.grid(row=row, column=0, columnspan=4, padx=5, pady=2)

        row = row + 1
        urlLabel = TKLabel(self.__top, text=self.__host)
        urlLabel.grid(row=row, column=0, columnspan=4, padx=5, pady=2)

        row = row + 1
        usrLabel = TKLabel(self.__top, text='User')
        usrLabel.grid(row=row, column=0, columnspan=2, padx=20, pady=5)
        self.__usrEntry = TKEntry(self.__top, width=20)
        self.__usrEntry.grid(row=row, column=2, columnspan=2, padx=5, pady=5)

        row = row + 1
        pwdLabel = TKLabel(self.__top, text='Password')
        pwdLabel.grid(row=row, column=0, columnspan=2, padx=20, pady=5)
        self.__pwdEntry = TKEntry(self.__top, width=20, show="*")
        self.__pwdEntry.grid(row=row, column=2, columnspan=2, padx=5, pady=5)

        row = row + 1
        cancelButton = TKButton(self.__top,
                                text='Cancel',
                                command=self.__cancel_action)
        cancelButton.grid(row=row, column=1, padx=5, pady=5)
        loginButton = TKButton(self.__top,
                               text='Login',
                               command=self.__login_action)
        loginButton.grid(row=row, column=2, padx=5, pady=5)

    def show_login(self):
        if self.__initialized:
            self.__usrEntry.focus_set()
            self.__rootFrame.mainloop()
        else:
            print("tkinter python module is not available.\n\
            Please, install tkinter module or use command line login utility.")

    def is_accepted(self):
        return self.__accepted

    def get_user(self):
        return self.__usr

    def get_password(self):
        return self.__pwd
Esempio n. 3
0
class AuthUI(object):
    def __init__(self, parent, app):
        parent.title('Auth window')

        self.parent = parent
        self.root = app

        # Widget Initialization
        self._label_header = Label(
            parent,
            font="{Segoe UI} 20 bold",
            foreground="#ff0000",
            text="Trakt Account Authorization",
        )
        self._button_get_code = Button(
            parent,
            font="{MS Sans Serif} 12 bold",
            text="Get PIN Code",
        )
        self._label_enter_code = Label(
            parent,
            font="{MS Sans Serif} 14",
            text="Enter the code:",
        )
        self._label_click = Label(
            parent,
            font="{MS Sans Serif} 14",
            text="Click the button to get a code:",
        )
        self.pin_code = StringVar()
        self._entry_code = Entry(
            parent,
            font="{MS Sans Serif} 14 bold",
            width=10,
            justify="center",
            textvariable=self.pin_code,
            state="disabled",
        )
        self._button_done = Button(
            parent,
            borderwidth=3,
            font="{MS Sans Serif} 12 bold",
            text="Done",
            state="disabled",
        )

        # widget commands
        self._button_get_code.configure(command=self.button_get_code_command)
        self._button_done.configure(command=self.button_done_command)

        # Geometry Management
        self._label_header.grid(in_=parent,
                                column=1,
                                row=1,
                                columnspan=1,
                                ipadx=0,
                                ipady=0,
                                padx=0,
                                pady=0,
                                rowspan=1,
                                sticky="ew")
        self._label_click.grid(in_=parent,
                               column=1,
                               row=2,
                               columnspan=1,
                               ipadx=0,
                               ipady=0,
                               padx=0,
                               pady=0,
                               rowspan=1,
                               sticky="")
        self._button_get_code.grid(in_=parent,
                                   column=1,
                                   row=3,
                                   columnspan=1,
                                   ipadx=0,
                                   ipady=0,
                                   padx=0,
                                   pady=0,
                                   rowspan=1,
                                   sticky="")
        self._label_enter_code.grid(in_=parent,
                                    column=1,
                                    row=4,
                                    columnspan=1,
                                    ipadx=0,
                                    ipady=0,
                                    padx=0,
                                    pady=0,
                                    rowspan=1,
                                    sticky="")
        self._entry_code.grid(in_=parent,
                              column=1,
                              row=5,
                              columnspan=1,
                              ipadx=5,
                              ipady=0,
                              padx=5,
                              pady=0,
                              rowspan=1,
                              sticky="")
        self._button_done.grid(in_=parent,
                               column=1,
                               row=6,
                               columnspan=1,
                               ipadx=0,
                               ipady=0,
                               padx=0,
                               pady=0,
                               rowspan=1,
                               sticky="")

        # Resize Behavior
        parent.resizable(False, False)
        parent.grid_rowconfigure(1, weight=1, minsize=40, pad=10)
        parent.grid_rowconfigure(2, weight=1, minsize=40, pad=10)
        parent.grid_rowconfigure(3, weight=1, minsize=40, pad=10)
        parent.grid_rowconfigure(4, weight=1, minsize=40, pad=10)
        parent.grid_rowconfigure(5, weight=1, minsize=50, pad=10)
        parent.grid_rowconfigure(6, weight=1, minsize=50, pad=10)
        parent.grid_columnconfigure(1, weight=1, minsize=0, pad=10)
Esempio n. 4
0
class LoginDialog(object):

    def __init__(self, host):
        self.__interna_init()
        self.__host = host
        self.__create_content()

    def __interna_init(self):
        self.__rootFrame = None
        self.__top = None
        self.__usrEntry = None
        self.__pwdEntry = None
        self.__accepted = False
        self.__host = None
        self.__usr = None
        self.__pwd = None

    def __cancel_action(self):
        self.__accepted = False
        self.__rootFrame.destroy()

    def __login_action(self):
        self.__accepted = True
        self.__usr = self.__usrEntry.get()
        self.__pwd = self.__pwdEntry.get()
        self.__rootFrame.destroy()

    def __enter_action(self, event):
        self.__login_action()

    def __create_content(self):
        self.__rootFrame = TKTk()
        self.__rootFrame.withdraw()

        self.__top = TKToplevel(self.__rootFrame)
        self.__top.title("Login")
        self.__top.protocol("WM_DELETE_WINDOW", self.__rootFrame.destroy)

        self.__top.bind('<Return>', self.__enter_action)

        self.__top.update_idletasks()
        width = self.__top.winfo_width()
        height = self.__top.winfo_height()
        x = (self.__top.winfo_screenwidth() // 2) - (width // 2)
        y = (self.__top.winfo_screenheight() // 2) - (height // 2)

        self.__top.geometry("+%d+%d" % (x, y))

        row = 0
        expLabel = TKLabel(self.__top, text='Login to host:')
        expLabel.grid(row=row, column=0, columnspan=4, padx=5, pady=2)

        row = row+1
        urlLabel = TKLabel(self.__top, text=self.__host)
        urlLabel.grid(row=row, column=0, columnspan=4, padx=5, pady=2)

        row = row+1
        usrLabel = TKLabel(self.__top, text='User')
        usrLabel.grid(row=row, column=0, columnspan=2, padx=20, pady=5)
        self.__usrEntry = TKEntry(self.__top, width=20)
        self.__usrEntry.grid(row=row, column=2, columnspan=2, padx=5, pady=5)

        row = row+1
        pwdLabel = TKLabel(self.__top, text='Password')
        pwdLabel.grid(row=row, column=0, columnspan=2, padx=20, pady=5)
        self.__pwdEntry = TKEntry(self.__top, width=20, show="*")
        self.__pwdEntry.grid(row=row, column=2, columnspan=2, padx=5, pady=5)

        row = row+1
        cancelButton = TKButton(self.__top, text='Cancel', command=self.__cancel_action)
        cancelButton.grid(row=row, column=1, padx=5, pady=5)
        loginButton = TKButton(self.__top, text='Login', command=self.__login_action)
        loginButton.grid(row=row, column=2, padx=5, pady=5)

    def show_login(self):
        self.__usrEntry.focus_set()
        self.__rootFrame.mainloop()

    def is_accepted(self):
        return self.__accepted

    def get_user(self):
        return self.__usr

    def get_password(self):
        return self.__pwd
class MainUI(object):
    def __init__(self, parent, root):
        self.parent = parent
        self.root = root

        self.selectedStatus = False

        # Widget Initialization
        self._listbox = Listbox(
            parent,
            font="{Segoe UI} 10",
            height=0,
            selectmode="extended",
            state="normal",
            cursor="hand2",
            exportselection=False,
        )
        self._listbox_scrollbar = AutoScrollbar(self._listbox)
        self._lbl_help = Label(
            parent,
            font="{Segoe UI Light} 12 bold",
            text="Hold [Ctrl] to select multiple items",
        )
        self._label_header = Label(
            parent,
            font="{Segoe UI} 16 bold",
            text="Playback items available for removal",
        )
        self._label_actions = Label(
            parent,
            font="{Segoe UI} 14 bold",
            text="Actions",
        )
        self._label_info = Label(
            parent,
            font="{Segoe UI} 14 bold",
            text="Info",
        )
        self._btnRefresh = Button(
            parent,
            font="{Segoe UI} 12 bold",
            text="Refresh",
        )
        self._btnRemoveSelected = Button(
            parent,
            font="{Segoe UI} 12 bold",
            wraplength=175,
            text="Remove Selected",
        )
        self._btnSelectDeselectAll = Button(
            parent,
            font="{Segoe UI} 12 bold",
            wraplength=175,
            text="Select / Deselect All",
        )
        self._btnStopCurrentlyPlaying = Button(
            parent,
            font="{Segoe UI} 12 bold",
            # wraplength=80,
            text="Stop Currently Playing",
        )
        self._btnLogin = Button(
            parent,
            font="{Segoe UI} 12 bold",
            text="Login/Auth",
        )
        self._lbl_ID = Label(
            parent,
            font="{Segoe UI Light} 12 bold",
            text="ID:",
        )
        self._lbl_PausedAt = Label(
            parent,
            font="{Segoe UI Light} 12 bold",
            text="Paused At:",
        )
        self._lbl_Progress = Label(
            parent,
            font="{Segoe UI Light} 12 bold",
            text="Progress:",
        )
        self.lbl_showName = StringVar(value="Show:")
        self._lbl_Show = Label(
            parent,
            font="{Segoe UI Light} 12 bold",
            textvariable=self.lbl_showName,
        )
        self.lbl_season = StringVar(value="Season:")
        self._lbl_Season = Label(
            parent,
            font="{Segoe UI Light} 12 bold",
            textvariable=self.lbl_season,
        )
        self.lbl_episode = StringVar(value="Episode:")
        self._lbl_Episode = Label(
            parent,
            font="{Segoe UI Light} 12 bold",
            textvariable=self.lbl_episode,
        )
        self.lbl_episodeTitle = StringVar(value="Title:")
        self._lbl_Title = Label(
            parent,
            font="{Segoe UI Light} 12 bold",
            textvariable=self.lbl_episodeTitle,
        )
        self.txt_ID = StringVar()
        self._txtID = Entry(
            parent,
            font="{Segoe UI Light} 12",
            readonlybackground="#ffffff",
            relief="flat",
            state="readonly",
            textvariable=self.txt_ID,
            width=0,
        )
        self.txt_paused_at = StringVar()
        self._txtPausedAt = Entry(
            parent,
            font="{Segoe UI Light} 12",
            readonlybackground="#ffffff",
            relief="flat",
            state="readonly",
            textvariable=self.txt_paused_at,
            width=0,
        )
        self.txt_progress = StringVar()
        self._txtProgress = Entry(
            parent,
            font="{Segoe UI Light} 12",
            readonlybackground="#ffffff",
            relief="flat",
            state="readonly",
            textvariable=self.txt_progress,
            width=0,
        )
        self.txt_showName = StringVar()
        self._txtShowName = Entry(
            parent,
            font="{Segoe UI Light} 12",
            readonlybackground="#ffffff",
            relief="flat",
            state="readonly",
            textvariable=self.txt_showName,
            width=0,
        )
        self.txt_season = StringVar()
        self._txtSeason = Entry(
            parent,
            font="{Segoe UI Light} 12",
            readonlybackground="#ffffff",
            relief="flat",
            state="readonly",
            textvariable=self.txt_season,
            width=0,
        )
        self.txt_episode = StringVar()
        self._txtEpisode = Entry(
            parent,
            font="{Segoe UI Light} 12",
            readonlybackground="#ffffff",
            relief="flat",
            state="readonly",
            textvariable=self.txt_episode,
            width=0,
        )
        self.txt_title = StringVar()
        self._txtTitle = Entry(
            parent,
            font="{Segoe UI Light} 12",
            readonlybackground="#ffffff",
            relief="flat",
            state="readonly",
            textvariable=self.txt_title,
            width=0,
        )
        self.lbl_loggedin = StringVar(value="")
        self._lbl_loggedin = Label(
            parent,
            font="{Segoe UI Light} 12 bold",
            textvariable=self.lbl_loggedin,
        )
        self._lbl_version = Label(
            parent,
            font="{Segoe UI Light} 10 bold",
            text="v%s" % app.__version__,
            foreground="blue",
            cursor="hand2",
        )

        # widget commands
        self._listbox.bind('<<ListboxSelect>>', self._listbox_onselect)
        self._listbox.config(yscrollcommand=self._listbox_scrollbar.set)
        self._listbox_scrollbar.config(orient='vertical',
                                       command=self._listbox.yview)
        self._btnRefresh.configure(command=self._btn_refresh_command)
        self._btnRemoveSelected.configure(
            command=self._btn_remove_selected_command)
        self._btnSelectDeselectAll.configure(
            command=self._btn_toggle_selection_command)
        self._btnStopCurrentlyPlaying.configure(
            command=self._btn_stop_currently_playing)
        self._btnLogin.configure(command=self._btn_login_command)
        self._lbl_version.bind('<Button-1>', self._open_repo)

        # Geometry Management
        self._listbox.grid(in_=parent,
                           column=4,
                           row=2,
                           columnspan=1,
                           ipadx=0,
                           ipady=0,
                           padx=5,
                           pady=5,
                           rowspan=10,
                           sticky="nsew")
        self._listbox.columnconfigure(0, weight=1)
        self._listbox.rowconfigure(0, weight=1)
        self._listbox_scrollbar.grid(column=4, rowspan=10, sticky="ns")
        self._lbl_help.grid(in_=parent,
                            column=4,
                            row=11,
                            ipadx=0,
                            ipady=0,
                            padx=5,
                            pady=5,
                            sticky="nsew")
        self._label_header.grid(in_=parent,
                                column=4,
                                row=1,
                                columnspan=1,
                                ipadx=0,
                                ipady=0,
                                padx=0,
                                pady=0,
                                rowspan=1,
                                sticky="nsew")
        self._label_actions.grid(in_=parent,
                                 column=1,
                                 row=9,
                                 columnspan=3,
                                 ipadx=0,
                                 ipady=0,
                                 padx=0,
                                 pady=0,
                                 rowspan=1,
                                 sticky="nsew")
        self._label_info.grid(in_=parent,
                              column=1,
                              row=1,
                              columnspan=3,
                              ipadx=0,
                              ipady=0,
                              padx=0,
                              pady=0,
                              rowspan=1,
                              sticky="nsew")
        self._btnRefresh.grid(in_=parent,
                              column=1,
                              row=10,
                              columnspan=1,
                              ipadx=0,
                              ipady=0,
                              padx=0,
                              pady=0,
                              rowspan=1,
                              sticky="")
        self._btnRemoveSelected.grid(in_=parent,
                                     column=2,
                                     row=10,
                                     columnspan=1,
                                     ipadx=0,
                                     ipady=0,
                                     padx=0,
                                     pady=0,
                                     rowspan=1,
                                     sticky="")
        self._btnSelectDeselectAll.grid(in_=parent,
                                        column=3,
                                        row=10,
                                        columnspan=1,
                                        ipadx=0,
                                        ipady=0,
                                        padx=0,
                                        pady=0,
                                        rowspan=1,
                                        sticky="")
        self._btnStopCurrentlyPlaying.grid(in_=parent,
                                           column=2,
                                           row=11,
                                           columnspan=2,
                                           ipadx=0,
                                           ipady=0,
                                           padx=5,
                                           pady=0,
                                           rowspan=1,
                                           sticky="ne")
        self._btnLogin.grid(in_=parent,
                            column=2,
                            row=11,
                            columnspan=1,
                            ipadx=0,
                            ipady=0,
                            padx=0,
                            pady=0,
                            rowspan=1,
                            sticky="")
        # Hide the login button at first
        self._btnLogin.grid_remove()
        self._lbl_ID.grid(in_=parent,
                          column=1,
                          row=2,
                          columnspan=1,
                          ipadx=0,
                          ipady=0,
                          padx=0,
                          pady=7,
                          rowspan=1,
                          sticky="nsew")
        self._lbl_PausedAt.grid(in_=parent,
                                column=1,
                                row=3,
                                columnspan=1,
                                ipadx=0,
                                ipady=0,
                                padx=0,
                                pady=7,
                                rowspan=1,
                                sticky="nsew")
        self._lbl_Progress.grid(in_=parent,
                                column=1,
                                row=4,
                                columnspan=1,
                                ipadx=0,
                                ipady=0,
                                padx=0,
                                pady=7,
                                rowspan=1,
                                sticky="nsew")
        self._lbl_Show.grid(in_=parent,
                            column=1,
                            row=5,
                            columnspan=1,
                            ipadx=0,
                            ipady=0,
                            padx=0,
                            pady=7,
                            rowspan=1,
                            sticky="nsew")
        self._lbl_Season.grid(in_=parent,
                              column=1,
                              row=6,
                              columnspan=1,
                              ipadx=0,
                              ipady=0,
                              padx=0,
                              pady=7,
                              rowspan=1,
                              sticky="nsew")
        self._lbl_Episode.grid(in_=parent,
                               column=1,
                               row=7,
                               columnspan=1,
                               ipadx=0,
                               ipady=0,
                               padx=0,
                               pady=7,
                               rowspan=1,
                               sticky="nsew")
        self._lbl_Title.grid(in_=parent,
                             column=1,
                             row=8,
                             columnspan=1,
                             ipadx=0,
                             ipady=0,
                             padx=0,
                             pady=7,
                             rowspan=1,
                             sticky="nsew")
        self._txtID.grid(in_=parent,
                         column=2,
                         row=2,
                         columnspan=2,
                         ipadx=0,
                         ipady=0,
                         padx=5,
                         pady=7,
                         rowspan=1,
                         sticky="nsew")
        self._txtPausedAt.grid(in_=parent,
                               column=2,
                               row=3,
                               columnspan=2,
                               ipadx=0,
                               ipady=0,
                               padx=5,
                               pady=7,
                               rowspan=1,
                               sticky="nsew")
        self._txtProgress.grid(in_=parent,
                               column=2,
                               row=4,
                               columnspan=2,
                               ipadx=0,
                               ipady=0,
                               padx=5,
                               pady=7,
                               rowspan=1,
                               sticky="nsew")
        self._txtShowName.grid(in_=parent,
                               column=2,
                               row=5,
                               columnspan=2,
                               ipadx=0,
                               ipady=0,
                               padx=5,
                               pady=7,
                               rowspan=1,
                               sticky="nsew")
        self._txtSeason.grid(in_=parent,
                             column=2,
                             row=6,
                             columnspan=2,
                             ipadx=0,
                             ipady=0,
                             padx=5,
                             pady=7,
                             rowspan=1,
                             sticky="nsew")
        self._txtEpisode.grid(in_=parent,
                              column=2,
                              row=7,
                              columnspan=2,
                              ipadx=0,
                              ipady=0,
                              padx=5,
                              pady=7,
                              rowspan=1,
                              sticky="nsew")
        self._txtTitle.grid(in_=parent,
                            column=2,
                            row=8,
                            columnspan=2,
                            ipadx=0,
                            ipady=0,
                            padx=5,
                            pady=7,
                            rowspan=1,
                            sticky="nsew")
        self._lbl_loggedin.grid(in_=parent,
                                column=1,
                                row=11,
                                columnspan=2,
                                ipadx=0,
                                ipady=0,
                                padx=5,
                                pady=5,
                                rowspan=1,
                                sticky="sw")
        self._lbl_version.grid(in_=parent,
                               column=1,
                               row=1,
                               columnspan=1,
                               ipadx=0,
                               ipady=0,
                               padx=0,
                               pady=0,
                               rowspan=1,
                               sticky="nw")

        # Resize Behavior
        parent.resizable(False, False)
        parent.grid_rowconfigure(1, weight=0, minsize=30, pad=0)
        parent.grid_rowconfigure(2, weight=0, minsize=30, pad=0)
        parent.grid_rowconfigure(3, weight=0, minsize=30, pad=0)
        parent.grid_rowconfigure(4, weight=0, minsize=30, pad=0)
        parent.grid_rowconfigure(5, weight=0, minsize=30, pad=0)
        parent.grid_rowconfigure(6, weight=0, minsize=30, pad=0)
        parent.grid_rowconfigure(7, weight=0, minsize=30, pad=0)
        parent.grid_rowconfigure(8, weight=0, minsize=30, pad=0)
        parent.grid_rowconfigure(9, weight=0, minsize=30, pad=0)
        parent.grid_rowconfigure(10, weight=0, minsize=60, pad=0)
        parent.grid_rowconfigure(11, weight=0, minsize=30, pad=5)
        parent.grid_columnconfigure(1, weight=0, minsize=70, pad=5)
        parent.grid_columnconfigure(2, weight=0, minsize=175, pad=0)
        parent.grid_columnconfigure(3, weight=0, minsize=175, pad=0)
        parent.grid_columnconfigure(4, weight=0, minsize=400, pad=0)
Esempio n. 6
0
class MainUI(object):
    def __init__(self, parent, app):
        parent.title('Trakt.tv Playback Progress Remover')

        self.parent = parent
        self.root = app

        self.selectedStatus = False

        # Widget Initialization
        self._listbox = Listbox(
            parent,
            font="{Segoe UI} 10",
            height=0,
            selectmode="extended",
            state="normal",
            cursor="hand2",
        )
        self._listbox_scrollbar = AutoScrollbar(self._listbox)
        self._label_header = Label(
            parent,
            font="{Segoe UI} 16 bold",
            text="Playback items available for removal",
        )
        self._label_actions = Label(
            parent,
            font="{Segoe UI} 14 bold",
            text="Actions",
        )
        self._label_info = Label(
            parent,
            font="{Segoe UI} 14 bold",
            text="Info",
        )
        self._btnRefresh = Button(
            parent,
            font="{Segoe UI} 12 bold",
            text="Refresh",
        )
        self._btnRemoveSelected = Button(
            parent,
            font="{Segoe UI} 12 bold",
            wraplength=120,
            text="Remove Selected",
        )
        self._btnSelectDeselectAll = Button(
            parent,
            font="{Segoe UI} 12 bold",
            wraplength=120,
            text="Select / Deselect All",
        )
        self._btnLogin = Button(
            parent,
            font="{Segoe UI} 12 bold",
            text="Login/Auth",
        )
        self._lbl_ID = Label(
            parent,
            font="{Segoe UI Light} 12 bold",
            text="ID:",
        )
        self._lbl_Progress = Label(
            parent,
            font="{Segoe UI Light} 12 bold",
            text="Progress:",
        )
        self.lbl_showName = StringVar(value="Show:")
        self._lbl_Show = Label(
            parent,
            font="{Segoe UI Light} 12 bold",
            textvariable=self.lbl_showName,
        )
        self.lbl_season = StringVar(value="Season:")
        self._lbl_Season = Label(
            parent,
            font="{Segoe UI Light} 12 bold",
            textvariable=self.lbl_season,
        )
        self.lbl_episode = StringVar(value="Episode:")
        self._lbl_Episode = Label(
            parent,
            font="{Segoe UI Light} 12 bold",
            textvariable=self.lbl_episode,
        )
        self.lbl_episodeTitle = StringVar(value="Title:")
        self._lbl_Title = Label(
            parent,
            font="{Segoe UI Light} 12 bold",
            textvariable=self.lbl_episodeTitle,
        )
        self.txt_ID = StringVar()
        self._txtID = Entry(
            parent,
            font="{Segoe UI Light} 12",
            readonlybackground="#ffffff",
            relief="flat",
            state="readonly",
            textvariable=self.txt_ID,
            width=0,
        )
        self.txt_progress = StringVar()
        self._txtProgress = Entry(
            parent,
            font="{Segoe UI Light} 12",
            readonlybackground="#ffffff",
            relief="flat",
            state="readonly",
            textvariable=self.txt_progress,
            width=0,
        )
        self.txt_showName = StringVar()
        self._txtShowName = Entry(
            parent,
            font="{Segoe UI Light} 12",
            readonlybackground="#ffffff",
            relief="flat",
            state="readonly",
            textvariable=self.txt_showName,
            width=0,
        )
        self.txt_season = StringVar()
        self._txtSeason = Entry(
            parent,
            font="{Segoe UI Light} 12",
            readonlybackground="#ffffff",
            relief="flat",
            state="readonly",
            textvariable=self.txt_season,
            width=0,
        )
        self.txt_episode = StringVar()
        self._txtEpisode = Entry(
            parent,
            font="{Segoe UI Light} 12",
            readonlybackground="#ffffff",
            relief="flat",
            state="readonly",
            textvariable=self.txt_episode,
            width=0,
        )
        self.txt_title = StringVar()
        self._txtTitle = Entry(
            parent,
            font="{Segoe UI Light} 12",
            readonlybackground="#ffffff",
            relief="flat",
            state="readonly",
            textvariable=self.txt_title,
            width=0,
        )
        self.lbl_loggedin = StringVar(value="Not logged in.")
        self._lbl_loggedin = Label(
            parent,
            font="{Segoe UI Light} 12 bold",
            textvariable=self.lbl_loggedin,
        )

        # widget commands
        self._listbox.bind('<<ListboxSelect>>', self._listbox_onselect)
        self._listbox.config(yscrollcommand=self._listbox_scrollbar.set)
        self._listbox_scrollbar.config(orient='vertical',
                                       command=self._listbox.yview)
        self._btnRefresh.configure(command=self._btn_refresh_command)
        self._btnRemoveSelected.configure(
            command=self._btn_remove_selected_command)
        self._btnSelectDeselectAll.configure(
            command=self._btn_toggle_selection_command)
        self._btnLogin.configure(command=self._btn_login_command)

        # Geometry Management
        self._listbox.grid(in_=parent,
                           column=3,
                           row=2,
                           columnspan=1,
                           ipadx=0,
                           ipady=0,
                           padx=0,
                           pady=5,
                           rowspan=7,
                           sticky="nsew")
        self._listbox.columnconfigure(0, weight=1)
        self._listbox.rowconfigure(0, weight=1)
        self._listbox_scrollbar.grid(column=2, rowspan=7, sticky="ns")
        self._label_header.grid(in_=parent,
                                column=3,
                                row=1,
                                columnspan=1,
                                ipadx=0,
                                ipady=0,
                                padx=0,
                                pady=0,
                                rowspan=1,
                                sticky="nsew")
        self._label_actions.grid(in_=parent,
                                 column=4,
                                 row=1,
                                 columnspan=1,
                                 ipadx=0,
                                 ipady=0,
                                 padx=0,
                                 pady=0,
                                 rowspan=1,
                                 sticky="nsew")
        self._label_info.grid(in_=parent,
                              column=1,
                              row=1,
                              columnspan=2,
                              ipadx=0,
                              ipady=0,
                              padx=0,
                              pady=0,
                              rowspan=1,
                              sticky="nsew")
        self._btnRefresh.grid(in_=parent,
                              column=4,
                              row=6,
                              columnspan=1,
                              ipadx=0,
                              ipady=0,
                              padx=0,
                              pady=0,
                              rowspan=2,
                              sticky="")
        self._btnRemoveSelected.grid(in_=parent,
                                     column=4,
                                     row=2,
                                     columnspan=1,
                                     ipadx=0,
                                     ipady=0,
                                     padx=0,
                                     pady=0,
                                     rowspan=2,
                                     sticky="")
        self._btnSelectDeselectAll.grid(in_=parent,
                                        column=4,
                                        row=4,
                                        columnspan=1,
                                        ipadx=0,
                                        ipady=0,
                                        padx=0,
                                        pady=0,
                                        rowspan=2,
                                        sticky="")
        self._btnLogin.grid(in_=parent,
                            column=4,
                            row=7,
                            columnspan=1,
                            ipadx=0,
                            ipady=0,
                            padx=5,
                            pady=5,
                            rowspan=2,
                            sticky="es")
        self._lbl_ID.grid(in_=parent,
                          column=1,
                          row=2,
                          columnspan=1,
                          ipadx=0,
                          ipady=0,
                          padx=0,
                          pady=7,
                          rowspan=1,
                          sticky="nsew")
        self._lbl_Progress.grid(in_=parent,
                                column=1,
                                row=3,
                                columnspan=1,
                                ipadx=0,
                                ipady=0,
                                padx=0,
                                pady=7,
                                rowspan=1,
                                sticky="nsew")
        self._lbl_Show.grid(in_=parent,
                            column=1,
                            row=4,
                            columnspan=1,
                            ipadx=0,
                            ipady=0,
                            padx=0,
                            pady=7,
                            rowspan=1,
                            sticky="nsew")
        self._lbl_Season.grid(in_=parent,
                              column=1,
                              row=5,
                              columnspan=1,
                              ipadx=0,
                              ipady=0,
                              padx=0,
                              pady=7,
                              rowspan=1,
                              sticky="nsew")
        self._lbl_Episode.grid(in_=parent,
                               column=1,
                               row=6,
                               columnspan=1,
                               ipadx=0,
                               ipady=0,
                               padx=0,
                               pady=7,
                               rowspan=1,
                               sticky="nsew")
        self._lbl_Title.grid(in_=parent,
                             column=1,
                             row=7,
                             columnspan=1,
                             ipadx=0,
                             ipady=0,
                             padx=0,
                             pady=7,
                             rowspan=1,
                             sticky="nsew")
        self._txtID.grid(in_=parent,
                         column=2,
                         row=2,
                         columnspan=1,
                         ipadx=0,
                         ipady=0,
                         padx=5,
                         pady=7,
                         rowspan=1,
                         sticky="nsew")
        self._txtProgress.grid(in_=parent,
                               column=2,
                               row=3,
                               columnspan=1,
                               ipadx=0,
                               ipady=0,
                               padx=5,
                               pady=7,
                               rowspan=1,
                               sticky="nsew")
        self._txtShowName.grid(in_=parent,
                               column=2,
                               row=4,
                               columnspan=1,
                               ipadx=0,
                               ipady=0,
                               padx=5,
                               pady=7,
                               rowspan=1,
                               sticky="nsew")
        self._txtSeason.grid(in_=parent,
                             column=2,
                             row=5,
                             columnspan=1,
                             ipadx=0,
                             ipady=0,
                             padx=5,
                             pady=7,
                             rowspan=1,
                             sticky="nsew")
        self._txtEpisode.grid(in_=parent,
                              column=2,
                              row=6,
                              columnspan=1,
                              ipadx=0,
                              ipady=0,
                              padx=5,
                              pady=7,
                              rowspan=1,
                              sticky="nsew")
        self._txtTitle.grid(in_=parent,
                            column=2,
                            row=7,
                            columnspan=1,
                            ipadx=0,
                            ipady=0,
                            padx=5,
                            pady=7,
                            rowspan=1,
                            sticky="nsew")
        self._lbl_loggedin.grid(in_=parent,
                                column=1,
                                row=8,
                                columnspan=2,
                                ipadx=0,
                                ipady=0,
                                padx=5,
                                pady=5,
                                rowspan=1,
                                sticky="sw")

        # Resize Behavior
        parent.resizable(False, False)
        parent.grid_rowconfigure(1, weight=0, minsize=30, pad=20)
        parent.grid_rowconfigure(2, weight=0, minsize=30, pad=0)
        parent.grid_rowconfigure(3, weight=0, minsize=30, pad=0)
        parent.grid_rowconfigure(4, weight=0, minsize=30, pad=0)
        parent.grid_rowconfigure(5, weight=0, minsize=30, pad=0)
        parent.grid_rowconfigure(6, weight=0, minsize=30, pad=0)
        parent.grid_rowconfigure(7, weight=0, minsize=30, pad=0)
        parent.grid_rowconfigure(8, weight=0, minsize=200, pad=0)
        parent.grid_columnconfigure(1, weight=0, minsize=70, pad=5)
        parent.grid_columnconfigure(2, weight=0, minsize=450, pad=0)
        parent.grid_columnconfigure(3, weight=0, minsize=450, pad=0)
        parent.grid_columnconfigure(4, weight=0, minsize=120, pad=0)