Example #1
0
    def __init__(self, master=None):
        ttk.Frame.__init__(self, master)
        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)
        # Have the columns all grow evenly when the window is resized.
        self.columnconfigure(0, weight=0, minsize=20)
        self.columnconfigure(1, weight=0, minsize=20)
        self.columnconfigure(2, weight=0, minsize=20)
        self.columnconfigure(3, weight=0, minsize=20)
        self.columnconfigure(4, weight=1, minsize=20)
        self.columnconfigure(5, weight=1, minsize=20)
        self.columnconfigure(6, weight=1, minsize=20)
        self.rowconfigure(0, weight=0,  minsize=20)
        self.rowconfigure(1, weight=0,  minsize=10)
        self.rowconfigure(2, weight=10, minsize=20)
        self.rowconfigure(3, weight=0,  minsize=20)
        # Listbox to contain the collection names
        self.collection_frame = ttk.Frame(master=self)
        self.collection_frame['padding'] = 5
        self.collection_frame.grid(column=0, row=0, sticky='nsew', 
                                   columnspan=2, rowspan=3)
        self.collection_scroll = ttk.Scrollbar(self.collection_frame)
        self.collection_scroll.pack(side=tk.RIGHT, fill=tk.Y)
        self.collection_box = tk.Listbox(self.collection_frame)
        self.collection_box['width'] = 30
        self.collection_box['height'] = 60
        self.collection_box['font'] = 'TkFixedFont'
        self.collection_box['borderwidth'] = 0
        self.collection_box['highlightthickness'] = 0
        self.collection_box.bind('<<ListboxSelect>>', self.on_collection_select)
        self.collection_box.pack(fill=tk.BOTH, expand=1)
        self.collection_box.configure(yscrollcommand=self.collection_scroll.set)
        self.collection_scroll.configure(command=self.collection_box.yview)
        self.collection_names = api.collection_names()
        for collection_name in self.collection_names:
            self.collection_box.insert(tk.END, collection_name)
        # Listbox to contain each file name in the selected collection
        self.file_name_frame = ttk.Frame(master=self)
        self.file_name_frame['padding'] = 5
        self.file_name_frame.grid(column=2, row=0, sticky='nsew', 
                                   columnspan=2, rowspan=3)
        self.file_name_scroll = ttk.Scrollbar(self.file_name_frame)
        self.file_name_scroll.pack(side=tk.RIGHT, fill=tk.Y)
        self.file_name_box = tk.Listbox(self.file_name_frame)
        self.file_name_box['width'] = 30
        self.file_name_box['height'] = 20
        self.file_name_box['font'] = 'TkFixedFont'
        self.file_name_box['borderwidth'] = 0
        self.file_name_box['highlightthickness'] = 0
        self.file_name_box.pack(fill=tk.BOTH, expand=1)
        self.file_name_box.bind('<<ListboxSelect>>', self.on_file_name_select)
        self.file_name_box.configure(yscrollcommand=self.file_name_scroll.set)
        self.file_name_scroll.configure(command=self.file_name_box.yview)

        # Display to contain the files attributes
        self.metadata_display = tk.Text(master=self)
        self.metadata_display.grid(column=4, row=0, sticky='nsew', columnspan=3)
        self.metadata_display['width'] = 200
        self.metadata_display['height'] = 5
        self.metadata_display['borderwidth'] = 4
        self.metadata_display['font'] = 'TkFixedFont'

        # OptionMenu to select how to display the file
        self.options = ['              ',
                        'byte histogram',
                        'opcode histogram']
        self.file_display_type_str = tk.StringVar(master=self)
        self.file_display_type_str.set(self.options[0])
        self.file_display_option_menu = ttk.OptionMenu(self, 
                       self.file_display_type_str, self.options[0], 
                       command=self.on_file_data_select, *self.options)
        self.file_display_option_menu.grid(column=4, row=1)

        # Create a display to contain the histogram image
        self.display = tk.Frame(master=self)
        self.display.grid(column=4, row=2, sticky='nsew',
                          columnspan=3)
        self.display['width'] = 40
        self.display['height'] = 40
        self.display['borderwidth'] = 2

        # Label for the file counter
        self.label_str = tk.StringVar()
        self.label_str.set('')
        self.count_label = ttk.Label(self, textvariable=self.label_str)
        self.count_label.grid(column=2, row=3, sticky='nse')
        # File counter
        self.file_count = tk.StringVar()
        self.file_count.set('')
        self.file_count_display = ttk.Label(self, textvariable=self.file_count)
        self.file_count_display.grid(column=3, row=3, sticky='nsw')
        # give every widget in the mainframe a little padding
        for child in self.winfo_children():
            child.grid_configure(padx=5, pady=5)
Example #2
0
    def __init__(self, master):
        tk.Toplevel.__init__(self, master)
        self.transient(master)
        self.master = master
        self.result = None

        # create a frame to contain all window contents
        self.main_frame = ttk.Frame(self)

        # Have the columns all grow evenly when the window is resized.
        self.main_frame.columnconfigure(0, weight=0)
        self.main_frame.columnconfigure(1, weight=0)
        self.main_frame.columnconfigure(2, weight=0)
        self.main_frame.rowconfigure(0, weight=1)
        self.main_frame.rowconfigure(1, weight=0)

        #self.main_frame.grid(column=0, row=0, sticky='nsew')
        self.main_frame.pack(expand=True)

        # Listbox to contain the collection names
        self.collection_frame = ttk.Frame(master=self.main_frame)
        self.collection_frame['padding'] = 5
        self.collection_frame.grid(column=0, row=0, sticky='nsew')
        self.collection_scroll = ttk.Scrollbar(self.collection_frame)
        self.collection_scroll.pack(side=tk.RIGHT, fill=tk.Y)
        self.collection_box = tk.Listbox(self.collection_frame)
        self.collection_box['width'] = 30
        self.collection_box['height'] = 10
        self.collection_box['font'] = 'TkFixedFont'
        self.collection_box['borderwidth'] = 0
        self.collection_box['highlightthickness'] = 0
        self.collection_box.bind('<<ListboxSelect>>', self.on_collection_select)
        self.collection_box.pack(fill=tk.BOTH, expand=1)
        self.collection_box.configure(yscrollcommand=self.collection_scroll.set)
        self.collection_scroll.configure(command=self.collection_box.yview)
        self.collection_names = api.collection_names()
        for collection_name in self.collection_names:
            self.collection_box.insert(tk.END, collection_name)

        # Listbox to contain each file name in the selected collection
        self.file_name_frame = ttk.Frame(master=self.main_frame)
        self.file_name_frame['padding'] = 5
        self.file_name_frame.grid(column=1, row=0, sticky='nsew')
        self.file_name_scroll = ttk.Scrollbar(self.file_name_frame)
        self.file_name_scroll.pack(side=tk.RIGHT, fill=tk.Y)
        self.file_name_box = tk.Listbox(self.file_name_frame)
        self.file_name_box['width'] = 30
        self.file_name_box['height'] = 10
        self.file_name_box['font'] = 'TkFixedFont'
        self.file_name_box['borderwidth'] = 0
        self.file_name_box['highlightthickness'] = 0
        self.file_name_box.pack(fill=tk.BOTH, expand=1)
        self.file_name_box.bind('<<ListboxSelect>>', self.on_file_name_select)
        self.file_name_box.configure(yscrollcommand=self.file_name_scroll.set)
        self.file_name_scroll.configure(command=self.file_name_box.yview)

        # Display to contain the files attributes
        self.metadata_display = tk.Text(master=self.main_frame)
        self.metadata_display.grid(column=2, row=0, sticky='nsew')
        self.metadata_display['width'] = 30
        self.metadata_display['height'] = 10
        self.metadata_display['borderwidth'] = 4
        self.metadata_display['font'] = 'TkFixedFont'

        # buttons for cancel and ok
        self.button_box = ttk.Frame(self.main_frame)
        ok_button = ttk.Button(self.button_box, text="OK", width=10, 
                               command=self.ok, default=tk.ACTIVE)
        ok_button.pack(side=tk.LEFT, padx=5, pady=5)
        cancel_button = ttk.Button(self.button_box, text="Cancel", width=10, 
                                   command=self.cancel)
        cancel_button.pack(side=tk.LEFT, padx=5, pady=5)
        self.bind("<Return>", self.ok)
        self.bind("<Escape>", self.cancel)
        self.button_box.grid(row=1, column=0, columnspan=3)

        # makes the dialog modal
        self.grab_set()

        # Make sure that an explicit close is treated as cancel
        self.protocol("WM_DELETE_WINDOW", self.cancel)
        self.geometry("+%d+%d" % (self.master.winfo_rootx()+50,
                                  self.master.winfo_rooty()+50))

        # moves the keyboard focus to the collection listbox
        self.collection_box.focus_set()

        # give every widget in the mainframe a little padding
        for child in self.winfo_children():
            child.grid_configure(padx=2, pady=2)

        # enters the local event loop and does not return
        # until this window is destroyed
        self.wait_window(self)