Example #1
0
    def __init__(self, parent=None, proj=None):
        if not parent:
            parent = getTkRoot()
        tk.Toplevel.__init__(self, parent)

        assert proj
        self.task = ExportTask(proj)

        self.resizable(False, False)
        self.title('Awake Export')

        frame = ttk.Frame(self)
        frame.pack(fill='both')

        self.mode_radios = RadioGroup(frame, 'What', self.task.modes, 'flow')
        self.mode_radios.grid(row=1, column=1, columnspan=2, sticky='NESW')

        self.scope_var = tk.StringVar()
        group = ttk.LabelFrame(frame, text='From where')
        group.grid(row=2, column=1, columnspan=2)
        radio = ttk.Radiobutton(group, text='All banks', variable=self.scope_var, value='all')
        radio.grid(row=1, column=1, columnspan=2, sticky='NESW')
        radio = ttk.Radiobutton(group, text='Single bank', variable=self.scope_var, value='bank')
        radio.grid(row=2, column=1, sticky='NESW')
        self.bank_select = BankSelect(group, proj)
        self.bank_select.var.trace('w', self.enableBank)
        self.bank_select.grid(row=2, column=2, sticky='NESW')
        radio = ttk.Radiobutton(group, text='Single procedure', variable=self.scope_var, value='proc')
        radio.grid(row=3, column=1, sticky='NESW')
        self.proc_address = tk.StringVar()
        self.proc_address.set("100")
        self.proc_address.trace('w', self.enableProc)
        address = ttk.Entry(group, textvariable=self.proc_address, width=10)
        address.grid(row=3, column=2, sticky='NESW')
        self.scope_var.set(self.task.scope)

        self.status = ttk.Label(frame, text='')
        self.status.grid(row=3, column=1, columnspan=2, sticky='NESW')
        self.progressbar = ttk.Progressbar(frame, orient="horizontal", mode="determinate")
        self.progressbar.grid(row=4, column=1, columnspan=2, sticky='NESW')

        self.export_button = ttk.Button(frame)
        self.export_button.grid(row=5, column=2, columnspan=1, sticky='NESW')
        self.enableExport()
        self.close_button = ttk.Button(frame, text="Close", command=self.quit)
        self.close_button.grid(row=5, column=1, sticky='NESW')
        self.bind('<Return>', self.export)
        self.bind('<Escape>', self.quit)

        self.protocol("WM_DELETE_WINDOW", self.quit)
Example #2
0
class ExportDialog(tk.Toplevel):
    def __init__(self, parent=None, proj=None):
        if not parent:
            parent = getTkRoot()
        tk.Toplevel.__init__(self, parent)

        assert proj
        self.task = ExportTask(proj)

        self.resizable(False, False)
        self.title('Awake Export')

        frame = ttk.Frame(self)
        frame.pack(fill='both')

        self.mode_radios = RadioGroup(frame, 'What', self.task.modes, 'flow')
        self.mode_radios.grid(row=1, column=1, columnspan=2, sticky='NESW')

        self.scope_var = tk.StringVar()
        group = ttk.LabelFrame(frame, text='From where')
        group.grid(row=2, column=1, columnspan=2)
        radio = ttk.Radiobutton(group, text='All banks', variable=self.scope_var, value='all')
        radio.grid(row=1, column=1, columnspan=2, sticky='NESW')
        radio = ttk.Radiobutton(group, text='Single bank', variable=self.scope_var, value='bank')
        radio.grid(row=2, column=1, sticky='NESW')
        self.bank_select = BankSelect(group, proj)
        self.bank_select.var.trace('w', self.enableBank)
        self.bank_select.grid(row=2, column=2, sticky='NESW')
        radio = ttk.Radiobutton(group, text='Single procedure', variable=self.scope_var, value='proc')
        radio.grid(row=3, column=1, sticky='NESW')
        self.proc_address = tk.StringVar()
        self.proc_address.set("100")
        self.proc_address.trace('w', self.enableProc)
        address = ttk.Entry(group, textvariable=self.proc_address, width=10)
        address.grid(row=3, column=2, sticky='NESW')
        self.scope_var.set(self.task.scope)

        self.status = ttk.Label(frame, text='')
        self.status.grid(row=3, column=1, columnspan=2, sticky='NESW')
        self.progressbar = ttk.Progressbar(frame, orient="horizontal", mode="determinate")
        self.progressbar.grid(row=4, column=1, columnspan=2, sticky='NESW')

        self.export_button = ttk.Button(frame)
        self.export_button.grid(row=5, column=2, columnspan=1, sticky='NESW')
        self.enableExport()
        self.close_button = ttk.Button(frame, text="Close", command=self.quit)
        self.close_button.grid(row=5, column=1, sticky='NESW')
        self.bind('<Return>', self.export)
        self.bind('<Escape>', self.quit)

        self.protocol("WM_DELETE_WINDOW", self.quit)

    def update(self):
        try:
            while True:
                done, total, msg = self.task.queue.get_nowait()
                self.progressbar['maximum'] = total
                self.progressbar['value'] = done
                self.status.configure(text=msg)
        except Queue.Empty:
            pass

        if self.task.isFinished():
            self.enableExport()
        else:
            self.after(100, self.update)

    def enableBank(self, *args):
        self.scope_var.set('bank')

    def enableProc(self, *args):
        self.scope_var.set('proc')

    def export(self, *args):
        self.task.mode = self.mode_radios.getValue()
        self.task.scope = self.scope_var.get()
        self.task.bank = self.bank_select.getValue()
        self.task.address = self.proc_address.get()
        self.task.filename = asksaveasfilename(
            title="Select destination file",
            parent=self,
            initialdir=os.path.dirname(self.task.getDefaultFilename()),
            initialfile=os.path.basename(self.task.getDefaultFilename())
        )
        if not self.task.filename:
            return
        self.task.start()

        self.export_button.configure(text='Abort', command=self.abortExport)
        self.update()

    def enableExport(self):
        self.export_button.configure(text='Export', command=self.export)

    def abortExport(self):
        self.task.requestCancel = True
        self.enableExport()

    def quit(self, *args):
        self.task.requestCancel = True
        self.destroy()

    def wait(self):
        self.wait_window(self)