Ejemplo n.º 1
0
class VertCanvas(Frame):
  
    def __init__(self, parent):
        Frame.__init__(self, parent, background="white")   
        self.parent = parent
        self.canvas = Canvas(self)         
        self.canvas.pack(fill=BOTH, expand=1)
Ejemplo n.º 2
0
 def _initUI(self):
     
     self._parent.title("Drone Flight Emulator")
     self.style = Style()
     self.style.theme_use("default")
     
     self.pack(fill=BOTH, expand=1)
     
     drawFrame = tkFrame(self)
     drawFrame.grid(column=0, row=0, sticky="W")
     
     self._canvasYZ = Canvas(drawFrame, bg="white", height=200, width=200)
     self._canvasYZ.grid(column=0, row=0, sticky="W", padx=(2,0), pady=(2,0))
     
     self._canvasXZ = Canvas(drawFrame, bg="white", height=200, width=200)
     self._canvasXZ.grid(column=1, row=0, sticky="E", padx=(2,2), pady=(2,0))
     
     self._canvasXY = Canvas(drawFrame, bg="white", height=200, width=400)
     self._canvasXY.grid(column=0, row=1, columnspan=2, sticky="S", padx=(2,2), pady=(0,2))
     self._linesXY = [self._canvasXY.create_line(200,100, 200, 90, fill="#ff0000"), \
                      self._canvasXY.create_line(200,100, 210, 100, fill="#0000ff"), \
                      self._canvasXY.create_line(200,100, 200, 110, fill="#0000ff"), \
                      self._canvasXY.create_line(200,100, 190, 100, fill="#0000ff")]
     
     self._linesYZ = [self._canvasYZ.create_line(100,200, 90, 200, fill="#0000ff"), \
                      self._canvasYZ.create_line(100,200, 110, 200, fill="#0000ff")]
     
     self._linesXZ = [self._canvasXZ.create_line(100,200, 90, 200, fill="#0000ff"), \
                      self._canvasXZ.create_line(100,200, 110, 200, fill="#0000ff")]
class CanvasFrame(Frame):
    
    def __initialize_canvas(self):
        self.__canvas = Canvas(self.master,
                            width=Constants.DEFAULT_FRAME_WIDTH() + 120,
                            height=Constants.DEFAULT_FRAME_HEIGHT())
        self.__canvas.pack()
        self.pack()
        
    def __setup_timer(self):
        RefreshTimer(self.master, 10, self)
        MonsterTimer(self.master, 1000)
        
    def __setup_handlers(self):
        ArrowHandler(self.master)
        KeyMovementHandler(self.master)
        MouseClickHandler(self.master)
        
    def refresh(self):
        self.__canvas.delete('all')
        BoardPrinter.print_board(self.__canvas)
        SelectPrinter.print_selected(self.__canvas)
        TurnMenuPrinter.print_turn_menu(self.__canvas)
        
    def __init__(self):
        Frame.__init__(self, Tk())
        self.pack()
        
        self.__initialize_canvas()
        self.__setup_timer()
        self.__setup_handlers()
Ejemplo n.º 4
0
 def __init__(self, parent):
     Canvas.__init__(self, width=WIDTH, height=HEIGHT, 
         background="black", highlightthickness=0)
      
     self.parent = parent 
     self.initGame()
     self.pack()
Ejemplo n.º 5
0
    def _setupDisplay(self, root, config):
        """Set screen size and add background image
        
        root -- the Tk instance of the application
        config -- ConfigParser containing application settings

        """
        fullscreen = config.getboolean(ini.general, ini.fullscreen)
        bgimage = ini.getPath(config.get(ini.general, ini.bgimage))
        
        image = Image.open(bgimage)
        backgroundIm = ImageTk.PhotoImage(image)        
        
        if(fullscreen):
            screenwidth = root.winfo_screenwidth()
            screenheight = root.winfo_screenheight()
            (w, h) = image.size
            self._scalefactor = (screenwidth / float(w), screenheight / float(h))
            image = image.resize((screenwidth, screenheight))
        else:
            (screenwidth, screenheight) = image.size
            self._scalefactor = (1, 1)
            
        geom = "{}x{}+{}+{}".format(screenwidth, screenheight, 0, 0)
        root.geometry(geom)
        root.overrideredirect(1)
        
        background = Canvas(root, width = screenwidth, height = screenheight)
        self._canvas = background
        background.pack()
        backgroundIm = ImageTk.PhotoImage(image)
        self._backgroundIm = backgroundIm
        background.create_image(0,0, image = backgroundIm, anchor = NW)
Ejemplo n.º 6
0
def main():
    master = Tk()
    w = Canvas(master, width=WIDTH, height=HEIGHT)
    w.pack()

    img = PhotoImage(width=WIDTH, height=HEIGHT, master=master)
    w.create_image((WIDTH/2, HEIGHT/2), image=img, state="normal")

    cam = Camera()
    cam.look_at(np.array([0, 10, -8]),
                np.array([0, 0, 3.0]),
                np.array([0, 1.0, 0]))

    init_world(world_objects)
    init_light(light_objects)
    # Generate rays for each pixel and determine color
    progress_interval = HEIGHT*WIDTH / 10
    progress_tick = 0
    print 'Progress (10 ticks): [ -',
    sys.stdout.flush()
    for y in xrange(HEIGHT):
        for x in xrange(WIDTH):
            progress_tick += 1
            if progress_tick > progress_interval:
                progress_tick = 0
                print ' -',
                sys.stdout.flush()
            ray = compute_camera_ray(WIDTH, HEIGHT, cam, 3, x, y)
            color = trace_ray(world_objects, light_objects, ray)
            # TKinter requires a hex string as color input for photo image
            img.put('#%02X%02X%02X' % tuple(color), (x, y))
    print ' ]'
    mainloop()
Ejemplo n.º 7
0
    def __init__(self, master=None, fps=20, *args, **kw):
        Canvas.__init__(self, master, *args, **kw)

        self.frame = Frame3D()
        self.items = {}

        self.w = float(self['width'])
        self.h = float(self['height'])

        self.axes_on = True
        self._xy_axes()

        self.bind('<Configure>', self.resize_callback)

        self.fps_ms = 1000 / fps # Frames per second in milliseconds.

        self.focal_distance = 2.2
        self.x_arc_of_view = 73.0
        self.y_arc_of_view = 73.0

        self.f = G(self.w, self.x_arc_of_view)
        self.u = G(self.h, self.y_arc_of_view)

        self._frustum = Frustum(
            self.w,
            self.h,
            self.x_arc_of_view,
            self.y_arc_of_view,
            self.focal_distance,
            )
Ejemplo n.º 8
0
    def initUI(self):
        self.parent.title("Layout Test")
        self.config(bg = '#F0F0F0')
        self.pack(fill = BOTH, expand = 1)

        #create canvas
        canvas1 = Canvas(self, 
                         relief = FLAT,
                         background = "#D2D2D2",
                         width = 180, 
                         height = 500)

        canvas1.pack(side = TOP,
                     anchor = NW, 
                     padx = 10, 
                     pady = 10)

        #add quit button
        button1 = Button(canvas1,
                         text = "Quit",
                         command = self.quit,
                         anchor = W)
        button1.configure(width = 10, 
                          activebackground = "#ee0000",
                          relief = FLAT)
        button1.pack(side = TOP)

        button2 = Button(canvas1,
                         text = "Start",
                         command = self.print_out,
                         anchor = W)
        button2.configure(width = 10, 
                          activebackground = "#00ee00",
                          relief = FLAT)
        button2.pack(side = TOP)
Ejemplo n.º 9
0
def main():


        cWidth = 1280
        cHeight = 800

        #leap-sets up the leap stuff
        leapControl = Leap.Controller()
        leapControl.set_policy_flags(Leap.Controller.POLICY_BACKGROUND_FRAMES)
        theListener = TouchPointListener()
        leapControl.add_listener(theListener)

        #tkinter-create base widget for Tkinter
        master = Tk()
        master.title( "Touch Points" )
        #tkinter-add a canvas widget to the base widget, For a description of tkinter canvas api see:
        #http://effbot.org/tkinterbook/canvas.htm
        paintCanvas = Canvas(width = cWidth, height = cHeight )
        paintCanvas.pack()

        #leap-adds the canvas to the Listener object
        theListener.set_canvas(paintCanvas)

        #tkinterstarts the Tkinter main loop and destroys it when the window is closed
        #note theres weirdness here that I didn't care about becuase it's going away eventually
        master.mainloop()
        master.destroy()
    def __init__(self, parent, *args, **kw):
        Frame.__init__(self, parent, *args, **kw)
        vscrollbar = Scrollbar(self, orient=VERTICAL)
        vscrollbar.pack(fill=Y, side=RIGHT, expand=FALSE)
        canvas = Canvas(
            self, bd=0, highlightthickness=0, yscrollcommand=vscrollbar.set)
        canvas.pack(side=LEFT, fill=BOTH, expand=TRUE)
        vscrollbar.config(command=canvas.yview)
        canvas.xview_moveto(0)
        canvas.yview_moveto(0)
        self.interior = interior = Frame(canvas)
        interior_id = canvas.create_window(0, 0, window=interior, anchor=NW)
        self.canv = canvas  # @UndefinedVariable
        self.scroller = vscrollbar

        def _configure_interior(event):
            size = (interior.winfo_reqwidth(), interior.winfo_reqheight())
            canvas.config(scrollregion="0 0 %s %s" % size)
            if interior.winfo_reqwidth() != canvas.winfo_width():
                canvas.config(width=interior.winfo_reqwidth())
        interior.bind('<Configure>', _configure_interior)

        def _configure_canvas(event):
            if interior.winfo_reqwidth() != canvas.winfo_width():
                canvas.itemconfigure(interior_id, width=canvas.winfo_width())
        canvas.bind('<Configure>', _configure_canvas)
Ejemplo n.º 11
0
def success(cur_dir):
    """
    Displays a "successful submission" picture
    """
    root = Tk()
    root.focus_set()
    # Get the size of the screen and place the splash screen in the center
    img = Image.open(str(cur_dir) + '/Images/Success.gif')
    width = img.size[0]
    height = img.size[1]
    flog = (root.winfo_screenwidth()/2-width/2)
    blog = (root.winfo_screenheight()/2-height/2)
    root.overrideredirect(1)
    root.geometry('%dx%d+%d+%d' % (width, height, flog, blog))
    # Pack a canvas into the top level window.
    # This will be used to place the image
    success_canvas = Canvas(root)
    success_canvas.pack(fill = "both", expand = True)
    # Open the image
    imgtk = PhotoImage(img)
    # Get the top level window size
    # Need a call to update first, or else size is wrong
    root.update()
    cwidth = root.winfo_width()
    cheight =  root.winfo_height()
    # create the image on the canvas
    success_canvas.create_image(cwidth/2, cheight/2, image = imgtk)
    root.after(4000, root.destroy)
    root.mainloop()
Ejemplo n.º 12
0
def expired(cur_dir, amount):
    """
    Displays a "deadline expired" picture
    """
    root = Tk()
    root.focus_set()
    # Get the size of the screen and place the splash screen in the center
    img = Image.open(str(cur_dir) + '/Images/Expired.gif')
    width = img.size[0]
    height = img.size[1]
    flog = root.winfo_screenwidth()/2-width/2
    blog = root.winfo_screenheight()/2-height/2
    root.overrideredirect(True)
    root.geometry('%dx%d+%d+%d' % (width*1, height + 44, flog, blog))
    # Pack a canvas into the top level window.
    # This will be used to place the image
    expired_canvas = Canvas(root)
    expired_canvas.pack(fill="both", expand=True)
    # Open the image
    imgtk = PhotoImage(img)
    # Get the top level window size
    # Need a call to update first, or else size is wrong
    root.update()
    cwidth = root.winfo_width()
    cheight =  root.winfo_height()
    # create the image on the canvas
    expired_canvas.create_image(cwidth/2, cheight/2.1, image=imgtk)
    Button(root, text='Deadline Expired by ' + str(amount
          ) + '. Assignment Submitted, time '\
          'noted', width=80, height=2, command=root.destroy).pack()
    root.after(5000, root.destroy)
    root.mainloop()
Ejemplo n.º 13
0
    def __init__(self, window,color, value, maxVal, name, gaugeScale, lineColor, bgColor, textFont):
        Canvas.__init__(self, window, bg=bgColor, height=100, width=100)
        xval = 20
        yval = 10
        self.maxVal = maxVal
        self.value = value

        self.gaugeValue = self.maxVal / float(value)  # calculate the GaugeValue

        self.hand = self.create_arc(xval, yval, (xval + 100 * gaugeScale),
                                      (yval + 100 * gaugeScale), start=0,
                                      extent=-(220 / self.gaugeValue), fill=color)  # Draw hand

        self.outline = self.create_arc(xval - 3, yval - 3, (xval + 100 * gaugeScale + 3),
                                         (yval + 100 * gaugeScale + 3), start=0, extent=-220, style="arc",
                                         outline=lineColor, width=2)  # draw outline

        self.valueBox = self.create_rectangle((xval + 50 * gaugeScale), yval + 20 * gaugeScale,
                                                xval + 100 * gaugeScale + 3, yval + 50 * gaugeScale,
                                                outline=lineColor,
                                                width=2)  # draw Value Box

        self.value1 = self.create_text(xval + 54 * gaugeScale, yval + 22 * gaugeScale, anchor="nw",
                                         text=self.value,
                                         fill=lineColor, font=(textFont, int(round(15 * gaugeScale))))

        self.value2 = self.create_text(xval-10, yval - 8, anchor="nw", text=name, fill=lineColor,
                                         font=(textFont, int(round(19 * gaugeScale))))
Ejemplo n.º 14
0
    def __init__(self, master, width, data_callback):
        """Construct a Meter.

        :param master
        :param width
        :param data_callback: function to retrieve meter data
        :param end_callback: function to call upon completion
        """
        Canvas.__init__(self, master, bg=COLOR_METER_BG, borderwidth=2, relief=Tkinter.GROOVE, width=width, height=METER_HEIGHT)

        self._data_callback = data_callback

        self._width = (int)(self.cget("width"))
        self._x0 = 0
        self._y0 = METER_HEIGHT - 25
        self._x1 = self._width + 5
        self._y1 = METER_HEIGHT

        self.create_text(10, 60, anchor=Tkinter.W, font=FONT_SMALL, text=TEXT_POSITION, fill=COLOR_METER_TEXT)
        self.create_text(140, 60, anchor=Tkinter.W, font=FONT_SMALL, text=TEXT_LENGTH, fill=COLOR_METER_TEXT)
        self.create_text(270, 60, anchor=Tkinter.W, font=FONT_SMALL, text=TEXT_CUE, fill=COLOR_METER_TEXT)

        self._position = self.create_text(10, 85, anchor=Tkinter.W, font=FONT_NUM, fill=COLOR_METER_TEXT)
        self._length = self.create_text(140, 85, anchor=Tkinter.W, font=FONT_NUM, fill=COLOR_METER_TEXT)
        self._cue = self.create_text(270, 85, anchor=Tkinter.W, font=FONT_NUM, fill=COLOR_METER_TEXT)
        self._title = self.create_text(10, 20, anchor=Tkinter.W, font=FONT_HEAD, fill=COLOR_METER_TEXT)
        self._artist = self.create_text(self._width, 20, anchor=Tkinter.E, font=FONT_HEAD, fill=COLOR_METER_TEXT)

        self._bar_bg = self.create_rectangle(self._x0, self._y0, self._x1, self._y1, fill=COLOR_BAR_BG)
        self._bar_fg = self.create_rectangle(self._x0, self._y0, self._x0, self._y1, fill=COLOR_BAR_FG)

        self.reset()
Ejemplo n.º 15
0
class GUI:
    def __init__(self, title, width, height):
        from Tkinter import Tk, Canvas, Toplevel
        self.width = width
        self.height = height
        self.title = title
        self.app = Tk()
        self.app.withdraw()
        self.win = Toplevel()
        self.win.wm_title(title)
        self.canvas = Canvas(self.win,
                             width=(self.width * 2),
                             height=(self.height * 2))
        self.canvas.pack(side = 'bottom', expand = "yes", anchor = "n",
                         fill = 'both')
        self.win.winfo_toplevel().protocol('WM_DELETE_WINDOW',self.close)
        #self.canvas.bind("<Configure>", self.changeSize)
        
    def close(self):
        self.app.destroy()

    def draw(self, lat, length):
        print "Drawing...",
        for h in range(length):
            for w in range(self.width):
                if lat.data[h][w]:
                    self.canvas.create_rectangle(w*2, h*2, w*2+2, h*2+2,
                                                 fill = "black")
            self.win.update_idletasks()
        print "Done!"
Ejemplo n.º 16
0
    def initUI(self):
        self.parent.title("Crazyflie Client")

        Label(self, text="Pitch").place(x=5, y=5)
        self.label_pitch = Label(self, text="0.00")
        self.label_pitch.place(x=60, y=5)
        
        Label(self, text="Roll").place(x=5, y=25)
        self.label_roll = Label(self, text="0.00")
        self.label_roll.place(x=60, y=25)
        
        Label(self, text="Yaw").place(x=5, y=50)
        self.label_yaw = Label(self, text="0.00")
        self.label_yaw.place(x=60, y=50)
        
        Label(self, text="Throttle").place(x=5, y=70)
        self.label_thrust = Label(self, text="0.00")
        self.label_thrust.place(x=60, y=70)
        
        self.canvas1 = Canvas(self, bg="#ddd", width=150, height=150)
        self.canvas1.place(x=395, y=25)
        
        self.canvas2 = Canvas(self, bg="#eee", width=340, height=280)
        self.canvas2.place(x=300, y=200)
        
        self.pack(fill=BOTH, expand=1)
class SimpleGrid(Frame):
	
	def __init__(self, parent, props):
		Frame.__init__(self,parent)
		
		self.parent = parent
		self.iWidth = props['width']
		self.iHeight = props['height']
		self.nCols = props['cols']
		self.nRows = props['rows']
		self.gWidthPercent = 0.90
		self.gHeightPercent = 0.90

		self.gridSqWidth = 0
		self.gridSqHeight = 0
		self.gridX = 0
		self.gridY = 0
		
		self.initGrid()
		
	def initGrid(self):
		self.parent.title("SimpleGrid")
		self.pack(fill=BOTH, expand=1)
		self.buildCanvas()
		self.calculateDimensions()
		self.enableEvents()
		
	def calculateDimensions(self):
	
		# calculate the size of the grid squares
		self.gridSqWidth = (self.gWidthPercent * self.iWidth) / self.nCols
		self.gridSqHeight = (self.gHeightPercent * self.iHeight) / self.nRows
	
		# calculate the upper left corner
		self.gridX = (1.0 - self.gWidthPercent) * self.iWidth / 2.0
		self.gridY = (1.0 - self.gHeightPercent) * self.iHeight / 2.0
		
	def buildCanvas(self):
		self.canvas = Canvas(self)
		
	def draw(self):		
		
		for i in range(0,self.nRows):
			for j in range(0,self.nCols):
				self.drawSquare(i,j)
		
		self.canvas.pack(fill=BOTH, expand=1)
		
	def drawSquare(self,row,col):
		sqX = self.gridX + (self.gridSqWidth*col)
		sqY = self.gridY + (self.gridSqHeight*row)
		self.canvas.create_rectangle(sqX, sqY,
									 sqX + self.gridSqWidth,
									 sqY + self.gridSqHeight,
									 outline="black")
		
		
	def enableEvents(self):
		# do nothing -- let child classes do this
		return
class MapRenderer:
    def __init__(self, config=config, **kwargs):
        self.config = config
        self.__dict__.update(kwargs)
        self.map = Map(**kwargs)

    @property
    def canvas_width(self):
        return self.map.width * self.map.block_width

    @property
    def canvas_height(self):
        return self.map.height * self.map.block_height

    def init_canvas(self, parent=None):
        if parent == None:
            parent = self.parent
        if hasattr(self, 'canvas'):
            pass
        else:
            self.canvas = Canvas(parent)
        self.canvas.xview_moveto(0)
        self.canvas.yview_moveto(0)

    def kill_canvas(self):
        if hasattr(self, 'canvas'):
            self.canvas.destroy()

    def draw(self):
        self.canvas.configure(width=self.canvas_width, height=self.canvas_height)
        for i in xrange(len(self.map.blockdata)):
            block_x = i % self.map.width
            block_y = i / self.map.width
            self.draw_block(block_x, block_y)

    def draw_block(self, block_x, block_y):
        # the canvas starts at 4, 4 for some reason
        # probably something to do with a border
        index, indey = 4, 4

        # Draw one block (4x4 tiles)
        block = self.map.blockdata[block_y * self.map.width + block_x]

        # Ignore nonexistent blocks.
        if block >= len(self.map.tileset.blocks): return

        for j, tile in enumerate(self.map.tileset.blocks[block]):
            try:
                # Tile gfx are split in half to make vram mapping easier
                if tile >= 0x80:
                    tile -= 0x20
                tile_x = block_x * self.map.block_width + (j % 4) * 8
                tile_y = block_y * self.map.block_height + (j / 4) * 8
                self.canvas.create_image(index + tile_x, indey + tile_y, image=self.map.tileset.tiles[tile])
            except:
                pass

    def crop(self, *args, **kwargs):
        self.map.crop(*args, **kwargs)
        self.draw()
Ejemplo n.º 19
0
class Visualizer(object):

    def __init__(self, toplevel, **kwargs):
        self.toplevel = toplevel
        self.canvas = Canvas(
            self.toplevel, width=600, height=400, background='black'
        )
        self.canvas.pack()
        self._playing_lines = {}

    def add_point(self, phrase, point, color):
        if point in self._playing_lines:
            self.remove_point(phrase, point)
        if point.type == 'Rest':
            return
        if point not in phrase.points:
            return
        px,py, px2,py2 = phrase.get_line(point)
        self._playing_lines[point] = self.canvas.create_line(
            px,py, px2,py2, fill=color
        )

    def remove_point(self, phrase, point):
        if point not in self._playing_lines:
            return
        self.canvas.delete(self._playing_lines[point])
        del self._playing_lines[point]
Ejemplo n.º 20
0
    def __scrubber(self, master):
        sc = Canvas(
            master,
            width=800, height=SCRUBBER_HEIGHT,
            background="white",
        )

        def sc_goto(e):
            width_fraction = float(e.x) / sc.winfo_width()
            ev_s = self.get_earliest_bookmark_after(0)
            ev_e = self.get_latest_bookmark_before(sys.maxint)
            ev_l = ev_e - ev_s
            self.render_start.set(ev_s + ev_l * width_fraction - float(self.render_len.get()) / 2)
            if not self.render_auto.get():
                self.update()
            self.canvas.xview_moveto(0.5)
        sc.bind("<1>", sc_goto)

        def resize(event):
            if self.c:
                self.render_scrubber_activity()
                self.render_scrubber_arrow()
            # sc.coords(line, 0, 0, event.width, event.height)
        sc.bind("<Configure>", resize)

        return sc
Ejemplo n.º 21
0
    def __init__(self, parent, *args, **kw):
        Frame.__init__(self, parent, *args, **kw)
        # create a canvas object and a vertical scrollbar for scrolling it
        vscrollbar = Scrollbar(self, orient=VERTICAL)
        vscrollbar.pack(fill=Y, side=RIGHT, expand=FALSE)
        canvas = Canvas(self, bd=0, highlightthickness=0,
                        yscrollcommand=vscrollbar.set)
        canvas.pack(side=LEFT, fill=BOTH, expand=TRUE)
        vscrollbar.config(command=canvas.yview)

        # reset the view
        canvas.xview_moveto(0)
        canvas.yview_moveto(0)

        # create a frame inside the canvas which will be scrolled with it
        self.interior = interior = Frame(canvas)
        interior_id = canvas.create_window(0, 0, window=interior,
                                           anchor=NW)

        # track changes to the canvas and frame width and sync them,
        # also updating the scrollbar
        def _configure_interior(event=None):
            # update the scrollbars to match the size of the inner frame
            size = (interior.winfo_reqwidth(), interior.winfo_reqheight())
            canvas.config(scrollregion="0 0 %s %s" % size)
            if interior.winfo_reqwidth() != canvas.winfo_width():
                # update the canvas's width to fit the inner frame
                canvas.config(width=interior.winfo_reqwidth())
        interior.bind('<Configure>', _configure_interior)

        def _configure_canvas(event=None):
            if interior.winfo_reqwidth() != canvas.winfo_width():
                # update the inner frame's width to fill the canvas
                canvas.itemconfigure(interior_id, width=canvas.winfo_width())
        canvas.bind('<Configure>', _configure_canvas)
Ejemplo n.º 22
0
    def __init__(self, root, width, height, app):
        self.holiday_manager = app.holiday_manager
        self.root = root
        today = datetime.date.today()

        self.month = today.month
        self.year = today.year

        self.month_label = Label(root, text=self.months[today.month] + " " + str(today.year))
        self.month_label.grid(row=1)

        win = Canvas(root, width=width, height=height)
        win.grid(ipadx=10, ipady=10)  # Places canvas on screen

        self.canvas = win

        self.calendar = calendar.Calendar()

        self.rows = 6
        self.columns = 7

        self.box_width = width / self.columns
        self.box_height = height / self.rows

        self.boxes = self.__generate_boxes(self.rows * self.columns)

        self.__draw_weekday_names()
        self.draw_month(today.month, today.year)
Ejemplo n.º 23
0
 def show(self):
     root = Tk()
     canvas = Canvas(root, width=self.layout.width, height=self.layout.height)
     self.layout.layout()
     self.draw_page_sets(canvas, self.layout.page_set)
     canvas.pack()
     root.mainloop()
Ejemplo n.º 24
0
    def initUI(self):
        # Setting title as wordle      
        self.parent.title("Wordle")        
        self.pack(fill=BOTH, expand=1)
        #print "Inside Canvas", self.arg
        # Task 5 - Pad outside border by 50 pixels all around
        # Canvas with 50 pixels outside border
        canvas = Canvas(self, bd=50, bg = "white")
        # Two helper variables
        # for generating start position of a word

        # Task 6 - Random color for each word
        # Generating Random colors for each of the word
        for word, value in self.arg.items():
            # Task 7 - Font size based on frequency of the words
            # Generating font size based on the frequency of the words!
            # Very simple logic
            # Could make it more complex but didn't do that!
            if value > 15:
                i = random.randrange(150,400, 70)
                j = random.randrange(150,600, 50)
            else:    
                i = random.randrange(200,600, 27)
                j = random.randrange(100,600, 33)

            canvas.create_text(i, j, anchor=W, font=("times",(value*2)),
                text=word, fill=choice(COLORS))
        canvas.pack(fill=BOTH, expand=1)
class TronCanvas(object):
    """
    Tron canvas class, contains the fields related to drawing the game. Canvas
    is used to draw the Players on the screen. The drawing is done by Tk.

    Attributes:

    - Root -- The root Tk instance
    - Canvas -- The TkCanvas
    - Bike width -- Width of the bike in pixels
    - Rows -- Number of cells in each row of the board.
      The Bike width x Rows + 2 x MARGIN gives the size in pixels of the
      canvas.

    MARGIN
      The margin of the canvas

    DELAY
      Delay time between redrawing the canvas

    GUI_DISPLAY_AFTER_COLLISION
      Time in seconds GUI is displayed after a collision. Default is 2 seconds
    """

    # Margin of canvas in pixels
    MARGIN = 5
    # Delay between updates in milliseconds
    DELAY = 150
    # Time GUI is displayed after a collision
    GUI_DISPLAY_AFTER_COLLISION = 2

    def __init__(self, rows, bike_width):
        """
        Constructor

        :param rows: number of rows on the grid
        :type rows: int
        :param bike_width: width of bike when drawing
        :type bike_width: int
        """
        # Create Tk instance
        self.root = Tk()
        # Set window to be resizable
        self.root.resizable(width=0, height=0)
        # Canvas to draw on
        canvas_width = 2 * TronCanvas.MARGIN + rows * bike_width
        canvas_height = canvas_width
        # Create a Tk Canvas instance
        self.tk_canvas = Canvas(self.root, width=canvas_width,
                                height=canvas_height)
        # Geometry manager organizes widgets in blocks before placing
        # them in the parent widget
        self.tk_canvas.pack()
        # Set bike width
        self.bike_width = bike_width
        # Set bike height
        self.bike_height = bike_width
        # Set number of rows
        self.rows = rows
Ejemplo n.º 26
0
    def __init__(self, parent, graph):
        Canvas.__init__(self, parent, width=graph.width, height=graph.height)

        for e in graph.edges:
            self.create_line(*[i for j in e for i in graph.vertex[j]])

        self.vertex = {k: self.createCircle(v[0], v[1], 6, fill="black") for k, v in graph.vertex.items()}
        self.pack()
Ejemplo n.º 27
0
    def initUI(self):
        self.parent.title("Skyline")

        canvas = Canvas(self)
        self.buildcity(canvas,150)

        canvas.pack(fill=BOTH, expand=1)
        self.pack(fill=BOTH, expand=1)
Ejemplo n.º 28
0
    def __init__(self, filename, parentnotebook):
        """Create a new EditTab
        
        Argument
        filename -- name and path to the file being edited
        parentnotebook -- the NoteBook in which this tab will be added
        
        """
        Frame.__init__(self)
        self._filename = filename
        self._parentnotebook = parentnotebook
        self._inputs = []
        self.path = os.path.dirname(filename)
        self._dirty = False
        parentnotebook.add(self, state = 'normal')
        self._setLabel()

        #Set up GUI
        self.rowconfigure(0, weight = 1)        
        self.columnconfigure(0, weight = 1)
        
        vscroll = Scrollbar(self, orient = VERTICAL)
        self._vscroll = vscroll
        vscroll.grid(row=0, column=1, sticky=N+S)
        hscroll = Scrollbar(self, orient = HORIZONTAL)
        self._hscroll = hscroll
        hscroll.grid(row=1, column=0, sticky=E+W)

        canvas = Canvas(self, yscrollcommand = vscroll.set, xscrollcommand = hscroll.set)
        self._canvas = canvas
        canvas.grid(row = 0, column = 0, padx = 5, pady = 5, sticky = NSEW)

        vscroll['command'] = canvas.yview
        hscroll['command'] = canvas.xview

        scrollframe = Frame(canvas)
        self._scrollframe = scrollframe
        canvas.create_window(0, 0, window = scrollframe, anchor = N + W)

        scrollframe.rowconfigure(0, weight = 1)        
        scrollframe.columnconfigure(0, weight = 1)
                
        self._mainframe = Frame(scrollframe)
        self._mainframe.grid(row = 0, column = 0, padx = 5, pady = 5, sticky = NSEW)
        
        cf = Frame(scrollframe)
        self._control_frame = cf
        cf.grid(row = 1, column = 0, padx = 5, pady = 5, sticky = E)
        b = Button(cf, text = lang[lng.txtCopyImages], command = self._ehCopyImages)
        self._btnCopy = b
        b.grid(row = 0, column = 0, padx = 5, pady = 5)
        b = Button(cf, text = lang[lng.txtSave], command = self._ehSave, state = DISABLED)
        self._btnSave = b
        b.grid(row = 0, column = 1, padx = 5, pady = 5)
        b = Button(cf, text = lang[lng.txtClose], command = self._ehClose)
        b.grid(row = 0, column = 2, padx = 5, pady = 5)

        parentnotebook.after_idle(self._setCanvas)
Ejemplo n.º 29
0
 def __init__(self, parent, height=30, width=150, increments=15):
     self.increments = increments
     self.height = height
     self.increment_width = width/increments-2
     self.current_increment = 0
     Canvas.__init__(self, parent, height=height, width=width, bd=0)
     self.create_rectangle(1, 1, width-1, height-1, fill="")
     self.xview_moveto(0)
     self.yview_moveto(0)
Ejemplo n.º 30
0
    def __initUI(self):
        self.parent.title("Simple Sudoku")
        self.pack(fill=BOTH, expand=1)
        self.canvas = Canvas(self, width=WIDTH, height=HEIGHT)
        self.canvas.pack(fill=BOTH, side=TOP)
        clear_button = Button(self,
                              text="Clear Answers",
                              command=self.__clear_answers)
        clear_button.pack(fill=BOTH, side=BOTTOM)

        self.__draw_grid()
        self.__draw_puzzle()

        self.canvas.bind("<Button-1>", self.__cell_clicked)
        self.canvas.bind("<Key>", self.__key_pressed)
Ejemplo n.º 31
0
    def initUI(self):
        #create initial Beings object (not instantiated until live is called)
        self.wc = WorldConfiguration()

        self.style = Style()
        self.style.theme_use("default")
        self.pack(fill=BOTH, expand=1)

        self.columnconfigure(2, weight=1)
        self.columnconfigure(4, pad=7)
        self.rowconfigure(3, weight=1)

        lbl = Label(self, text="PyLife")
        lbl.grid(sticky=W, padx=25, pady=5)

        self.world = Canvas(self, background="#7474DB")
        self.world.grid(row=1,
                        column=0,
                        columnspan=3,
                        rowspan=8,
                        padx=5,
                        sticky=E + W + N + S)

        self.sbtn = Button(self, text="Stop")
        self.sbtn.grid(row=1, column=4, pady=5, sticky=E)

        self.bbox = Text(self, height=20, width=36)
        self.bbox.grid(row=3, column=4, padx=5, sticky=E + W + N + S)

        self.bbox1 = Text(self, height=11, width=36)
        self.bbox1.grid(row=4, column=4, padx=5, sticky=E + W + N + S)

        self.cbtn = Button(self, text="Close", command=self.parent.destroy)
        self.cbtn.grid(row=9, column=4, pady=5)

        self.cnfbtn = Button(self, text="Configure Universe")
        self.cnfbtn.grid(row=9, column=0, padx=5)

        self.timelbl = Text(self, height=1, width=10)
        self.timelbl.grid(row=2, column=4, pady=5)

        b = Beings(self)
        abtn = Button(
            self, text="Start", command=b.live
        )  #Beings(cnfbtn, world, 4, 10, sbtn, bbox, bbox1, timelbl).live)
        abtn.grid(row=1, column=4, pady=5, sticky=W)

        self.cnfbtn.config(command=b.configure)
Ejemplo n.º 32
0
 def __draw(s):  #Rysuje kontrolke
     s.__C = Canvas(s.__master,
                    highlightthickness=0,
                    bg="gray70",
                    height=100)
     s.__C.pack(side="top", expand=0, fill="x")
     s.__tag = s.__C.create_text(50, 30, anchor="nw", width=500, text="")
Ejemplo n.º 33
0
class PaintBox(Frame):
    def __init__(self):
        Frame.__init__(self)
        self.leap = Leap.Controller()
        self.painter = SignatureListener()
        self.leap.add_listener(self.painter)
        self.pack(expand=YES, fill=BOTH)
        self.master.title("Leap Signature")
        self.master.geometry("800x600")

        # create Canvas component
        self.paintCanvas = Canvas(self, width="800", height="600")
        self.paintCanvas.pack()
        self.painter.set_canvas(self.paintCanvas)

        self.painter.state = 0
Ejemplo n.º 34
0
 def __init__(self, parent):
     Frame.__init__(self, master=parent)
     parent.title('Liar\'s Dice')
     self.canvas = Canvas(self, width=550, height=500)
     self.canvas.pack(fill='both', expand=True)
     self.canvas.place(x=0, y=0)
     self.bid_logs = ScrolledText(self, undo=True, width=100, height=100)
     self.bid_logs.pack(fill='both', expand=True)
     self.bid_logs['font'] = ('consolas', '12')
     self.bid_logs.place(x=350, y=0)
     self.input_box = Text(self, undo=True, width=100, height=100)
     self.input_box.pack(fill='both', expand=True)
     self.input_box['font'] = ('consolas', '12')
     self.input_box.place(x=350, y=450)
     self.pack(fill='both', expand=True)
     self.insert_to_log()
Ejemplo n.º 35
0
    def display_plots(self):
        """
        CFProjectionPanel requires a 2D grid of plots.
        """
        plots = self.plotgroup.plots
        # Generate the zoomed images.
        self.zoomed_images = [
            ImageTk.PhotoImage(p.bitmap.image) for p in plots
        ]
        old_canvases = self.canvases

        self.canvases = [
            Canvas(self.plot_container,
                   width=image.width(),
                   height=image.height(),
                   borderwidth=1,
                   highlightthickness=0,
                   relief='groove') for image in self.zoomed_images
        ]

        # Lay out images
        for i, image, canvas in zip(range(len(self.zoomed_images)),
                                    self.zoomed_images, self.canvases):
            canvas.grid(row=i // self.plotgroup.proj_plotting_shape[1],
                        column=i % self.plotgroup.proj_plotting_shape[1],
                        padx=UNIT_PADDING,
                        pady=UNIT_PADDING)
            canvas.create_image(1, 1, anchor='nw', image=image)

        # Delete old ones.  This may resize the grid.
        for c in old_canvases:
            c.grid_forget()

        self._add_canvas_bindings()
Ejemplo n.º 36
0
    def __init__(self, root):
        # create bar graph
        self._canvas = Canvas(root,
                              width=CANVAS_WIDTH,
                              height=CANVAS_HEIGHT,
                              bg='black')
        self._canvas.pack()

        self._bars = []
        for pos in range(0, CANVAS_WIDTH, BAR_WIDTH):
            r = self._canvas.create_rectangle(pos,
                                              CANVAS_HEIGHT,
                                              pos + BAR_WIDTH,
                                              100,
                                              fill='white')
            self._bars.append(r)
Ejemplo n.º 37
0
    def __init__(self, *args, **kwargs):
        self._width = 264
        self._height = 176
        self._panel = 'EPD 2.7'
        self._cog = 0
        self._film = 0
        self._auto = False

        self._version = '4'

        if ('auto' in kwargs) and kwargs['auto']:
            self._auto = True

        self.root = Tk()
        self.canvas = Canvas(self.root, width=self._width, height=self._height)
        self.canvas.pack()
Ejemplo n.º 38
0
    def __initUI(self):
        """
        Initialises the Sudoku board
        """
        self.pack(fill=BOTH)
        self.canvas = Canvas(self,
                             width=WIDTH,
                             height=HEIGHT,
                             highlightthickness=0)
        self.canvas.pack(fill=BOTH, side=TOP)

        self.__draw_grid()
        self.draw_puzzle()

        self.canvas.bind("<Button-1>", self.__cell_clicked)
        self.canvas.bind("<Key>", self.__key_pressed)
Ejemplo n.º 39
0
 def __init__(self, master, title, dict=None):
     width = 0
     height = 40
     if dict:
         height = 20 * len(
             dict)  # XXX 20 == observed height of Entry widget
     self.master = master
     self.title = title
     import repr
     self.repr = repr.Repr()
     self.repr.maxstring = 60
     self.repr.maxother = 60
     self.frame = frame = Frame(master)
     self.frame.pack(expand=1, fill="both")
     self.label = Label(frame, text=title, borderwidth=2, relief="groove")
     self.label.pack(fill="x")
     self.vbar = vbar = Scrollbar(frame, name="vbar")
     vbar.pack(side="right", fill="y")
     self.canvas = canvas = Canvas(frame,
                                   height=min(300, max(40, height)),
                                   scrollregion=(0, 0, width, height))
     canvas.pack(side="left", fill="both", expand=1)
     vbar["command"] = canvas.yview
     canvas["yscrollcommand"] = vbar.set
     self.subframe = subframe = Frame(canvas)
     self.sfid = canvas.create_window(0, 0, window=subframe, anchor="nw")
     self.load_dict(dict)
Ejemplo n.º 40
0
    def __init__(self, master, width=None, anchor=N, height=None, mousewheel_speed = 2, scroll_horizontally=True, xscrollbar=None, scroll_vertically=True, yscrollbar=None, background=None, inner_frame=Frame, **kw):
        Frame.__init__(self, master, class_="Scrolling_Area", background=background)

        self.grid_columnconfigure(0, weight=1)
        self.grid_rowconfigure(0, weight=1)
        
        self._width = width
        self._height = height

        self.canvas = Canvas(self, background=background, highlightthickness=0, width=width, height=height)
        self.canvas.grid(row=0, column=0, sticky=N+E+W+S)

        if scroll_vertically:
            if yscrollbar is not None:
                self.yscrollbar = yscrollbar
            else:
                self.yscrollbar = Scrollbar(self, orient=VERTICAL)
                self.yscrollbar.grid(row=0, column=1,sticky=N+S)
        
            self.canvas.configure(yscrollcommand=self.yscrollbar.set)
            self.yscrollbar['command']=self.canvas.yview
        else:
            self.yscrollbar = None

        if scroll_horizontally:
            if xscrollbar is not None:
                self.xscrollbar = xscrollbar
            else:
                self.xscrollbar = Scrollbar(self, orient=HORIZONTAL)
                self.xscrollbar.grid(row=1, column=0, sticky=E+W)
            
            self.canvas.configure(xscrollcommand=self.xscrollbar.set)
            self.xscrollbar['command']=self.canvas.xview
        else:
            self.xscrollbar = None

        self.rowconfigure(0, weight=1)
        self.columnconfigure(0, weight=1)
        
        self.innerframe = inner_frame(self.canvas, **kw)
        self.innerframe.pack(anchor=anchor)
        
        self.canvas.create_window(0, 0, window=self.innerframe, anchor='nw', tags="inner_frame")

        self.canvas.bind('<Configure>', self._on_canvas_configure)

        Mousewheel_Support(self).add_support_to(self.canvas, xscrollbar=self.xscrollbar, yscrollbar=self.yscrollbar)
Ejemplo n.º 41
0
    def __init__(self):
        self.app = Tk()
        self.app.title('Tic Tac Toe')
        #self.app.resizable(width=False, height=False)
        #width and hight of window
        w = 900
        h = 1100
        #width and hight of screen
        ws = self.app.winfo_screenwidth()
        hs = self.app.winfo_screenheight()
        #calculate position
        x = ws / 2 - w / 2
        y = hs / 2 - h / 2
        #place window -> pramaters(visina, dolzina, pozicija x, pozicija y)
        self.app.geometry("%dx%d+%d+%d" % (w, h, x, y))

        #======================================
        self.frame = Frame()  #main frame
        self.frame.pack(fill='both', expand=True)
        self.label = Label(self.frame,
                           text='Tic Tac Toe',
                           height=4,
                           bg='white',
                           fg='blue')
        self.label.pack(fill='both', expand=True)
        #self.label2 = Label(self.frame, text	= 'here', height = 2, bg = 'white', fg = 'blue') odkomentiri samo za develop-------------
        #self.label2.pack(fill='both', expand = True)
        self.canvas = Canvas(self.frame, width=900, height=900)
        self.canvas.pack(fill='both', expand=True)
        self.framepod = Frame(self.frame)  #sub frame
        self.framepod.pack(fill='both', expand=True)
        self.Single = Button(self.framepod,
                             text='Start single player',
                             height=4,
                             command=self.startsingle,
                             bg='white',
                             fg='blue')
        self.Single.pack(fill='both', expand=True, side=RIGHT)
        self.Multi = Button(self.framepod,
                            text='Start double player',
                            height=4,
                            command=self.double,
                            bg='white',
                            fg='blue')
        self.Multi.pack(fill='both', expand=True, side=RIGHT)
        self.board = AI()
        self.draw()
Ejemplo n.º 42
0
    def initUI(self):
        self.parent.title("Colours")
        self.pack(fill=BOTH, expand=1)

        canvas = Canvas(self)
        canvas.create_rectangle(30, 10, 120, 80, outline="#fb0", fill="#fb0")
        canvas.create_rectangle(150, 10, 240, 80, outline="#f50", fill="#f50")
        canvas.create_rectangle(270, 10, 370, 80, outline="#05f", fill="#05f")
        canvas.pack(fill=BOTH, expand=1)
Ejemplo n.º 43
0
    def initUI(self):
        self.parent.title("Shapes")
        self.pack(fill=BOTH, expand=1)

        canvas = Canvas(self)
        canvas.create_oval(40, 10, 110, 80, outline="black", width=2)
        canvas.create_line(75, 80, 75, 180, width=2)

        canvas.pack(fill=BOTH, expand=1)
Ejemplo n.º 44
0
    def initUI(self):

        self.parent.title("Colors")  # is parent = the background frame?
        self.pack(fill=BOTH, expand=1)  # what is pack, fill, and expand?

        canvas = Canvas(self)
        canvas.create_rectangle(30, 10, 120, 80, outline="#fb0", fill="#fb0")
        canvas.create_rectangle(150, 10, 240, 80, outline="#05f", fill="#05f")
        canvas.pack(fill=BOTH, expand=1)
Ejemplo n.º 45
0
    def prepare_the_playground(self, ncol, nrow):
        '''
    draw the playground according to the cell status map
    different status maps to different color
    '''

        # place the canvas
        canvass = Canvas(self.gui,
                         bg="white",
                         height=self.height,
                         width=self.width)
        canvass.pack()

        # place top bar
        self.make_top_bar()

        # place side info
        #self.make_side_info()

        # place the buttons
        for row_idx in range(nrow):
            for col_idx in range(ncol):
                idx = ncol * row_idx + col_idx

                cell = self.game.canvass.get_cell((row_idx, col_idx))

                # active buttons, with callback function passing the button index
                if cell.status == 'disabled':
                    # disabled buttons, which are unclickable
                    button = Button(self.gui, state=DISABLED)
                else:
                    button = Button(self.gui, cursor="target", \
                                    command=lambda row_idx=row_idx, col_idx=col_idx: \
                                                   self.game.human_play(row_idx, col_idx))

                # calculate the x,y coordinates and place the buttons
                offset_x = self.margin + self.unit * col_idx
                offset_y = 4 * self.margin + self.unit * row_idx + 30
                button.place(x=offset_x,
                             y=offset_y,
                             width=self.unit,
                             height=self.unit)

                self.button_map[idx] = button

        self.refresh_playground()
Ejemplo n.º 46
0
    def __init__(self, parent, initial_state):
        Frame.__init__(self, parent)
        self.pack(fill=BOTH, expand=1)

        self.canvas = Canvas(self, cnf={'background': BACKGROUND_COLOR})

        # outer circle
        kw = {'outline': self.outline, 'fill': self.green}
        base = 30 * SCALE
        d = 190 * SCALE
        s = 10 * SCALE
        outer_circle = ((base, base, base + d - s, base + d),
                        (base + s, base + s, base + d - s - s, base + d - s))
        self.canvas.create_oval(*outer_circle[0], **kw)

        kw['fill'] = BACKGROUND_COLOR
        self.canvas.create_oval(*outer_circle[1], **kw)

        # inner circle
        kw = {'outline': self.outline, 'fill': self.green}
        base = 70 * SCALE
        d = 100 * SCALE
        s = 14 * SCALE
        outer_circle = ((base, base + s, base + d, base + d),
                        (base + s, base + s + s, base + d - s, base + d - s))
        self.canvas.create_oval(*outer_circle[0], **kw)

        kw['fill'] = initial_state[1] if initial_state[0] else self.unpowered
        self.item = self.canvas.create_oval(*outer_circle[1], **kw)

        # top bar
        self.canvas.create_rectangle(base,
                                     base,
                                     base + d,
                                     base + s,
                                     outline=self.green,
                                     fill=self.green)

        # bottom bar
        self.canvas.create_rectangle(base,
                                     base + d,
                                     base + d,
                                     base + d + s,
                                     outline=self.green,
                                     fill=self.green)
        self.canvas.pack(fill=BOTH, expand=1)
Ejemplo n.º 47
0
    def packing(self) :

        Screen.packing(self)
        for i in range(0,4):
            self.frame.columnconfigure(i, weight=1)
        Canvas(self.frame,bg='red',width=10,height=10).grid(row=0,column=0,sticky="e")
        Label(self.frame,text="X",  justify='left').grid(row=0,column=1,sticky="w")
        Canvas(self.frame,bg='green',width=10,height=10).grid(row=0,column=2,sticky="e")
        Label(self.frame,text="Y",  justify='left').grid(row=0,column=3,sticky="w")
        self.magnitudeX.grid(row=1,column=0,sticky='nsew',columnspan=2)
        self.frequencyX.grid(row=2,column=0,sticky='nsew',columnspan=2)
        self.phaseX.grid(row=3,column=0,sticky='nsew',columnspan=2)
        self.magnitudeY.grid(row=1,column=2,sticky='nsew',columnspan=2)
        self.frequencyY.grid(row=2,column=2,sticky='nsew',columnspan=2)
        self.phaseY.grid(row=3,column=2,sticky='nsew',columnspan=3)

        self.frame.pack(fill="both")
Ejemplo n.º 48
0
def displaysampleAutomata(event):
    global frameSampleDisplay
    try:
        if (srcStateTextVariable.get())=='':
            tkMessageBox.showerror("Initial State","Please select an initial state first.")
            return
        elif (destStateTextVariable.get())=='':
            tkMessageBox.showerror("Accepting States","Please select accepting states first.")
            return
        
        if sInputCheck.get()==1:
            import resizeimage
            frameSampleDisplay=ttk.LabelFrame(statsFrame,width=300,height=200)
            samplaCanvas=Canvas(frameSampleDisplay,bg='#FFFFFF',height=200,width=300)
            configGrid(frameSampleDisplay,1,2,1,1)
            samplaCanvas.pack(side=tk.TOP,fill=BOTH)
            filename='../graph/sample.png'
            
            def displaySampleFSM():
                resizeimage.resizeImage(filename,0.5)
                img = PhotoImage(file="../graph/sample0.5.png")
                label1.image = img # keep a reference!
                
                samplaCanvas.delete(img) #reset canvas
                samplaCanvas.create_image(0, 80, anchor='nw',image=img,tags="bg_img")
                
            displaySampleFSM()
            vbar=Scrollbar(frameSampleDisplay,orient=VERTICAL)
            vbar.pack(side=tk.RIGHT,fill=Y,anchor='ne')
            hbar=Scrollbar(frameSampleDisplay,orient=HORIZONTAL)
            hbar.pack(side=tk.TOP,fill=X,anchor='sw')
            hbar.config(command=samplaCanvas.xview)
            vbar.config(command=samplaCanvas.yview)
            canvas.config(xscrollcommand=hbar.set, yscrollcommand=vbar.set)
            
            samplaCanvasLogFrame=Canvas(frameSampleDisplay,bg='#FFFFFF',height=200,width=300)
            samplaCanvasLogFrame.pack(side=BOTTOM)
            displaysamplelogProcesslog=ttk.Button(samplaCanvasLogFrame,text='Process Log',width=10)
            displaysamplelogProcesslog.pack(side=LEFT,fill=X,anchor='w')
            displaysamplelogFSM=ttk.Button(samplaCanvasLogFrame,text='FSM',width=10,command=combine_funcs(generateSampleAutomata,displaySampleFSM))
            
            displaysamplelogFSM.pack(side=LEFT,fill=X,anchor='e')
            
            displaysamplelogPreview=ttk.Button(samplaCanvasLogFrame,text='Preview',width=10)
            displaysamplelogPreview.pack(side=LEFT,fill=X,anchor='e')
            
            def displaysampleFromBrowsercallback(event):
                displayFromBrowser(samplaCanvas,'sample')
                
            displaysamplelogPreview.bind('<ButtonRelease-1>',displaysampleFromBrowsercallback)
            
        elif sInputCheck.get()==0:
            #frameSampleDisplay.pack_forget()
            frameSampleDisplay.grid_forget() #Remove the Frame
    except (NameError,Exception):
        pass
Ejemplo n.º 49
0
    def __initUI(self, gridopts=None):
        if gridopts is None:
            gridopts = {}

        self.grid(fill=None, row=self._row, column=self._col, **gridopts)
        self.canvas = Canvas(self,
                             width=self._dim["WIDTH"],
                             height=self._dim["HEIGHT"])
        self.canvas.pack(fill=None)

        self.redraw_state()

        # bind keyboard
        # self.canvas.focus_set()

        self.canvas.bind("<Button-1>", self.__cell_clicked)
        self.canvas.bind("<Key>", self.__key_pressed)
Ejemplo n.º 50
0
 def __init__(self, call_forest, tk, width, height, colours):
     self.call_forest = call_forest
     self.tk = tk
     self.width = width
     self.height = height
     self.colours = colours
     self.font = ('Courier', 12)
     self.character_width = 0.1 * Font(family='Courier',
                                       size=12).measure('mmmmmmmmmm')
     self.min_width_for_text = 3 * self.character_width
     self.min_height_for_text = 10
     self.x_scale = float(width) / call_forest.samples()
     self.y_scale = float(height) / call_forest.depth()
     self.top = Toplevel(tk)
     self.top.title(call_forest.name)
     self.canvas = Canvas(self.top, width=width, height=height)
     self.canvas.pack()
Ejemplo n.º 51
0
 def __init__(self,
              canvasWidth,
              canvasHeight,
              viewCenterX=0.0,
              viewCenterY=0.0,
              viewWidth=1.0,
              viewHeight=1.0,
              **kw):
     Toplevel.__init__(self, **kw)
     self.viewCenterX = viewCenterX
     self.viewCenterY = viewCenterY
     self.viewWidth = viewWidth
     self.viewHeight = viewHeight
     self.canvas = Canvas(self, width=canvasWidth, height=canvasHeight)
     self.canvas.pack()
     self.protocol("WM_DELETE_WINDOW", self.onClose)
     self.bind("<Configure>", self.onResize)
Ejemplo n.º 52
0
    def __init__(self, parent, size, color):
        self.parent = parent
        self.size = size
        self.color = color

        # design to fit tkinter grid(row, col)two params
        self.unused_cells_dict = CELLS_DICT.copy()

        # creating main container for the board
        self.container = Frame(self.parent)
        self.container.pack()

        # creating canvas for the container
        self.canvas = Canvas(self.container,
                             width=self.size * 3,
                             height=self.size * 3)
        self.canvas.grid(row=0, column=0, rowspan=3, sticky=W + E + N + S)
Ejemplo n.º 53
0
def show_mol( mol):
  from Tkinter import Tk, Canvas, Frame

  app = Tk()
  app.title( "oasa")

  mainFrame = Frame( app)
  mainFrame.pack( fill='both', expand=1)

  paper = Canvas( mainFrame, width=640, height=480, background="white", closeenough=5)
  paper.pack()

  xmin, xmax, ymin, ymax = None,None,None,None
  for a in mol.vertices:
    if xmin == None or a.x < xmin:
      xmin = a.x
    if xmax == None or a.x > xmax:
      xmax = a.x
    if ymin == None or a.y < ymin:
      ymin = a.y
    if ymax == None or a.y > ymax:
      ymax = a.y

  dx = xmax-xmin
  dy = ymax-ymin
  #print "dx", dy, ymax, ymin
  range = min( (600.0/dx, 450.0/dy))/2
  xp = 640-range*dx
  yp = 480-range*dy
  xtrans = lambda xx: range*(xx - xmin)+xp/2
  ytrans = lambda xx: range*(xx - ymin)+yp/2

  for b in mol.edges:
    a1, a2 = b.vertices
    x1 = xtrans( a1.x)
    x2 = xtrans( a2.x)
    y1 = ytrans( a1.y)
    y2 = ytrans( a2.y)
    paper.create_line( x1, y1, x2, y2, fill='black')
    paper.create_text( (x1+x2)/2, (y1+y2)/2, text=str( b.order), fill="#F00")
  for v in mol.vertices: 
    x = xtrans( v.x)
    y = ytrans( v.y)
    #paper.create_oval( x-5, y-5, x+5, y+5, fill="#0F0")
    paper.create_text( x, y, text=v.symbol, fill="#0F0")
  app.mainloop()
Ejemplo n.º 54
0
    def __init__(self,
                 master,
                 filename=None,
                 data=None,
                 start_animation=True,
                 time=40,
                 **kwargs):

        if data is not None:
            self._image = Image.open(BytesIO(base64.b64decode(data)))
        elif filename is not None:
            self._image = Image.open(filename)
        elif hasattr(self, "data"):
            self._image = Image.open(BytesIO(base64.b64decode(self.data)))
        else:
            raise Exception("No image data or file")

        if self._image.format == "XBM":
            self._imagetk_class = ImageTk.BitmapImage
        else:
            self._imagetk_class = ImageTk.PhotoImage

        width, height = self._image.size

        self._time = time

        kwargs.setdefault("width", width)
        kwargs.setdefault("height", height)
        kwargs.setdefault("highlightthickness", 0)

        if "borderwidth" not in kwargs and "bd" not in kwargs:
            kwargs["borderwidth"] = 0

        Canvas.__init__(self, master, **kwargs)

        self._bind_tag = "icon_rotating%s" % RotatingIcon._bind_tag_ID
        RotatingIcon._bind_tag_ID += 1

        self.bind_class(self._bind_tag, "<Unmap>", self._on_unmap)
        self.bind_class(self._bind_tag, "<Map>", self._on_map)

        self._running = False
        self._is_mapped = False

        if start_animation:
            self.start_animation()
Ejemplo n.º 55
0
    def __init__(self,
                 suction_height,
                 regions,
                 tl_x=0,
                 tl_y=0,
                 width=500,
                 height=150,
                 title='Grid',
                 background='tan'):
        self.tk = Tk()
        # tk.geometry('%dx%d+%d+%d'%(width, height, 100, 0))
        self.tk.withdraw()
        self.top = Toplevel(self.tk)
        self.top.wm_title(title)
        self.top.protocol('WM_DELETE_WINDOW', self.top.destroy)

        self.suction_height = suction_height
        self.regions = regions
        self.tl_x = tl_x
        self.tl_y = tl_y
        self.width = width
        self.height = height
        self.canvas = Canvas(self.top,
                             width=self.width,
                             height=self.height,
                             background=background)
        self.canvas.pack()
        # self.center()
        self.move_frame(self.tl_x, self.tl_y)

        max_width = max(
            map(get_width,
                regions.values()))  # Really should take width of max minus min
        self.dist_to_pixel = (self.width - 2 * PIXEL_BUFFER
                              ) / max_width  # Maintains aspect ratio
        self.dist_width = self.width / self.dist_to_pixel
        self.dist_height = self.height / self.dist_to_pixel
        self.ground_height = self.height - self.dist_to_pixel * ENV_HEIGHT
        self.robot_dist = self.dist_height / 2.

        self.robot = []
        self.blocks = []
        self.holding = None
        self.environment = []
        self.draw_environment()
Ejemplo n.º 56
0
 def __draw_continuous_view(self, min_val, max_val, scheme, m_unit_string,
                            n_classes):
     """
     :param min_val:
     :param max_val:
     :param scheme:
     :param m_unit_string:
     :param n_classes:
     :return:
     """
     is_width_longer = self._width > self._height
     start_x, start_y, x_pos, y_pos = 0, 0, 0, 0
     val_range = (max_val - min_val) / n_classes
     if is_width_longer:
         y_pos = int(self._height * 0.2)
         start_x = int(self._width * 0.25)
         square_side1 = int(0.2 * self._height)
         square_side2 = int((self._width / 2) / n_classes)
     else:
         x_pos = int(self._width * 0.2)
         start_y = int(self._height * 0.25)
         square_side1 = int((self._height / 2) / n_classes)
         square_side2 = int(0.2 * self._width)
     for i in xrange(n_classes):
         color = View.calculate_color(min_val, max_val, n_classes,
                                      val_range * i + 1, scheme)
         if is_width_longer:
             x_pos = start_x + (i * square_side2)
         else:
             y_pos = start_y + (i * square_side2)
         Canvas.create_rectangle(self,
                                 x_pos,
                                 y_pos,
                                 x_pos + square_side1,
                                 y_pos + square_side2,
                                 fill=color)
     text = str(float(min)) + m_unit_string + " - " + str(
         float(max)) + m_unit_string
     if is_width_longer:
         x = int(self._width / 2)
         y = int(self._height * 0.7)
     else:
         x = int(self._width * 0.7)
         y = int(self._height / 2)
     Canvas.create_text(self, x, y, text=text)
Ejemplo n.º 57
0
def error_and_exit(title, main_text):
    """
    Show a pop-up window and sys.exit() out of Python.

    :param title: the short error description
    :param main_text: the long error description
    """
    # NOTE: We don't want to load all of these imports normally.
    #       Otherwise we will have these unused GUI modules loaded in the main process.
    from Tkinter import Tk, Canvas, DISABLED, INSERT, Label, Text, WORD

    root = Tk()
    root.wm_title("Tribler: Critical Error!")
    root.wm_minsize(500, 300)
    root.wm_maxsize(500, 300)
    root.configure(background='#535252')

    Canvas(root, width=500, height=50, bd=0, highlightthickness=0, relief='ridge', background='#535252').pack()
    pane = Canvas(root, width=400, height=200, bd=0, highlightthickness=0, relief='ridge', background='#333333')
    Canvas(pane, width=400, height=20, bd=0, highlightthickness=0, relief='ridge', background='#333333').pack()
    Label(pane, text=title, width=40, background='#333333', foreground='#fcffff', font=("Helvetica", 11)).pack()
    Canvas(pane, width=400, height=20, bd=0, highlightthickness=0, relief='ridge', background='#333333').pack()

    main_text_label = Text(pane, width=45, height=6, bd=0, highlightthickness=0, relief='ridge', background='#333333',
                           foreground='#b5b5b5', font=("Helvetica", 11), wrap=WORD)
    main_text_label.tag_configure("center", justify='center')
    main_text_label.insert(INSERT, main_text)
    main_text_label.tag_add("center", "1.0", "end")
    main_text_label.config(state=DISABLED)
    main_text_label.pack()

    pane.pack()

    root.mainloop()
Ejemplo n.º 58
0
 def _draw_fuel_view(self):
     """
     :return:
     """
     if self.__fuel_model is not None:
         side = self.__square_side
         for i in xrange(self.__n_rows):
             for j in xrange(self.__n_cols):
                 x = self.__start_x + j * side
                 y = self.__start_y + i * side
                 rbg_color = self._fuel_color_map[self.__fuel_model[i][j]]
                 hex_color = View.convert_rbg_triplet_hexadecimal(rbg_color)
                 Canvas.create_rectangle(self,
                                         x,
                                         y,
                                         x + side,
                                         y + side,
                                         fill=hex_color)
Ejemplo n.º 59
-1
def failure(reason, cur_dir):
    """
    Displays a "submission failure" picture and emails
    a bug report to maintenance.
    """
    bugmail = {"email": "*****@*****.**"}
    send_email(bugmail, "QR Code Submission Failure", reason, None)
    root = Tk()
    root.focus_set()
    # Get the size of the screen and place the splash screen in the center
    gif = Image.open(str(cur_dir) + '/Images/Failure.gif')
    width = gif.size[0]
    height = gif.size[1]
    flog = (root.winfo_screenwidth()/2-width/2)
    blog = (root.winfo_screenheight()/2-height/2)
    root.overrideredirect(1)
    root.geometry('%dx%d+%d+%d' % (width*1, height + 44, flog, blog))
    # Pack a canvas into the top level window.
    # This will be used to place the image
    failure_canvas = Canvas(root)
    failure_canvas.pack(fill = "both", expand = True)
    # Open the image
    imgtk = PhotoImage(gif)
    # Get the top level window size
    # Need a call to update first, or else size is wrong
    root.update()
    cwidth = root.winfo_width()
    cheight =  root.winfo_height()
    # create the image on the canvas
    failure_canvas.create_image(cwidth/2, cheight/2.24, image=imgtk)
    Button(root, text = str(
        reason), width = 50, height = 2, command = root.destroy).pack()
    root.after(5000, root.destroy)
    root.mainloop()
Ejemplo n.º 60
-2
def displayFromBrowser(Canvas,flag):
    try:
        import webbrowser
        if flag=='ktail':
            if len(Canvas.find_all())==0:
                tkMessageBox.showinfo("FSM", 'Nothing to show.Please generate an FSM first')
                return
            webbrowser.open('../graph/ktail.png')
        elif flag=='sample':
            if len(Canvas.find_all())==0:
                tkMessageBox.showinfo("FSM", 'Nothing to show.Please generate an FSM first')
                return
            webbrowser.open('../graph/sample0.5.png')
    except Exception:
        tkMessageBox.showerror("Error", "Error encountered while opening the FSM")
        pass