Example #1
0
class UI(object):
    def __init__(self, args):
        self.root = Tk()
        self.args = args

        # Make it invisible
        # - 0 size, top left corner, transparent.
        self.root.attributes('-alpha', 0.0)
        self.root.geometry('0x0+0+0')

        # "Show" window again and lift it to top so it can get focus,
        # otherwise dialogs will end up behind other windows
        self.root.deiconify()
        self.root.lift()
        self.root.focus_force()

    def selectFolder(self, **options):
        """
        Show a folder selection window for the user to import
        an addon
        """
        if self.args.addon_path is None:
            selected_addon_dir_path = tkFileDialog.askdirectory(
                parent=self.root, **options)
        else:
            selected_addon_dir_path = self.args.addon_path
        return selected_addon_dir_path

    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)

    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 fail(self, msg):
        print(msg)
        if self.args.addon_path is None:
            tkMessageBox.showerror(message=msg)
        sys.exit(1)

    def confirmAction(self, addon_name):
        proceed = True
        info = addon_select_info_message.format(addon_name, self.args.project,
                                                self.args.workspace)
        print(info)
        if self.args.addon_path is None:
            proceed = tkMessageBox.askokcancel('Attention!', info)
        print(proceed)
        return proceed
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)))
class UI(object):
    def __init__(self, args):
        self.root = Tk()

        # Make it invisible
        # - 0 size, top left corner, transparent.
        self.root.attributes('-alpha', 0.0)
        self.root.geometry('0x0+0+0')

        try:
            qmde_icon = os.path.join(args.devkit, 'res', 'q_logo.ico')
            self.root.iconbitmap(bitmap=qmde_icon)
        except TclError:
            pass

        # "Show" window again and lift it to top so it can get focus,
        # otherwise dialogs will end up behind other windows
        self.root.deiconify()
        self.root.lift()
        self.root.focus_force()

    def selectFolder(self, **options):
        """
        Show a folder selection window for the user to import/export
        private pre-built libraries
        """
        return tkFileDialog.askdirectory(parent=self.root, **options)

    def selectFile(self, **options):
        """
        Show a folder selection window for the user to import/export
        private pre-built libraries
        """
        return tkFileDialog.askopenfilename(parent=self.root, **options)

    def success(self, action):
        message = 'Library {} operation succesful'.format(action.lower())
        print(message)
        tkMessageBox.showinfo(message=message)

    def cancel(self, action):
        message = 'Library {} operation cancelled'.format(action.lower())
        print(message)
        tkMessageBox.showinfo(message=message)
        sys.exit(0)

    def fail(self, msg):
        print(msg)
        tkMessageBox.showerror(message=msg)
        sys.exit(1)

    def confirmAction(self, action, header, archive):
        proceed = True
        header_base = os.path.basename(header)
        archive_base = os.path.basename(archive)
        info = "About to {} files:\n--{}\n--{}\n\n" \
            .format(action.lower(), header_base, archive_base)
        question = "Proceed?"
        print(info + question)
        proceed = tkMessageBox.askokcancel('Attention!', info + question)
        print(proceed)
        return proceed

    def proceedDstFileExists(self, dst_dir, dst_file):
        dst_file = os.path.join(dst_dir, dst_file)
        proceed = True
        if os.path.isfile(dst_file):
            info = 'File: \n--{}\n\nalready exists at destination' \
                .format(dst_file)
            question = "Proceed?"
            proceed = tkMessageBox.askokcancel('Attention!', info + question)
        return proceed