def __init__(self, master, **kwargs): Frame.__init__(self, master) textarea_frame = Frame(self, bd=1, relief=SOLID,**kwargs) textarea_frame.pack(fill=X) textarea_frame.pack_propagate(False) self.textarea = Text(textarea_frame, height=1, pady=self.TAG_ENTRY_PADY, padx=self.TAG_ENTRY_PADX, highlightthickness =0, spacing1=0, spacing2=0, spacing3=0, borderwidth=0, wrap="none") self.textarea.pack(expand=True, fill=BOTH, padx=2) scrollbar = Scrollbar(self, orient=HORIZONTAL, command=self.textarea.xview) scrollbar.pack(fill=X) self.textarea.configure(xscrollcommand=scrollbar.set) self.textarea.bind("<KeyPress>",self._on_keypress) tag = Tag(self.textarea, "") self.textarea.window_create("1.0", window=tag) self.update_idletasks() tag_reqheight = tag.winfo_reqheight() textarea_frame.configure(height=tag_reqheight + 2*self.TAG_ENTRY_PADY+2*self.textarea["borderwidth"]) # I add a hidden frame because I want the cursor centered including when there is no tag self.textarea.window_create("1.0", window=Frame(self.textarea, height=tag_reqheight, width=0, borderwidth=0)) tag.destroy()
def _scrolled_text_display(title='Diagnil Text Display', intro=None, button_proc=null_proc, tab_stops=(), return_frame=0): fr = Toplevel() fr.geometry(newGeometry='-0+50') if intro: Label(fr, text=intro).pack(padx=10, pady=10) txt_fr = Frame(fr) if on_win: txt = Text(txt_fr, width=70, padx=10, pady=5, wrap=WORD, tabs=tab_stops) else: txt = Text(txt_fr, width=70, padx=10, pady=5, wrap=WORD, background=text_bg_color, tabs=tab_stops) scroll = Scrollbar(txt_fr, command=txt.yview) txt.configure(yscrollcommand=scroll.set) wrapped_bind(fr, '<Key-Prior>', lambda event: txt.yview_scroll(-1, PAGES)) wrapped_bind(fr, '<Key-Next>', lambda event: txt.yview_scroll(1, PAGES)) wrapped_bind(fr, '<Enter>', lambda event: fr.focus_set()) txt.pack(side=LEFT, fill=BOTH, expand=YES) scroll.pack(side=LEFT, fill=Y) txt_fr.pack(padx=5, pady=5, fill=BOTH, expand=YES) button_proc(fr) fr.title(string=title) if return_frame: return fr, txt else: return txt
def __init__(self, master, **kwargs): Frame.__init__(self, master) textarea_frame = Frame(self, bd=1, relief=SOLID, **kwargs) textarea_frame.pack(fill=X) textarea_frame.pack_propagate(False) self.textarea = Text(textarea_frame, height=1, pady=self.TAG_ENTRY_PADY, padx=self.TAG_ENTRY_PADX, highlightthickness=0, spacing1=0, spacing2=0, spacing3=0, borderwidth=0, wrap="none") self.textarea.pack(expand=True, fill=BOTH, padx=2) scrollbar = Scrollbar(self, orient=HORIZONTAL, command=self.textarea.xview) scrollbar.pack(fill=X) self.textarea.configure(xscrollcommand=scrollbar.set) self.textarea.bind("<KeyPress>", self._on_keypress) tag = Tag(self.textarea, "") self.textarea.window_create("1.0", window=tag) self.update_idletasks() tag_reqheight = tag.winfo_reqheight() textarea_frame.configure(height=tag_reqheight + 2 * self.TAG_ENTRY_PADY + 2 * self.textarea["borderwidth"]) # I add a hidden frame because I want the cursor centered including when there is no tag self.textarea.window_create("1.0", window=Frame(self.textarea, height=tag_reqheight, width=0, borderwidth=0)) tag.destroy()
class ScrolledCanvas(Frame): """ A scrolling canvas of frames with checkboxes. """ def __init__(self, master, name=None, scrollregion=(0, 0, '5i', '5i'), items=[], window_size=[160, 30], **canvaskw): Frame.__init__(self, master, name=name) self.scrollcanvas = Canvas(self, name='scrollcanvas', scrollregion=scrollregion, **canvaskw) self.yscroll = Scrollbar(self, name='yscroll', command=self.scrollcanvas.yview) self.scrollcanvas['yscrollcommand'] = self.yscroll.set self.yscroll.pack(side=RIGHT, fill=Y) self.scrollcanvas.pack(side=LEFT, fill=BOTH, expand=YES) self.items = dict.fromkeys(items) for n, i in enumerate(items): self.items[i] = {'frame': Frame(self, name=(i.lower() + '_frame'))} self.items[i]['frame'].config(relief=GROOVE, padding=5) self.items[i]['chbx'] = Checkbutton(self.items[i]['frame'], name=(i.lower() + '_chbx')) self.items[i]['chbx']['text'] = i self.items[i]['chbx'].pack(side=LEFT, fill=X) y = window_size[1] / 2 + window_size[1] * n self.items[i]['window'] = self.scrollcanvas.create_window(0, y) self.scrollcanvas.itemconfigure(self.items[i]['window'], window=self.items[i]['frame'], anchor=W, width=window_size[0], height=window_size[1])
def __init__(self, master): Frame.__init__(self, master) scrollbar = Scrollbar(self, orient=VERTICAL) scrollbar.pack(side=RIGHT, fill=Y) self.canvas = Canvas(self, bd=0, highlightthickness=0, yscrollcommand=scrollbar.set) self.canvas.pack(side=LEFT, fill=BOTH, expand=1) scrollbar.config(command=self.canvas.yview) self.mainframe = Frame(self.canvas) self.mainframe_id = self.canvas.create_window((0, 0), window=self.mainframe, anchor=NW) self.mainframe.bind('<Configure>', self.config_mainframe) self.canvas.bind('<Configure>', self.config_canvas)
class Scrolled(object): """My own implementation for adding a scrollbar to a widget. Similar in principal to Python's ScrolledText module, but it works on other widgets too (this script uses it on Listbox too). So it's more like the Perl/Tk module Tk::Scrolled in that it can wrap any widget, in theory.""" def __init__(self, master, widget_class, attributes=None, scrollbar=None): """ master is the parent widget widget_class is the class, like Text or Listbox attributes are attributes for the widget scrollbar are attributes for the scrollbar """ if attributes is None: attributes = [] if scrollbar is None: scrollbar = [] self.master = master # Parent frame to hold the widget + scrollbar self.frame = Frame(master) # The scrollbar self.scrollbar = Scrollbar(self.frame, **scrollbar) # The widget itself self.widget = widget_class(self.frame, yscrollcommand=self.scrollbar.set, **attributes) self.scrollbar.configure(command=self.widget.yview) self.scrollbar.pack(side="right", fill="y") self.widget.pack(side="right", fill="both", expand=1) def widget(self): """Get at the inner widget.""" return self.widget def scrollbar(self): """Get at the scrollbar widget.""" return self.scrollbar def getSelectedIndex(self): return self.widget.curselection() def get(self, index): return str((self.widget.get(index))) def pack(self, **kwargs): """Wrapper so that pack() works as you'd expect.""" self.frame.pack(**kwargs)
class Panle: def __init__(self, master): self.frame = Frame(master) self.frame.pack(side=TOP) self.label = Tkinter.Label(self.frame, text='wordEcho') self.label.pack() self.input = Entry(self.frame, width=45) self.input.pack(side=LEFT) self.button = Button(self.frame, text='翻译') self.button.pack(side=RIGHT) self.frame2 = Scrollbar(master) self.frame2.pack(side=TOP) self.ms = Message(self.frame2, anchor='w', width=150) self.ms.pack()
def __init__(self,parent,caller,**args): Frame.__init__(self,parent,**args) self.pack(side=TOP) self.canvas = Canvas(self,scrollregion=(0,0,1000,1000) ,background='white',cursor='pencil') self.canvas.bind("<Button-1>",lambda event:caller.clickCell(event,1)) self.canvas.bind("<B1-Motion>",lambda event:caller.clickCell(event,1)) self.canvas.bind("<Control-Button-1>",lambda event:caller.clickCell(event,-1)) self.canvas.bind("<Control-B1-Motion>",lambda event:caller.clickCell(event,-1)) vScroll = Scrollbar(self, orient = VERTICAL) vScroll.pack(side = RIGHT, fill=Y) vScroll.config(command = self.canvas.yview) hScroll = Scrollbar(self, orient = HORIZONTAL) hScroll.pack(side = BOTTOM, fill=X) hScroll.config(command = self.canvas.xview) self.canvas.config(xscrollcommand = hScroll.set, yscrollcommand = vScroll.set) self.canvas.pack(side=LEFT)
class ScrollableFrame(Frame): def __init__(self, root): Frame.__init__(self, root) self.canvas = ResizingCanvas(self, borderwidth=0) self.frame = Frame(self.canvas) self.vsb = Scrollbar( self, orient="vertical", command=self.canvas.yview) self.canvas.configure(yscrollcommand=self.vsb.set) self.vsb.pack(side="right", fill="y") self.canvas.pack(side="left", fill="both", expand=True) self.canvas.create_window( (4, 4), window=self.frame, anchor="nw", tags="self.frame") self.frame.bind("<Configure>", self.OnFrameConfigure) def OnFrameConfigure(self, event): '''Reset the scroll region to encompass the inner frame''' # print "OnFrameConfigure" self.canvas.configure(scrollregion=self.canvas.bbox("all"))
class TypingField(Frame): def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent self.submit_tog = True self.initUI() self.text.bind_class("Text","<Control-a>", self.selectall) def initUI(self): self.parent.title("Text Field") self.pack(fill = BOTH, expand=True) frame1 = Frame(self, width = 50, height =25) frame1.pack(fill = X, expand=True) self.scroll = Scrollbar(frame1) self.scroll.pack(side = "right", fill = Y) self.text = Text(frame1) self.text.pack(fill=Y) self.scroll.config(command=self.text.yview) self.text.config(yscrollcommand=self.scroll.set) frame2 = Frame(self) frame2.pack(fill=X, expand=True) self.submit = Button(frame2,text="Start Test") self.submit.bind("<Button-1>", self.startPause) self.submit.pack(fill=X) def startPause(self, event): self.text.focus_set() if self.submit_tog: self.submit.configure(text = "Pause") else: self.submit.configure(text = "Start Test") self.submit_tog = not self.submit_tog def selectall(self, event): event.widget.tag_add("sel","1.0","end")
class TypingField(Frame): def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent self.submit_tog = True self.initUI() self.text.bind_class("Text", "<Control-a>", self.selectall) def initUI(self): self.parent.title("Text Field") self.pack(fill=BOTH, expand=True) frame1 = Frame(self, width=50, height=25) frame1.pack(fill=X, expand=True) self.scroll = Scrollbar(frame1) self.scroll.pack(side="right", fill=Y) self.text = Text(frame1) self.text.pack(fill=Y) self.scroll.config(command=self.text.yview) self.text.config(yscrollcommand=self.scroll.set) frame2 = Frame(self) frame2.pack(fill=X, expand=True) self.submit = Button(frame2, text="Start Test") self.submit.bind("<Button-1>", self.startPause) self.submit.pack(fill=X) def startPause(self, event): self.text.focus_set() if self.submit_tog: self.submit.configure(text="Pause") else: self.submit.configure(text="Start Test") self.submit_tog = not self.submit_tog def selectall(self, event): event.widget.tag_add("sel", "1.0", "end")
class ScrolledText(Text): def __init__(self, master=None, **kw): self.frame = Frame(master) self.vbar = Scrollbar(self.frame) self.vbar.pack(side=RIGHT, fill=Y) kw.update({'yscrollcommand': self.vbar.set}) Text.__init__(self, self.frame, **kw) self.pack(side=LEFT, fill=BOTH, expand=True) self.vbar['command'] = self.yview # Copy geometry methods of self.frame without overriding Text # methods -- hack! text_meths = vars(Text).keys() methods = vars(Pack).keys() + vars(Grid).keys() + vars(Place).keys() methods = set(methods).difference(text_meths) for m in methods: if m[0] != '_' and m != 'config' and m != 'configure': setattr(self, m, getattr(self.frame, m)) def __str__(self): return str(self.frame)
class Monitor(Frame): def __init__(self, parent, port, baud_rate, ser, toolchain, bii): ''' Params: parent: The parent Frame port: string baud_rate: ser: serial ''' Frame.__init__(self, parent) self.parent = parent self.port = port self.baud_rate = baud_rate self.ser = ser self.toolchain = toolchain self.bii = bii self.initUI() def initUI(self): self.parent.title("Biicode serial monitor %s" % self.port) self.style = Style() # We need to define a style, otherwhise seems flat whit in macos self.style.theme_use(get_style()) for x in range(1): Grid.columnconfigure(self, x, weight=1) for y in [1, 2]: Grid.rowconfigure(self, y, weight=1) self._make_top_bar() self._make_user_input() self._make_rcv_log() self._make_button_bar() self.pack(fill=BOTH, expand=1) self.serial_buffer = "" self.count = 0 self.running = True self.after(50, self.read_serial) # check serial again soon def _make_top_bar(self): menubar = Menu(self.parent) filemenu = Menu(menubar, tearoff=0) biimenu = Menu(menubar, tearoff=0) editmenu = Menu(menubar, tearoff=0) biimenu.add_command(label="Work (Save and process)", command=self.bii.work) biimenu.add_command(label="Find", command=self.bii.find) menubar.add_cascade(label="bii", menu=biimenu) filemenu.add_command(label="Flash code", command=self.upload) filemenu.add_separator() filemenu.add_command(label="Exit", command=self.parent.quit) menubar.add_cascade(label="File", menu=filemenu) editmenu.add_command(label="Clear", command=self.clear) # editmenu.add_separator() menubar.add_cascade(label="Edit", menu=editmenu) self.parent.config(menu=menubar) def _make_button_bar(self): self.button_upload = Button(self, text="Flash code", command=self.upload) self.button_upload.style = self.style self.button_upload.grid(row=0, column=0, padx=2, pady=2) self.baud_rate = 9600 self.button_combobox = Combobox(self) self.button_combobox.bind("<<ComboboxSelected>>", self._update_baud_rate) bauds = (300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200) self.button_combobox['values'] = bauds self.button_combobox.current(4) self.button_combobox.grid(row=3, column=1, padx=2, pady=2) def _make_user_input(self): # make user input self.user_input = Text(self, width=52, height=3, takefocus=1, borderwidth=1, relief='ridge') self.user_input.grid(row=1, column=0, padx=2, pady=2, sticky=N + S + E + W) # make send button self.button_send = Button(self, text="Send", command=self.send_clicked) self.button_send.style = self.style self.button_send.grid(row=1, column=1, padx=2, pady=2, sticky=N + S + E + W) def _make_rcv_log(self): # make receive log recvLogFrame = Frame(self, width=400, height=200) recvLogFrame.style = self.style recvLogFrame.grid(row=2, column=0, padx=2, pady=2, sticky=N + S + E + W) self.start_stop_button = Button(self, text="Stop", command=self.start_stop_clicked) self.start_stop_button.style = self.style self.start_stop_button.grid(row=2, column=1, padx=2, pady=2, sticky=N + S + E + W) # make a scrollbar self.scrollbar = Scrollbar(recvLogFrame) self.scrollbar.pack(side=RIGHT, fill=Y) # make a text box to put the serial output self.log = Text(recvLogFrame, width=50, height=30, takefocus=0, borderwidth=1, relief='ridge') self.log.pack(fill=BOTH, expand=True) # attach text box to scrollbar self.log.config(yscrollcommand=self.scrollbar.set) self.scrollbar.config(command=self.log.yview) def send_clicked(self): data = str(self.user_input.get(1.0, "end-1c") + '\0') self.ser.write(data) self._log(data) self.user_input.delete(1.0, END) def _log(self, msg): # if platform.system() == 'Darwin': # print '>> %s' % msg # else: self.log.insert(END, '\n>> %s' % msg) self.log.yview(END) self.update_idletasks() def clear(self): self.log.delete(1.0, END) self.update_idletasks() def start_stop_clicked(self): if self.running: self.running = False self.start_stop_button['text'] = 'Start' else: self.running = True self.start_stop_button['text'] = 'Stop' self.read_serial() # check serial again soon def upload(self): self.bii.work() try: if platform.system() == 'Darwin': self.toolchain.upload() else: self.ser.close() self.toolchain.upload() self.ser.open() self._log('** Code uploaded **') except BiiException: self._log('** Code upload failed **') def _update_baud_rate(self, event=None): new_rate = self.button_combobox.get() if new_rate != self.baud_rate: self.baud_rate = new_rate self.ser.setBaudrate(new_rate) logger.debug('Updated serial speed to %s' % new_rate) self.update_idletasks() def read_serial(self): self.log.update() # display input text self._read_character() if self.running: self.after(100, self.read_serial) # check serial again soon self.after(100, self.update_idletasks) def _read_character(self): try: c = self.ser.read() # attempt to read a character from Serial except SerialException as e: logger.error("Couldn't read serial port: %s" % str(e)) return # was anything read? while len(c) > 0 and c != '\r': # get the buffer from outside of this function # check if character is a delimeter if c == '\r': c = '' # don't want returns. chuck it if c == '\n': # self.serial_buffer += "\n" # add the newline to the buffer self.log.insert(END, "\n") self.log.insert(END, self.serial_buffer) self.log.yview(END) self.update_idletasks() self.serial_buffer = "" # empty the buffer else: self.serial_buffer += c # add to the buffer c = self.ser.read()
TCP_IP = "127.0.0.1" TCP_IP = raw_input("Enter IP: ") TCP_PORT = int(input("Enter port number: ")) key = raw_input("Enter id(default is 0): ") b1 = "up" xold, yold = None, None root = Tk() root.title("WhiteBoard") frame = Frame(root, width=200,height=100) frame.pack(expand=YES, fill=BOTH) # Scrollbars for canvas hScroll = Scrollbar(frame, orient=HORIZONTAL) vScroll = Scrollbar(frame, orient=VERTICAL) hScroll.pack(side=BOTTOM, fill=X) vScroll.pack(side=RIGHT, fill=Y) # canvas drawing_area = Canvas(frame, width=root.winfo_screenwidth()-800, height=root.winfo_screenheight()-400, scrollregion=(0, 0, root.winfo_screenwidth(), root.winfo_screenheight()), yscrollcommand=vScroll.set, xscrollcommand=hScroll.set) Scalewidth=root.winfo_screenwidth() Scaleheight=root.winfo_screenheight() hScroll['command'] = drawing_area.xview vScroll['command'] = drawing_area.yview # Canvas background drawing_area.pack(fill=BOTH, expand=YES) drawing_area["background"]="white" draw = []
class Monitor(Frame): def __init__(self, parent, port, baud_rate, ser, toolchain, bii): ''' Params: parent: The parent Frame port: string baud_rate: ser: serial ''' Frame.__init__(self, parent) self.parent = parent self.port = port self.baud_rate = baud_rate self.ser = ser self.toolchain = toolchain self.bii = bii self.initUI() def initUI(self): self.parent.title("Biicode serial monitor %s" % self.port) self.style = Style( ) # We need to define a style, otherwhise seems flat whit in macos self.style.theme_use(get_style()) for x in range(1): Grid.columnconfigure(self, x, weight=1) for y in [1, 2]: Grid.rowconfigure(self, y, weight=1) self._make_top_bar() self._make_user_input() self._make_rcv_log() self._make_button_bar() self.pack(fill=BOTH, expand=1) self.serial_buffer = "" self.count = 0 self.running = True self.after(50, self.read_serial) # check serial again soon def _make_top_bar(self): menubar = Menu(self.parent) filemenu = Menu(menubar, tearoff=0) biimenu = Menu(menubar, tearoff=0) editmenu = Menu(menubar, tearoff=0) biimenu.add_command(label="Work (Save and process)", command=self.bii.work) biimenu.add_command(label="Find", command=self.bii.find) menubar.add_cascade(label="bii", menu=biimenu) filemenu.add_command(label="Flash code", command=self.upload) filemenu.add_separator() filemenu.add_command(label="Exit", command=self.parent.quit) menubar.add_cascade(label="File", menu=filemenu) editmenu.add_command(label="Clear", command=self.clear) # editmenu.add_separator() menubar.add_cascade(label="Edit", menu=editmenu) self.parent.config(menu=menubar) def _make_button_bar(self): self.button_upload = Button(self, text="Flash code", command=self.upload) self.button_upload.style = self.style self.button_upload.grid(row=0, column=0, padx=2, pady=2) self.baud_rate = 9600 self.button_combobox = Combobox(self) self.button_combobox.bind("<<ComboboxSelected>>", self._update_baud_rate) bauds = (300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200) self.button_combobox['values'] = bauds self.button_combobox.current(4) self.button_combobox.grid(row=3, column=1, padx=2, pady=2) def _make_user_input(self): # make user input self.user_input = Text(self, width=52, height=3, takefocus=1, borderwidth=1, relief='ridge') self.user_input.grid(row=1, column=0, padx=2, pady=2, sticky=N + S + E + W) # make send button self.button_send = Button(self, text="Send", command=self.send_clicked) self.button_send.style = self.style self.button_send.grid(row=1, column=1, padx=2, pady=2, sticky=N + S + E + W) def _make_rcv_log(self): # make receive log recvLogFrame = Frame(self, width=400, height=200) recvLogFrame.style = self.style recvLogFrame.grid(row=2, column=0, padx=2, pady=2, sticky=N + S + E + W) self.start_stop_button = Button(self, text="Stop", command=self.start_stop_clicked) self.start_stop_button.style = self.style self.start_stop_button.grid(row=2, column=1, padx=2, pady=2, sticky=N + S + E + W) # make a scrollbar self.scrollbar = Scrollbar(recvLogFrame) self.scrollbar.pack(side=RIGHT, fill=Y) # make a text box to put the serial output self.log = Text(recvLogFrame, width=50, height=30, takefocus=0, borderwidth=1, relief='ridge') self.log.pack(fill=BOTH, expand=True) # attach text box to scrollbar self.log.config(yscrollcommand=self.scrollbar.set) self.scrollbar.config(command=self.log.yview) def send_clicked(self): data = str(self.user_input.get(1.0, "end-1c") + '\0') self.ser.write(data) self._log(data) self.user_input.delete(1.0, END) def _log(self, msg): # if platform.system() == 'Darwin': # print '>> %s' % msg # else: self.log.insert(END, '\n>> %s' % msg) self.log.yview(END) self.update_idletasks() def clear(self): self.log.delete(1.0, END) self.update_idletasks() def start_stop_clicked(self): if self.running: self.running = False self.start_stop_button['text'] = 'Start' else: self.running = True self.start_stop_button['text'] = 'Stop' self.read_serial() # check serial again soon def upload(self): self.bii.work() try: if platform.system() == 'Darwin': self.toolchain.upload() else: self.ser.close() self.toolchain.upload() self.ser.open() self._log('** Code uploaded **') except BiiException: self._log('** Code upload failed **') def _update_baud_rate(self, event=None): new_rate = self.button_combobox.get() if new_rate != self.baud_rate: self.baud_rate = new_rate self.ser.setBaudrate(new_rate) logger.debug('Updated serial speed to %s' % new_rate) self.update_idletasks() def read_serial(self): self.log.update() # display input text self._read_character() if self.running: self.after(100, self.read_serial) # check serial again soon self.after(100, self.update_idletasks) def _read_character(self): try: c = self.ser.read() # attempt to read a character from Serial except SerialException as e: logger.error("Couldn't read serial port: %s" % str(e)) return # was anything read? while len(c) > 0 and c != '\r': # get the buffer from outside of this function # check if character is a delimeter if c == '\r': c = '' # don't want returns. chuck it if c == '\n': # self.serial_buffer += "\n" # add the newline to the buffer self.log.insert(END, "\n") self.log.insert(END, self.serial_buffer) self.log.yview(END) self.update_idletasks() self.serial_buffer = "" # empty the buffer else: self.serial_buffer += c # add to the buffer c = self.ser.read()
T.insert(END, str(e)+'\n','redcol') T.config(yscrollcommand=S.set,state="disabled") ## Tkinter below root = Tk() root.title("Updater ver: "+str(v)) root.minsize(280,300) frame = Frame(root, height=210,width=600, relief=SUNKEN) frame.pack_propagate(0) frame.pack(anchor=NE,side=TOP,padx=20,pady=20) S = Scrollbar(frame) T = Text(frame, height=46, width=80,wrap=WORD) S.pack(side=RIGHT, fill=Y) T.pack(side=BOTTOM,fill=BOTH,expand=1) S.config(command=T.yview) T.tag_configure('redcol', foreground='red') T.tag_configure('blackcol', foreground='black') T.tag_configure('greencol', background='#c8d9ea',foreground='#009900') T.tag_configure('failed', background='#c8d9ea',foreground='red') button = Button(root, text='Reopen client', command=lambda: {restart_client(),root.destroy()}) button.place(x=180,y=250) button2 = Button(root, text='Close', command=lambda: {root.destroy()}) button2.place(x=360,y=250) ## Create download link list tlist = [] tfile = readf('load/upd_filelist')
class GuiFrame(): ## The constructor # # @param self [in] Object reference # @param parent [in] Root object reference # @param rulesFile [in] Rules file name # @param outDir [in] Location of output directory # @return None def __init__(self, parent, rulesFile, outDir): self.exit = False self.parent = parent self.rulesFile = rulesFile self.outDir = outDir self.bgndFrm = None self.scrollbar = None self.log = None # Create the outdir if it doesn't exist if not os.path.exists(outDir): os.makedirs(outDir) self.initUI() self.parseRules = ParseRules(self) self.parseRules.verifyParameters() ## Close button press # # Called when the close button is pressed. # # @param self [in] Object reference # @return None def closeBtnPress(self): self.exit = True ## Init UI # # Initialize the user interface. Create the cmd panel at the # top which contains the status and column headings. Walk # through the cardType array and create a panel for each card. # # @param self [in] Object reference # @return None def initUI(self): self.parent.wm_title("Generate Python Code GUI") self.parent.columnconfigure(0, weight=1) self.parent.rowconfigure(0, weight=1) self.bgndFrm = Frame(self.parent) self.bgndFrm.grid() self.cmdPanel() self.consolePanel() ## Create command panel # # Create the command panel. It contains the close button. # # @param self [in] Object reference # @return None def cmdPanel(self): tmpFrm = Frame(self.bgndFrm, borderwidth = 5, relief=RAISED) tmpFrm.grid() tmpFrm.grid(column = 0, row = 0) tmpBtn = Button(tmpFrm, width = 12, text="Close", command=self.closeBtnPress) tmpBtn.grid(column = 0, row = 0, padx=4, pady=8) ## Create console panel # # Create the console panel. It the console text box. # # @param self [in] Object reference # @return None def consolePanel(self): tmpFrm = Frame(self.bgndFrm, borderwidth = 5, relief=RAISED) tmpFrm.grid() tmpFrm.grid(column = 0, row = 1) self.scrollbar = Scrollbar(tmpFrm) self.scrollbar.pack(side=RIGHT, fill=Y) self.log = Text(tmpFrm, wrap=WORD, yscrollcommand=self.scrollbar.set) self.log.pack() self.scrollbar.config(command=self.log.yview) ## Update console # # Update the console window with new text # # @param self [in] Object reference # @param text [in] Text to be added to the console window # @return None def updateConsole(self, text): self.log['state'] = 'normal' self.log.insert('end', text + "\n") self.log['state'] = 'disabled' self.log.see(END) ## GUI exit # # Set the exit flag. # # @param self [in] Object reference # @return None def gui_exit(self): self.exit = True
class Edit_save(object): def __init__(self): self.root = Tk() self.root.title('EditSave') self.root.geometry('+120+50') self.font_en = Font(self.root, size=12) self.font_text = Font(self.root,family="Helvetica", size=12, weight='normal') self.menubar = Menu(self.root, bg='purple') self.filemenu = Menu(self.menubar) self.filemenu.add_command(label='Open', accelerator='Ctrl+o', command=self.__open, underline=0) self.filemenu.add_command(label='Save', accelerator='Ctrl+s', command=self.__save, underline=0) self.filemenu.add_command(label='Save As', accelerator='Ctrl+Shift+s', command=self.__save_as, underline=5) self.filemenu.add_separator() self.filemenu.add_command(label='Quit', accelerator='Alt+F4', command=self.root.destroy, underline=0) self.menubar.add_cascade(label='File', underline=0, menu=self.filemenu) self.helpmenu = Menu(self.menubar) self.helpmenu.add_command(label='About', underline=0, command=About_editsave) self.menubar.add_cascade(label='Help', underline=0, menu=self.helpmenu) self.editmenu = Menu(self.menubar, tearoff=False) self.editmenu.add_command(label='Refresh', accelerator='F5', command=self.root.update) self.editmenu.add_command(label='Copy', accelerator='Ctrl+C', command=lambda : self.text.event_generate('<<Copy>>')) self.editmenu.add_command(label='Paste', accelerator='Ctrl+V', command=lambda : self.text.event_generate('<<Paste>>')) self.editmenu.add_command(label='Cut', accelerator='Ctrl+X', command=lambda : self.text.event_generate('<<Cut>>')) # self.editmenu.add_command(label='Undo', accelerator='Ctrl+Z', # command=lambda : self.text.event_generate('<<Undo>>')) # self.editmenu.add_command(label='Redo', accelerator='Ctrl+Y', # command=lambda : self.text.event_generate('<<Redo>>')) self.editmenu.add_command(label='select_all', accelerator='Ctrl+A', command=lambda : self.text.tag_add('sel', '1.0', 'end')) self.fm_base = Frame(self.root) self.fm_up = Frame(self.fm_base) self.var = StringVar() self.en = Entry(self.fm_up, font=self.font_en, textvariable=self.var, width=20) self.bt_open = Button(self.fm_up, text='Open',) self.bt_quit = Button(self.fm_up, text='Quit', underline=0) self.bt_quit.pack(side=RIGHT, padx=10) self.bt_open.pack(side=RIGHT, padx=5) self.en.pack(side=RIGHT, pady=5) self.bt_open.config(command=self.__open) self.bt_quit.config(command=self.root.destroy) self.fm_up.pack(fill=X) self.fm_base.pack(fill=X) self.fm_down = Frame(self.root) self.text = Text(self.fm_down, font=self.font_text, width=50, height=20) self.text.pack(side=LEFT, fill=BOTH, expand=True) self.scb = Scrollbar(self.fm_down) self.scb.pack(side=LEFT, fill=Y) self.text.config(yscrollcommand=self.scb.set) self.scb.config(command=self.text.yview) self.fm_down.pack(fill=BOTH, expand=True) self.root.bind('<Control-o>', self.__invoke_open) self.root.bind('<Control-O>', self.__invoke_open) self.root.bind('<Control-s>', self.__invoke_save) self.root.bind('<Control-S>', self.__invoke_save_as) self.root.bind('<Button-3>', self.__popupmenu) self.root.bind('Alt-F4', lambda event: self.root.destroy) self.root.bind('<F5>', lambda event: self.root.update) self.root.bind('<Control-C>', lambda event: self.text.event_generate('<<Copy>>')) self.root.bind('<Control-V>', lambda event: self.text.event_generate('<<Paste>>')) self.root.bind('<Control-X>', lambda event: self.text.event_generate('<<Cut>>')) for i in 'a', 'A': self.root.bind('<Control-%s>' % i, lambda event: self.text.tag_add('sel', '1.0', 'end')) # for i in 'z', 'Z': # self.root.bind('<Control-%s>' % i, # lambda event: self.text.event_generate('<<Undo>>')) # for i in 'y', 'Y': # self.root.bind('<Control-%s>' % i, # lambda event: self.text.event_generate('<<Redo>>')) self.root.config(menu=self.menubar) self.root.mainloop() def __open(self): filetypes = [ ("All Files", '*'), ("Python Files", '*.py', 'TEXT'), ("Text Files", '*.txt', 'TEXT'), ("Config Files", '*.conf', 'TEXT')] fobj = askopenfile(filetypes=filetypes) if fobj: self.text.delete('1.0', END) self.text.insert('1.0', fobj.read()) self.en.delete(0, END) self.en.insert(0, fobj.name) def __save(self): value = self.var.get().strip() if value: f = open(value, 'w') f.write(self.text.get('1.0', END).strip() + '\n') f.close() else: self.__save_as() def __save_as(self): text_value = self.text.get('1.0', END).strip() if text_value: fobj = asksaveasfile() if fobj: fobj.write(text_value + '\n') def __invoke_open(self, event): self.__open() def __invoke_save(self, event): self.__save() def __invoke_save_as(self, event): self.__save_as() def __popupmenu(self, event): self.editmenu.post(event.x_root, event.y_root)
class GuiFrame(): ## The constructor # # @param self [in] Object reference # @param parent [in] Root object reference # @param rulesFile [in] Rules file name # @param outDir [in] Location of output directory # @return None def __init__(self, parent, rulesFile, outDir): self.exit = False self.parent = parent self.rulesFile = rulesFile self.outDir = outDir self.bgndFrm = None self.scrollbar = None self.log = None # Create the outdir if it doesn't exist if not os.path.exists(outDir): os.makedirs(outDir) self.initUI() self.parseRules = ParseRules(self) self.parseRules.verifyParameters() ## Close button press # # Called when the close button is pressed. # # @param self [in] Object reference # @return None def closeBtnPress(self): self.exit = True ## Init UI # # Initialize the user interface. Create the cmd panel at the # top which contains the status and column headings. Walk # through the cardType array and create a panel for each card. # # @param self [in] Object reference # @return None def initUI(self): self.parent.wm_title("Generate Python Code GUI") self.parent.columnconfigure(0, weight=1) self.parent.rowconfigure(0, weight=1) self.bgndFrm = Frame(self.parent) self.bgndFrm.grid() self.cmdPanel() self.consolePanel() ## Create command panel # # Create the command panel. It contains the close button. # # @param self [in] Object reference # @return None def cmdPanel(self): tmpFrm = Frame(self.bgndFrm, borderwidth=5, relief=RAISED) tmpFrm.grid() tmpFrm.grid(column=0, row=0) tmpBtn = Button(tmpFrm, width=12, text="Close", command=self.closeBtnPress) tmpBtn.grid(column=0, row=0, padx=4, pady=8) ## Create console panel # # Create the console panel. It the console text box. # # @param self [in] Object reference # @return None def consolePanel(self): tmpFrm = Frame(self.bgndFrm, borderwidth=5, relief=RAISED) tmpFrm.grid() tmpFrm.grid(column=0, row=1) self.scrollbar = Scrollbar(tmpFrm) self.scrollbar.pack(side=RIGHT, fill=Y) self.log = Text(tmpFrm, wrap=WORD, yscrollcommand=self.scrollbar.set) self.log.pack() self.scrollbar.config(command=self.log.yview) ## Update console # # Update the console window with new text # # @param self [in] Object reference # @param text [in] Text to be added to the console window # @return None def updateConsole(self, text): self.log['state'] = 'normal' self.log.insert('end', text + "\n") self.log['state'] = 'disabled' self.log.see(END) ## GUI exit # # Set the exit flag. # # @param self [in] Object reference # @return None def gui_exit(self): self.exit = True
T.config(yscrollcommand=S.set, state="disabled") ## Tkinter below root = Tk() root.title("Updater ver: " + str(v)) root.minsize(280, 300) frame = Frame(root, height=210, width=600, relief=SUNKEN) frame.pack_propagate(0) frame.pack(anchor=NE, side=TOP, padx=20, pady=20) S = Scrollbar(frame) T = Text(frame, height=46, width=80, wrap=WORD) S.pack(side=RIGHT, fill=Y) T.pack(side=BOTTOM, fill=BOTH, expand=1) S.config(command=T.yview) T.tag_configure('redcol', foreground='red') T.tag_configure('blackcol', foreground='black') T.tag_configure('greencol', background='#c8d9ea', foreground='#009900') T.tag_configure('failed', background='#c8d9ea', foreground='red') button = Button( root, text='Reopen client', command=lambda: {restart_client(), root.destroy()}) button.place(x=180, y=250) button2 = Button(root, text='Close', command=lambda: {root.destroy()}) button2.place(x=360, y=250)