def __init__(self, parent, resizeCallback = None, width=600, height=600, *args, **kw): self.bbox = None self.busy = 0 self.initialX = None self.initialY = None self.resizeCallback = resizeCallback apply(Frame.__init__, (self, parent) + args, kw) self.grid_rowconfigure(0, weight=1) self.grid_columnconfigure(0, weight=1) self.menu = Menu(self, tearoff=0, include_event=True) self.configMenu() self.canvas = Canvas(self, relief='flat', borderwidth=0, width=width, height=height) self.canvas.configure(xscrollincrement=2, yscrollincrement=2) self.canvas.grid(row = 0, column = 0, sticky = Tkinter.NSEW ) self.horizScrollbar = Tkinter.Scrollbar(self, bg=self.cget('bg'), command=self.canvas.xview, orient=Tkinter.HORIZONTAL, borderwidth=1) self.vertScrollbar = Tkinter.Scrollbar(self, bg=self.cget('bg'), command=self.canvas.yview, orient=Tkinter.VERTICAL, borderwidth=1) self.canvas.configure(xscrollcommand=self.horizScrollbar.set,yscrollcommand=self.vertScrollbar.set) self.canvas.bind('<Configure>', self.resizeAfter) self.canvas.bind('<Button-1>', self.mouseButton1) self.canvas.bind('<Button-2>', self.mouseButton2) self.canvas.bind('<Button-3>', self.mouseButton3) self.canvas.bind('<ButtonRelease-1>', self.mouseButtonRelease1) self.canvas.bind('<ButtonRelease-2>', self.mouseButtonRelease2) self.canvas.bind('<B2-Motion>', self.mouseScroll) self.canvas.bind('<B3-Motion>', self.doNothing) self.canvas.bind('<Motion>', self.mouseEnter) self.canvas.bind('<Enter>', self.mouseEnter)
def body(self, parent): self.bw = 2 # borderwidth width = self.cWidth + self.bw height = self.cHeight + self.bw self.label = Label(parent, text=self.text) self.label.grid(row=0, column=0, sticky=Tkinter.W) self.percent = Label(parent, text=' %') self.percent.grid(row=0, column=2, sticky=Tkinter.W) self.canvas = Canvas(parent, background='grey70', width=width, height=height) self.canvas.grid(row=0, column=1, sticky=Tkinter.W) self.canvas.create_rectangle(0, 0, width, height, outline='black', width=self.bw) self.bar = self.canvas.create_rectangle(self.bw, self.bw, self.bw, self.cHeight, outline='#B05848', fill='#B05848', width=self.bw) self.update()
def __init__(self, parent, callback, speed = 1.5, delay = 50, fill = 'grey73', outline = 'grey90', hilight='grey90', width = 144, height = 24, *args, **kw): self.callback = callback self.speed = speed self.delay = delay self.fill = fill self.outline = outline self.hilight = hilight Frame.__init__(self, parent=parent, *args, **kw) # if canvas width/height fixed then resizing has no effect, it seems #self.grid_rowconfigure(0, weight=1) #self.grid_columnconfigure(0, weight=1) font = '-schumacher-clean-bold-r-normal--14-140-75-75-c-70-iso646.1991-irv' self.canvas = c = Canvas(self, width=width, height=height, relief='flat', borderwidth=0) c.bind('<Configure>', self.resize) c.bind('<ButtonPress>', self.press) c.bind('<Motion>', self.motion) c.bind('<Enter>', self.mouseEnter) c.bind('<Leave>', self.mouseLeave) c.bind('<ButtonRelease>', self.release) self.bg = c.create_rectangle(1, 1, 1, 1, fill='red', outline='grey50') self.boxes0 = [] self.boxes1 = [] self.boxes2 = [] self.strikes = [] self.dashes = [] for n in range(24): box1 = c.create_rectangle(0, 0, 0, 0, fill=outline, outline=outline) box2 = c.create_rectangle(0, 0, 0, 0, fill=outline, outline=outline) box0 = c.create_rectangle(0, 0, 0, 0, fill=outline, outline=outline) self.boxes0.append(box0) self.boxes1.append(box1) self.boxes2.append(box2) for n in range(8): dash = c.create_line(0,0,0,0,fill='black') self.dashes.append( dash ) for n in range(4): strike = c.create_line(0,0,0,0,fill='black') self.strikes.append( strike ) c.grid(row=0, column=0, sticky=Tkinter.NSEW) self.continue_callback = False self.multiplier = 1.0
def __init__(self, parent, callback=None, texts=None, objects=None, categories=None, colors=None, index=0, prefix='', indent='', initCallback=False, forceCallback=False, numbering=False, arrowLine='#602000', arrowFill='#B05848', labelColor='#501000', menuBg='#F0F0FF', sticky='w', docKey=None, tipText=None, categoriesLast=True, *args, **kw): Frame.__init__(self, parent, sticky=sticky, docKey=docKey, tipText=tipText, createToolTip=True, *args, **kw) self.callback = callback self.texts = texts or [] self.objects = objects or [] self.categories = categories or [] self.colors = colors or [] self.prefix = prefix self.indent = indent self.initCallback = initCallback self.numbering = numbering self.arrowLine = arrowLine self.arrowFill = arrowFill self.labelColor = labelColor self.active = True self.categoriesLast = categoriesLast # Current selection self.index = None self.object = NullText self.rows = [] self.bg = self.cget('bg') self.label = Label(self, foreground=labelColor) self.canvas = Canvas(self, width=12, height=12, background=self.bg) self.menu = Menu(self.canvas, tearoff=False, bg=menuBg, relief='solid', borderwidth=1, activeborderwidth=1) self.menu.images = [] # Photoimage has to remain referenced self.setup(self.texts, self.objects, index, self.colors, self.categories) self.label.bind( "<Button-1>", self._labelClick) self.menu.bind( "<Leave>", self._leave) self.canvas.bind("<Button-1>", self._canvasClick) self.canvas.bind("<Configure>", self._resizeCallback) self.grid_columnconfigure(0, weight=1) self.label.grid(row=0, column=0, sticky='w') self.canvas.grid(row=0, column=1, sticky='w', padx=2)
def __init__(self, parent, color='black', side='both', canvas_bg='lightgrey', *args, **kw): self.color = color self.side = side apply(Frame.__init__, (self, parent) + args, kw) #self.grid_rowconfigure(0, weight=1) #self.grid_columnconfigure(1, weight=1) fill = Tkinter.X w = kw.get('width', 1) z = h = kw.get('height', 1) #self.canvas.config(height=h) self.canvas = Canvas(self, width=w, height=h, background=canvas_bg) self.cross = {'upper': [], 'lower': [], 'both': []} # # This is setup only... coordinates do not matter here # if self.side in ['both', 'upper']: self.cross['upper'].append( self.canvas.create_line(0, 0, 0, 0, fill=color)) self.cross['upper'].append( self.canvas.create_line(0, 0, 0, 0, fill=color)) self.cross['both'].append( self.canvas.create_line(0, 0, 0, 0, fill=color)) if self.side in ['both', 'lower']: self.cross['lower'].append( self.canvas.create_line(0, 0, 0, 0, fill=color)) self.cross['lower'].append( self.canvas.create_line(0, 0, 0, 0, fill=color)) self.canvas.pack(expand=Tkinter.YES, fill=fill) #self.canvas.bind('<Configure>', self.resizeCallback) self.bind('<Configure>', self.resizeCallback)
def __init__(self, parent, borderRelief='raised', text=' ', justify='left', font=None, sticky='ew', docKey=None, tipText=None, *args, **kw): Frame.__init__(self, parent, sticky=sticky, *args, **kw) self.borderRelief = borderRelief self.bg = self.cget('bg') self.justify = justify self.canvas1 = Canvas(self, background=self.bg) if self.borderRelief == 'sunken': fill1 = 'grey60' fill2 = 'white' else: fill1 = 'white' fill2 = 'grey60' fill3 = 'grey85' self.label = Label(self, text=text, font=font, docKey=docKey, tipText=tipText) self.label.grid() self.canvasL = [ self.canvas1.create_rectangle(0, 0, 0, 0, width=0, fill=fill1), self.canvas1.create_rectangle(0, 0, 0, 0, width=0, fill=fill2), self.canvas1.create_rectangle(0, 0, 0, 0, width=0, fill=fill3) ] self.canvasR = [ self.canvas1.create_rectangle(0, 0, 0, 0, width=0, fill=fill1), self.canvas1.create_rectangle(0, 0, 0, 0, width=0, fill=fill2), self.canvas1.create_rectangle(0, 0, 0, 0, width=0, fill=fill3) ] self.bind('<Configure>', self.resize)
def __init__(self, parent, arrowSize=11, outline='#5050b0', fill='#a0a0ff', isArrowClosed=True, callback=None, *args, **kw): self.arrowSize = arrowSize self.isArrowClosed = isArrowClosed self.callback = callback apply(Frame.__init__, (self, parent) + args, kw) bg = kw.get('bg') if (not bg): bg = kw.get('background') if (not bg): bg = parent.cget('bg') # below does not work for some reason, instead explicitly create rectangle below #self.canvas = Canvas(self, width=arrowSize, height=arrowSize, bg=bg) self.canvas = Canvas(self, width=arrowSize + 3, height=arrowSize + 1) self.canvas.grid(row=0, column=0) # need +/-1 otherwise get line along borders self.canvas.create_rectangle(-1, -1, arrowSize + 3, arrowSize + 1, fill=bg) # arbitrary coords self.arrow = self.canvas.create_polygon(0, 0, 1, 0, 1, 1, fill=fill, outline=outline) self.drawArrow() self.canvas.bind('<Button-1>', self.flipState)
def refreshSize(self, event=None): canvas = Canvas(self) textItem = canvas.create_text(0, 0, text='A', font=self.font) coords = canvas.bbox(textItem) letterWidth = coords[2] - coords[0] + 2 canvas.destroy() if not self.buttons: return if event: width = event.width height = event.height else: width = int(self.winfo_width()) height = int(self.winfo_height()) self.maxRowObjects = len(self.buttons) x = 0 for i, button in enumerate(self.buttons): text = button.cget('text') if '\n' in text: texts = text.split('\n') text = texts[0] for t in texts[1:]: if len(t) > len(text): text = t n = len(text) x1 = x + int(letterWidth * n) if x1 > width: self.maxRowObjects = max(1, i) break x = x1 self.update(self.objects, None, self.labels, self.colors, self.fonts) self.waiting = False
def __init__(self, parent, relief='raised', *args, **kw): apply(Frame.__init__, (self, parent) + args, kw) #self.grid_rowconfigure(0, weight=1) #self.grid_columnconfigure(1, weight=1) self.bg = self.cget('bg') self.relief = relief self.grid_columnconfigure(0, weight=1) self.canvas = Canvas(self, background=self.bg, width=1, height=6) self.canvas.grid(row=0, column=0, sticky=Tkinter.NSEW) #self.canvas.bind('<Configure>', self.resizeCallback) self.grid(sticky=Tkinter.EW) self.canvasL1 = [] self.canvasL2 = [] self.canvasL3 = [] self.refresh = 0 self.event = None self.bind('<Configure>', self.resizeAfter)
def __init__(self, parent, callback=None, entries=None, text_attr=None, colors=None, outline='#602000', fill='#B05848', label_color='#501000', selected_index=-1, indent='', extra='', sticky='w', do_initial_callback=True, force_callback=False, *args, **kw): if (entries is None): entries = [] Frame.__init__(self, parent, sticky=sticky, *args, **kw) self.text_attr = text_attr #indentation and extra string for popup information self.indent = indent self.extra = extra self.callback = callback self.do_initial_callback = do_initial_callback self.force_callback = force_callback frame = Frame(self) #frame = parent self.frame = frame self.bg = frame.cget('bg') self.outline = outline self.fill = fill self.label_color = label_color self.menu = Menu(parent, tearoff=0, borderwidth=1, activeborderwidth=1) self.menu.images = [] self.label = Label(self, foreground=label_color) self.first_pass = True #self.entries = entries self.entries = [] self.colors = [] self.setup(entries, selected_index, colors=colors) s = 10 self.canvas = Canvas(self, width=s, height=s, background=self.bg) self.label.bind("<Button-1>", self.labelPopup) # below does not work for some reason #self.bind("<Button-1>", self.labelPopup) # below does not work any more since can have submenus and # no way to reach those with below since involves leaving menu #self.menu.bind("<Leave>", self.popdown) self.menu.bind("<Leave>", self.leave) self.menu.bind("<Button-1>", self.buttonPress) self.poppedUpSubmenu = False self.canvas.bind("<Button-1>", self.canvasPopup) self.canvas.bind("<Configure>", self.resizeCallback) self.label.grid(row=0, column=0, sticky=Tkinter.W) self.canvas.grid(row=0, column=1, sticky=Tkinter.E, padx=2)
def __init__(self, parent, borderRelief='raised', text=' ', justify='left', width=None, font=None, height=None, docKey=None, tipText=None, *args, **kw): kw['borderwidth'] = self.bw = 18 Frame.__init__(self, parent, *args, **kw) self.borderRelief = borderRelief self.bg = self.cget('bg') self.justify = justify self.canvas1 = Canvas(self, background=self.bg) self.canvas2 = Canvas(self, background=self.bg) self.canvas3 = Canvas(self, background=self.bg) self.canvas4 = Canvas(self, background=self.bg) if self.borderRelief == 'sunken': fill1 = 'grey60' fill2 = 'white' else: fill1 = 'white' fill2 = 'grey60' fill3 = 'grey85' self.label = Label(self, text=text, font=font, docKey=None, tipText=tipText) self.canvasL1 = [] self.canvasL1a = [] self.canvasL2 = [] self.canvasL3 = [] self.canvasL3a = [] self.canvasL3b = [] self.canvasL4 = [] self.canvasL5 = [] self.canvasL5a = [] self.canvasL1.append( self.canvas1.create_rectangle(0, 0, 0, 0, width=0, fill=fill1)) self.canvasL1a.append( self.canvas1.create_rectangle(0, 0, 0, 0, width=0, fill=fill1)) self.canvasL2.append( self.canvas2.create_rectangle(0, 0, 0, 0, width=0, fill=fill1)) self.canvasL3a.append( self.canvas3.create_rectangle(0, 0, 0, 0, width=0, fill=fill1)) self.canvasL3.append( self.canvas3.create_rectangle(0, 0, 0, 0, width=0, fill=fill1)) self.canvasL3b.append( self.canvas3.create_rectangle(0, 0, 0, 0, width=0, fill=fill1)) self.canvasL4.append( self.canvas4.create_rectangle(0, 0, 0, 0, width=0, fill=fill1)) self.canvasL5.append( self.canvas1.create_rectangle(0, 0, 0, 0, width=0, fill=fill1)) self.canvasL5a.append( self.canvas1.create_rectangle(0, 0, 0, 0, width=0, fill=fill1)) self.canvasL1.append( self.canvas1.create_rectangle(0, 0, 0, 0, width=0, fill=fill2)) self.canvasL1a.append( self.canvas1.create_rectangle(0, 0, 0, 0, width=0, fill=fill2)) self.canvasL2.append( self.canvas2.create_rectangle(0, 0, 0, 0, width=0, fill=fill2)) self.canvasL3a.append( self.canvas3.create_rectangle(0, 0, 0, 0, width=0, fill=fill2)) self.canvasL3.append( self.canvas3.create_rectangle(0, 0, 0, 0, width=0, fill=fill2)) self.canvasL3b.append( self.canvas3.create_rectangle(0, 0, 0, 0, width=0, fill=fill2)) self.canvasL4.append( self.canvas4.create_rectangle(0, 0, 0, 0, width=0, fill=fill2)) self.canvasL5.append( self.canvas1.create_rectangle(0, 0, 0, 0, width=0, fill=fill2)) self.canvasL5a.append( self.canvas1.create_rectangle(0, 0, 0, 0, width=0, fill=fill2)) self.canvasL1.append( self.canvas1.create_rectangle(0, 0, 0, 0, width=0, fill=fill3)) self.canvasL1a.append( self.canvas1.create_rectangle(0, 0, 0, 0, width=0, fill=fill3)) self.canvasL2.append( self.canvas2.create_rectangle(0, 0, 0, 0, width=0, fill=fill3)) self.canvasL3a.append( self.canvas3.create_rectangle(0, 0, 0, 0, width=0, fill=fill3)) self.canvasL3.append( self.canvas3.create_rectangle(0, 0, 0, 0, width=0, fill=fill3)) self.canvasL3b.append( self.canvas3.create_rectangle(0, 0, 0, 0, width=0, fill=fill3)) self.canvasL4.append( self.canvas4.create_rectangle(0, 0, 0, 0, width=0, fill=fill3)) self.canvasL5.append( self.canvas1.create_rectangle(0, 0, 0, 0, width=0, fill=fill3)) self.canvasL5a.append( self.canvas1.create_rectangle(0, 0, 0, 0, width=0, fill=fill3)) self.bind('<Configure>', self.resize)
def __init__(self, parent, scrollX=True, scrollY=True, *args, **kw): self.parent = parent self.scrollX = scrollX self.scrollY = scrollY self.prototypes = [] self.nodes = [] self.node = None # Selected self.links = [] self.link = None # Selected self.objDict = {} # Map canvas to nodes, links self.cornerDict = {} self.editWidget = None self.mouseOver = None self.inMotion = None self.inMotion2 = None self.inMotion3 = None self.dragRegion = None self._resizeBusy = False self.selectedNodes = [] self.selectedLinks = [] self.highlightNodes = [] self.highlightLinks = [] kw['relief'] = 'flat' kw['borderwidth'] = 0 Frame.__init__(self, parent, *args, **kw) self.canvas = canvas = Canvas(self, relief='flat', borderwidth=0) self.canvas.configure(xscrollincrement=2, yscrollincrement=2, bg=self.cget('bg')) self.canvas.grid(row=0, column=0, sticky='nsew') if scrollX: self.horizScrollbar = Tkinter.Scrollbar(self, bg=self.cget('bg'), command=self.canvas.xview, orient=Tkinter.HORIZONTAL, borderwidth=1) self.canvas.configure(xscrollcommand=self.horizScrollbar.set) if scrollY: self.vertScrollbar = Tkinter.Scrollbar(self, bg=self.cget('bg'), command=self.canvas.yview, orient=Tkinter.VERTICAL, borderwidth=1) self.canvas.configure(yscrollcommand=self.vertScrollbar.set) canvas.bind('<Button-1>', self._mouseSingleClick) if not isWindowsOS(): canvas.bind('<Button-4>', self.scrollUp) canvas.bind('<Button-5>', self.scrollDown) else: canvas.bind('<MouseWheel>', self._windowsOsScroll) canvas.bind('<Double-1>', self._mouseDoubleClick) canvas.bind('<B1-Motion>', self._mouseDrag) canvas.bind('<ButtonRelease-1>', self._mouseRelease) canvas.bind('<Motion>', self._mouseEnter) canvas.bind('<Enter>', self._mouseEnter) canvas.bind('<Leave>', self._mouseLeave) canvas.bind('<KeyPress-Up>', self._moveUp) canvas.bind('<KeyPress-Down>', self._moveDown) canvas.bind('<KeyPress-Right>', self._moveRight) canvas.bind('<KeyPress-Left>', self._moveLeft) canvas.bind('<KeyPress-Delete>', self.deleteSelected) self.bind('<Configure>', self._resizeAfter) self.menu = Menu(self, tearoff=False) alignItems = [{ 'kind': 'command', 'label': 'Y axis', 'command': self._alignHorizontal }, { 'kind': 'command', 'label': 'X axis', 'command': self._alignVertical }] distributeItems = [{ 'kind': 'command', 'label': 'Horizontal', 'command': self._distributeHorizontal }, { 'kind': 'command', 'label': 'Verical', 'command': self._distributeVertical }] menuItems = [ { 'kind': 'cascade', 'label': 'Align', 'submenu': alignItems }, #0 { 'kind': 'cascade', 'label': 'Distribute', 'submenu': distributeItems }, #1 { 'kind': 'command', 'label': 'Link Selected', 'command': self.linkSelected }, #2 { 'kind': 'command', 'label': 'Reset Links', 'command': self._resetLinks }, #3 { 'kind': 'separator' }, { 'kind': 'command', 'label': 'Delete Links', #5 'command': self.deleteLinks }, { 'kind': 'command', 'label': 'Delete Items', #6 'command': self.deleteNodes }, { 'kind': 'separator' }, { 'kind': 'command', 'label': 'Save PostScript File', 'command': self.printCanvas }, ] self.menuItems = menuItems self.menu.setMenuItems(menuItems) canvas.bind('<ButtonPress-3>', self._popupMenu) self._drawAfter()
def __init__(self, parent, numButtons, state=None, orient='h', background=None, selectColor='#C0C0FF', size=15, callback=None, label=None, grid=None, *args, **kw): self.numButtons = numButtons self.orient = orient self.selectColor = selectColor self.size = size self.callback = callback self.state = state or [False] * numButtons self.canvasDict = {} self.canvasNums = {} self.initialN = None self.initialS = None if (background is None): self.bg = parent.cget('bg') else: self.bg = background Frame.__init__(self, parent, grid=grid, *args, **kw) self.bgLight = scaleColor(self, self.bg, 1.5) self.bgDark = scaleColor(self, self.bg, 0.4) self.bgLight2 = scaleColor(self, self.bg, 1.2) self.bgDark2 = scaleColor(self, self.bg, 0.7) if label: self.label = Label(self, text=label, tipText=TOOL_TIP) self.label.grid(row=0, column=0, sticky=Tkinter.EW) if orient in (Tkinter.HORIZONTAL, 'horizontal', 'h'): c_row = 0 c_col = 1 else: c_row = 1 c_col = 0 else: self.label = None if orient in (Tkinter.HORIZONTAL, 'horizontal', 'h'): self.orient = 'h' self.canvas = c = Canvas(self, bg=self.bg, height=size) self.grid_columnconfigure(c_col, weight=1) else: self.orient = 'v' self.canvas = c = Canvas(self, bg=self.bg, width=size) self.grid_rowconfigure(c_row, weight=1) c.grid(row=c_row, column=c_col, sticky='nsew') c.bind('<Configure>', self.resizeCanvas) c.bind('<Button-1>', self.slideState) c.bind('<B1-Motion>', self.slideState) c.bind('<ButtonRelease-1>', self.slideStateDone) c.bind('<Button-2>', self.clickState) c.bind('<B2-Motion>', self.clickState) c.bind('<ButtonRelease-2>', self.clickStateDone)
def __init__(self, parent, *args, **kw): apply(Frame.__init__, (self, parent) + args, kw) self.grid_rowconfigure(0, weight=1) self.grid_rowconfigure(1, weight=0) self.grid_rowconfigure(2, weight=0) self.grid_rowconfigure(3, weight=0) self.canvas = Canvas(self, relief='sunken', borderwidth=2, width=150) self.canvas.grid(row=0, column=1, columnspan=1, sticky=Tkinter.NSEW, pady=2, padx=2) frame = Frame(self) frame.grid_columnconfigure(1, weight=1) self.boxSize = 100 self.numPixels = 10 self.pixelWidth = round(self.boxSize / self.numPixels) self.colorBox = Canvas(frame, relief='sunken', borderwidth=2, width=self.boxSize + 2, height=self.boxSize + 2) self.colorBox.bind('<Button-1>', self.pickInColorBox) self.colorBox.bind('<Button-2>', self.pickInColorBox) self.colorBox.bind('<Button-3>', self.pickInColorBox) self.colorBox.grid(row=0, column=2, rowspan=3, sticky=Tkinter.NSEW, padx=4, pady=4) self.pixel = [] self.colors = [] self.setupColorBox() self.scale = Tkinter.Scale(frame, orient=Tkinter.VERTICAL, length=self.boxSize, from_=0, to=99, label='', showvalue=0, command=self.refreshColorBox) self.scale.grid(row=0, column=3, rowspan=3, sticky=Tkinter.NS, padx=4, pady=4) frame.grid(row=1, column=0, columnspan=2, sticky=Tkinter.NSEW) labels = ('Red', 'Green', 'Blue') self.labeled_scale = 3 * [None] for n in range(3): label = Label(frame, text=labels[n] + ':', anchor=Tkinter.W) label.grid(row=n, column=0, sticky=Tkinter.EW) self.labeled_scale[n] = LabeledScale( frame, values=range(101), label_format='%3d', set_callback=self.scaleCallback) self.labeled_scale[n].grid(row=n, column=1, sticky=Tkinter.EW)
def __init__(self, parent, iconSize='medium', multiSelect=False, font='Helvetica 8', doubleCallback=None, *args, **kw): Frame.__init__(self, parent, *args, **kw) self.multiSelect = multiSelect self.icons = {} self.openDict = {} self.scrollbarWidth = 15 self.canvasList = [] self.canvasDict = {} self.canvasLines = [] self._wait = False self.vOffset = 0 self.nodes = [] # Just a list of nodes self.nodeDict = {} # To fetch nodes via objects self.font = font self.doubleCallback = doubleCallback #bg = self.cget('background') iconItems = [{ 'kind': 'command', 'label': 'Small', 'command': self.smallIcons }, { 'kind': 'command', 'label': 'Medium', 'command': self.medIcons }, { 'kind': 'command', 'label': 'Large', 'command': self.largeIcons }] self.menu = Menu(self, tearoff=False) menu_items = [ { 'kind': 'cascade', 'label': 'Icon size', 'submenu': iconItems }, ] self.menu.setMenuItems(menu_items) self.rowHeight = None self.visibleRows = 80 self.setIconSize(iconSize, redraw=False) self.canvas = Canvas(self, relief='flat', borderwidth=0, background=BG_COLOR, xscrollcommand=self._setHScrollbar, *args, **kw) self.canvas.pack() self.xScrollbar = Scrollbar(self, orient='horizontal', width=self.scrollbarWidth, borderwidth=1, callback=self._moveHScrollbar, background=BG_COLOR) self.yScrollbar = Scrollbar(self, orient='vertical', width=self.scrollbarWidth, borderwidth=1, callback=self._setVScrollbar, background=BG_COLOR) self.canvas.bind('<Button-1>', self._mouseClick) self.canvas.bind('<Double-1>', self._mouseDoubleClick) if isWindowsOS: self.canvas.bind('<MouseWheel>', self._windowsOsScroll) else: self.canvas.bind('<Button-4>', self._mouseUp) self.canvas.bind('<Button-5>', self._mouseDown) self.canvas.bind('<p>', self._printCanvas) self.canvas.bind('<KeyPress-Prior>', self._pageUp) self.canvas.bind('<KeyPress-Next>', self._pageDown) self.canvas.bind('<KeyPress-Up>', self._keyUp) self.canvas.bind('<KeyPress-Down>', self._keyDown) self.canvas.bind('<KeyPress-Home>', self._keyHome) self.canvas.bind('<KeyPress-End>', self._keyEnd) self.canvas.bind('<Enter>', self._enter) self.canvas.bind('<ButtonPress-3>', self._popupMenu) self.bind('<Configure>', self._changeSizeAfter)
def __init__(self, parent, # arguments below are Tkinter.Scrollbar options orient = Tkinter.HORIZONTAL, width = 15, borderwidth = 1, background = None, troughcolor = None, repeatdelay = 300, # msecs before repeat action on arrows and troughs repeatinterval = 100, # msecs between repeat action on arrows and troughs # arguments below are not Tkinter.Scrollbar options # callback is approximately same as Tkinter.Scrollbar command # option but has different (more convenient) arguments allow_resize = False, callback = None, relief='sunken', show_text = False, text_color = '#000000', text_func = None, units_scroll = 0.1, pages_scroll = 1.0, min_thickness = None, *args, **kw): assert orient in (Tkinter.HORIZONTAL, Tkinter.VERTICAL) if (show_text): assert text_func is not None self.relief = relief self.orient = orient self.callback = callback self.borderwidth = borderwidth self.repeatdelay = repeatdelay self.repeatinterval = repeatinterval self.show_text = show_text self.text_func = text_func self.units_scroll = units_scroll self.pages_scroll = pages_scroll self.min_thickness = min_thickness self.mode = 0 self.lo = 0.0 self.hi = 1.0 self.first_pass = True Frame.__init__(self, parent, *args, **kw) if (background is None): bg = parent.cget('bg') else: bg = background if (troughcolor is None): bg_trough = scaleColor(self, bg, 0.9) else: bg_trough = troughcolor # below are for shadows if relief == 'sunken': color1 = scaleColor(self, bg_trough, 0.7) color2 = scaleColor(self, bg_trough, 1.2) color3 = scaleColor(self, bg, 1.2) color4 = scaleColor(self, bg, 0.7) elif relief == 'raised': color1 = scaleColor(self, bg_trough, 1.2) color2 = scaleColor(self, bg_trough, 0.7) color3 = scaleColor(self, bg, 0.7) color4 = scaleColor(self, bg, 1.2) else: color1 = color2 = scaleColor(self, bg_trough, 0.7) color3 = color4 = scaleColor(self, bg, 1.2) self.brColor = color4 self.tlColor = color3 defaultSize = 10 # gets overriden by other widgets in container # but need to do something otherwise canvas asks for too much space kw2 = {} if (orient == Tkinter.HORIZONTAL): kw2['width'] = defaultSize kw2['height'] = width else: kw2['width'] = width kw2['height'] = defaultSize self.canvas = c = Canvas(self, bg=bg, **kw2) # grid does not seem to work because once canvas size specified # in any way it never seems to be resized c.pack(side=Tkinter.TOP, expand=Tkinter.YES, fill=Tkinter.BOTH) self.tlOuter = c.create_polygon(0, 0, 0, 0, 0, 0,0, 0,fill=color1, outline='') self.brOuter = c.create_polygon(0, 0, 0, 0, 0, 0,0, 0,fill=color2, outline='') self.bgOuter = c.create_rectangle(0, 0, 0, 0, fill=bg_trough, outline='') # self.arrowXTl,Br are for shadows of the arrows # self.arrowXFill is for triangle infill # arrow and rectangle boundaries which are colored the # same as (and so in some sense are part of) the trough # the main part of the arrow does not need its own polygon # because it is the same color as the main rectangle self.arrow1Tl = c.create_polygon(0, 0, 0, 0, 0, 0, 0, 0, fill=color3, outline='') self.arrow1Br = c.create_polygon(0, 0, 0, 0, 0, 0, 0, 0, fill=color4, outline='') self.arrow1Fill = c.create_polygon(0, 0, 0, 0, 0, 0, fill=bg, outline='') self.arrow2Tl = c.create_polygon(0, 0, 0, 0, 0, 0, 0, 0, fill=color3, outline='') self.arrow2Br = c.create_polygon(0, 0, 0, 0, 0, 0, 0, 0, fill=color4, outline='') self.arrow2Fill = c.create_polygon(0, 0, 0, 0, 0, 0, fill=bg, outline='') # slider is the bit you grab in the middle # created with two triangles for the shadowsed border # with rectangle panel in middle self.tlSlider = c.create_polygon(0, 0, 0, 0, 0, 0,fill=color3, outline='') self.brSlider = c.create_polygon(0, 0, 0, 0, 0, 0,fill=color4, outline='') self.bgSlider = c.create_rectangle(0, 0, 0, 0, fill=bg, outline='') if (show_text): self.text0 = c.create_text(0, 0, fill=text_color) self.text1 = c.create_text(0, 0, fill=text_color) if (orient == Tkinter.HORIZONTAL): c.itemconfig(self.text0, anchor=Tkinter.W) c.itemconfig(self.text1, anchor=Tkinter.E) else: c.itemconfig(self.text0, anchor=Tkinter.S) c.itemconfig(self.text1, anchor=Tkinter.N) c.bind('<Configure>', self.configure) c.bind('<Button-1>', self.buttonPressMove) c.bind('<B1-Motion>', self.buttonMotionMove) c.bind('<ButtonRelease-1>', self.buttonReleaseMove) if (allow_resize): c.bind('<Button-2>', self.buttonPressResize) c.bind('<B2-Motion>', self.resize)