Example #1
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()
Example #2
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)
Example #3
0
    def comboboxcallback(self, bit):
        if self.indBitOptMenu[bit].get() == "Pulse":
            #Create a new button that is pulse
            tmpCnvs = Canvas(self.bitFrms[bit], width=100, height=40)
            tmpCnvs.grid(column=0, row=2, columnspan=2)
            tmpBtn = Button(self.bitFrms[bit],
                            text="SimSwitch",
                            command=lambda tmp=bit: self.toggle(tmp))
            tmpBtn.grid(column=0, row=2, columnspan=2, padx=4, pady=12)
            self.toggleBtn[bit] = tmpBtn

            #Set the state variables
            self.toggleState[bit] = False
            self.btnCfgBitfield &= ~(1 << bit)
            self.simSwitchBits &= ~(1 << bit)
        else:
            #Create a new button that is toggle
            tmpCnvs = Canvas(self.bitFrms[bit], width=100, height=40)
            tmpCnvs.grid(column=0, row=2, columnspan=2)
            tmpBtn = Btn(self.bitFrms[bit],
                         text="SimSwitch",
                         command=lambda tmp=bit: self.toggle(tmp))
            tmpBtn.grid(column=0, row=2, columnspan=2, padx=8, pady=8)
            self.toggleBtn[bit] = tmpBtn

            #Set the state variables
            self.btnCfgBitfield |= (1 << bit)
            if self.toggleState[bit]:
                self.simSwitchBits |= (1 << bit)
            else:
                self.simSwitchBits &= ~(1 << bit)
    def comboboxcallback(self, whichThread):
        if TkCmdFrm.comboVar[whichThread].get() == "Single Step":
            #Create a new button that is pulse
            tmpCnvs = Canvas(self.cmdFrm, width=100, height=40)
            tmpCnvs.grid(column=whichThread, row=2)
            tmpBtn = Button(self.cmdFrm,
                            text="Single Step",
                            command=lambda tmp=whichThread: self.toggle(tmp))
            tmpBtn.grid(column=whichThread, row=2, padx=4, pady=12)
            TkCmdFrm.toggleBtn[whichThread] = tmpBtn

            #Set the state variables
            TkCmdFrm.toggleState[whichThread] = False
            TkCmdFrm.threadSendStep[whichThread] = False
            TkCmdFrm.threadRun[whichThread] = False
            TkCmdFrm.btnCfgBitfield &= ~(1 << whichThread)
        else:
            #Create a new button that is toggle
            tmpCnvs = Canvas(self.cmdFrm, width=100, height=40)
            tmpCnvs.grid(column=whichThread, row=2)
            tmpBtn = Btn(self.cmdFrm,
                         text="Run",
                         command=lambda tmp=whichThread: self.toggle(tmp))
            tmpBtn.grid(column=whichThread, row=2, padx=8, pady=8)
            TkCmdFrm.toggleBtn[whichThread] = tmpBtn

            #Set the state variables
            TkCmdFrm.toggleState[whichThread] = False
            TkCmdFrm.threadSendStep[whichThread] = False
            TkCmdFrm.threadRun[whichThread] = True
            TkCmdFrm.btnCfgBitfield |= (1 << whichThread)
Example #5
0
    def __init__(self, drs, size_canvas=True, canvas=None):
        """
        :param drs: ``AbstractDrs``, The DRS to be drawn
        :param size_canvas: bool, True if the canvas size should be the exact size of the DRS
        :param canvas: ``Canvas`` The canvas on which to draw the DRS.  If none is given, create a new canvas.
        """
        master = None
        if not canvas:
            master = Tk()
            master.title("DRT")

            font = Font(family='helvetica', size=12)

            if size_canvas:
                canvas = Canvas(master, width=0, height=0)
                canvas.font = font
                self.canvas = canvas
                (right, bottom) = self._visit(drs, self.OUTERSPACE,
                                              self.TOPSPACE)

                width = max(right + self.OUTERSPACE, 100)
                height = bottom + self.OUTERSPACE
                canvas = Canvas(master, width=width,
                                height=height)  #, bg='white')
            else:
                canvas = Canvas(master, width=300, height=300)

            canvas.pack()
            canvas.font = font

        self.canvas = canvas
        self.drs = drs
        self.master = master
Example #6
0
 def show(self, board):
     if self.gamePlay is self.BOT_PLAY:
         if self.boardView == None:
             frame = Frame(self.root)
             frame.pack()
             self.boardView = Canvas(frame, bg='blue', height=board.ROWS*self.cellSize, width=board.COLLUMNS*self.cellSize)
             self.boardView.pack(side=Tkinter.TOP)
         
         self.boardView.children.clear()
         b = board.toArray()
         for i in range(board.COLLUMNS * board.ROWS):
             x, y = (i%board.COLLUMNS) * self.cellSize, (i//board.COLLUMNS) * self.cellSize
             start = self.cellSize//10
             end = self.cellSize-start
             oval = x+start, y+start, x+end, y+end
             if(b[i] == 0):
                 self.boardView.create_oval(oval, fill='white')
             elif(b[i] == 1):
                 self.boardView.create_oval(oval, fill='red')
             else:
                 self.boardView.create_oval(oval, fill='yellow')
     elif self.gamePlay is self.USER_PLAY:
         if self.boardView == None:
             frame = Frame(self.root)                
             frame.pack()
             self.boardView = Canvas(frame, bg='blue', height=board.ROWS*self.cellSize+self.cellSize, width=board.COLLUMNS*self.cellSize)
             self.boardView.pack(side=Tkinter.TOP)
             
         self.board = board
         
         self.boardView.children.clear()
         b = board.toArray()
         
         if(self.USER_POS == board.COLLUMNS):
             self.USER_POS = 0
         elif(self.USER_POS < 0):
             self.USER_POS = board.COLLUMNS - 1
         
         o = (self.USER_POS%board.COLLUMNS) * self.cellSize + self.cellSize//10, self.cellSize//10, (self.USER_POS%board.COLLUMNS) * self.cellSize + self.cellSize - self.cellSize//10, self.cellSize - self.cellSize//10
         
         if board.turn == 1:
             self.boardView.create_oval(o, fill='red')
         else:
             self.boardView.create_oval(o, fill='yellow')
         
         for i in range(board.COLLUMNS * board.ROWS):
             x, y = (i%board.COLLUMNS) * self.cellSize, (i//board.COLLUMNS) * self.cellSize + self.cellSize
             start = self.cellSize//10
             end = self.cellSize-start
             oval = x+start, y+start, x+end, y+end
             if(b[i] == 0):
                 self.boardView.create_oval(oval, fill='white')
             elif(b[i] == 1):
                 self.boardView.create_oval(oval, fill='red')
             else:
                 self.boardView.create_oval(oval, fill='yellow')
Example #7
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
Example #8
0
 def layout(self):
     canvas = Canvas(self.Widget, width=400, height=10)
     canvas.create_line(10, 2, 400, 2, fill='black', tags="line")
     self.rowindex = self.rowindex + 1
     canvas.grid(row=self.rowindex, column=1, columnspan=4)
     lblTarget = Label(self.Widget,
                       text=self.conf.get("TargetDeviceName", "title",
                                          "目标设备"),
                       font=self.fontSize)
     lblTarget.grid(row=self.rowindex, column=1, columnspan=4)
     lblTargetW = Label(self.Widget,
                        text=self.conf.get("TargetDeviceName", "width",
                                           "宽度(px)"),
                        font=self.fontSize)
     self.rowindex = self.rowindex + 1
     lblTargetW.grid(row=self.rowindex, column=1)
     entryTargetW = Entry(self.Widget, width=10, font=self.fontSize)
     entryTargetW.grid(row=self.rowindex, column=2)
     self.entryTargetW = entryTargetW
     lblTargetH = Label(self.Widget,
                        text=self.conf.get("TargetDeviceName", "width",
                                           "高度(px)"),
                        font=self.fontSize)
     lblTargetH.grid(row=self.rowindex, column=3)
     entryTargetH = Entry(self.Widget, width=10, font=self.fontSize)
     entryTargetH.grid(row=self.rowindex, column=4)
     self.entryTargetH = entryTargetH
     fmBox = Frame(self.Widget)
     scrollbar = Scrollbar(fmBox)
     scrollbar.pack(side=RIGHT, fill=Y)
     lb = Listbox(fmBox,
                  yscrollcommand=scrollbar.set,
                  width=25,
                  selectmode=EXTENDED)
     lb.pack(side=LEFT, fill=BOTH)
     scrollbar.config(command=lb.yview)
     self.rowindex = self.rowindex + 1
     fmBox.grid(row=self.rowindex, column=1, columnspan=2)
     self.lb = lb
     fmOper = Frame(self.Widget)
     fmAdd = Frame(fmOper, pady=10)
     btAdd = Button(fmAdd, text="添加", command=self.processAdd)
     btAdd.pack()
     fmDel = Frame(fmOper, pady=10)
     btDel = Button(fmDel, text="删除", command=self.processDel)
     btDel.pack()
     fmAdd.pack(side=TOP)
     fmDel.pack(side=BOTTOM)
     fmOper.grid(row=self.rowindex, column=3)
     canvas = Canvas(self.Widget, width=400, height=10)
     canvas.create_line(10, 2, 400, 2, fill='black', tags="line")
     self.rowindex = self.rowindex + 1
     canvas.grid(row=self.rowindex, column=1, columnspan=4)
     self.readDefDevice()
     return self.rowindex
Example #9
0
    def _setupUI(self):
        """
        Setup UI.
        """
        self.resizable(width=False, height=False)
      
        #obs model
        self.obsgraph = [Canvas(self, width=self._CELL_WIDTH, height=50) for i in xrange(self.numStates)]
        self.obsLabel = Label(self, text='P(O|S):')
        self.obsLabel.grid(row=19, column=0)
        for ix in xrange(len(self.obsgraph)):
            self.obsgraph[ix].grid(row=19, column=ix+2,ipady=5)
            self.obsgraph[ix]._old = None
            self.obsgraph[ix].create_rectangle(0,
                                               0,
                                               self._CELL_WIDTH,
                                               50, fill='white', outline='white') #clear
            self.obsgraph[ix].height = 50
            self.obsgraph[ix].color = 'blue'

        self.posteriorgraph = [Canvas(self, width=self._CELL_WIDTH, height=100) for i in xrange(self.numStates)]
        self.posteriorLabel = Label(self, text='Belief:')
        self.posteriorLabel.grid(row=24, column=0)
        for ix in xrange(len(self.posteriorgraph)):
            self.posteriorgraph[ix].grid(row=24, column=ix+2,ipady=5)
            self.posteriorgraph[ix]._old = None
            self.posteriorgraph[ix].create_rectangle(0,
                                                     0,
                                                     self._CELL_WIDTH,
                                                     100, fill='white', outline='white') #clear
            self.posteriorgraph[ix].height=100
            self.posteriorgraph[ix].color = 'blue'
        
        self.distgraph = [Canvas(self, width=self._CELL_WIDTH, height=50) for i in xrange(self.numStates)]
        self.distLabel = Label(self, text='Ideal\nDistance')
        self.distLabel.grid(row=7, column=0)
        for ix in xrange(len(self.distgraph)):
            self.distgraph[ix].grid(row=7, column=ix+2,ipady=5)
            self.distgraph[ix]._old = None
            self.distgraph[ix].create_rectangle(0,
                                               0,
                                               self._CELL_WIDTH,
                                               50, fill='red', outline='white') #clear
            self.distgraph[ix].height = 50
            self.distgraph[ix].color = 'white'
	maxDist = float(max(self.ideal)+3)
	self._drawGraph(self.distgraph, [i/maxDist for i in self.ideal])

        self.observation = StringVar()
        self.obsLabel = Label(self, textvariable=self.observation, height=1)
        self.obsLabel.grid(row=4,column=0)

        self.updateObsGraph([0 for i in xrange(self.numStates)])
        self.updateBeliefGraph([0 for i in xrange(self.numStates)])
Example #10
0
    def createWidgets(self):
        "Create initial widget set."

        # Objects
        title = Label(self, text='Bandwidth (Gb/s)', bg=self.bg)
        width = self.gwidth
        height = self.gheight
        scale = self.createScale()
        graph = Canvas(self, width=width, height=height, background=self.bg)
        xbar = Scrollbar(self, orient='horizontal', command=graph.xview)
        ybar = Scrollbar(self, orient='vertical', command=self.yview)
        graph.configure(xscrollcommand=xbar.set,
                        yscrollcommand=ybar.set,
                        scrollregion=(0, 0, width, height))
        scale.configure(yscrollcommand=ybar.set)

        # Layout
        title.grid(row=0, columnspan=3, sticky='new')
        scale.grid(row=1, column=0, sticky='nsew')
        graph.grid(row=1, column=1, sticky='nsew')
        ybar.grid(row=1, column=2, sticky='ns')
        xbar.grid(row=2, column=0, columnspan=2, sticky='ew')
        self.rowconfigure(1, weight=1)
        self.columnconfigure(1, weight=1)
        return title, scale, graph
Example #11
0
    def draw_game_grid(self):
        '''
        Draw empty 8x8 grid on the left side of the window.
        '''
        self.grid = Canvas(self.root,
                           bg="white",
                           height=self.gridh,
                           width=self.gridw)
        self.grid.bind("<Button 1>", self.place_stone_click_handler)
        gridsize = self.boardSize
        offy = self.offy
        offx = self.offx
        w = self.gridw
        h = self.gridh
        spacing = self.gridspacing
        # line around
        self.grid.create_line(offx, offy, offx, h - offy, w - offx, h - offy,
                              w - offx, offy, offx, offx)

        for x in range(0, gridsize):
            for y in range(0, gridsize):
                arrayText = '[' + str(y) + ',' + str(x) + ']'
                self.grid.create_text(offx + (spacing * x) + spacing / 2,
                                      offy + (spacing * y) + spacing / 2,
                                      text=arrayText)
        # line rows
        for rowy in range(offy + spacing, h - offy, spacing):
            self.grid.create_line(offx, rowy, w - offx, rowy)

        # line columns
        for colx in range(offx + spacing, w - offx, spacing):
            self.grid.create_line(colx, offy, colx, h - offy)

        self.grid.pack(side="left")
Example #12
0
 def __init__(self):
     self.app = Tk()
     self.app.title('Connect4')
     self.app.resizable(width=False, height=False)
     self.board = Board()
     self.buttons = {}
     self.frame = Frame(self.app, borderwidth=1, relief="raised")
     self.tiles = {}
     for x in range(self.board.width):
         handler = lambda x=x: self.move(x)
         button = Button(self.app,
                         command=handler,
                         font=Font(family="Helvetica", size=14),
                         text=x + 1)
         button.grid(row=0, column=x, sticky="WE")
         self.buttons[x] = button
     self.frame.grid(row=1, column=0, columnspan=self.board.width)
     for x, y in self.board.fields:
         tile = Canvas(self.frame,
                       width=60,
                       height=50,
                       bg="navy",
                       highlightthickness=0)
         tile.grid(row=self.board.height - 1 - y, column=x)
         self.tiles[x, y] = tile
     handler = lambda: self.reset()
     self.restart = Button(self.app, command=handler, text='reset')
     self.restart.grid(row=2,
                       column=0,
                       columnspan=self.board.width,
                       sticky="WE")
     self.update()
Example #13
0
 def __init__(self, parent):
     Frame.__init__(self, parent)
     self.parent = parent
     self.canvas = Canvas(self, width=WIDTH, height=HEIGHT)
     self.initTime()
     self.draw()
     self.onTimer()
    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
Example #15
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()
Example #16
0
    def __init__(self, parent, langton_ant):
        Frame.__init__(self, parent)
        self.parent = parent
        self.pack(fill=BOTH, expand=1)

        self.title = self.parent.title()

        self.rows = 101
        self.columns = 82
        self.cell_width = 6
        self.cell_height = 6

        self.canvas = Canvas(self,
                             width=self.cell_width * self.columns,
                             height=self.cell_height * self.rows,
                             borderwidth=0,
                             highlightthickness=0)
        self.canvas.pack(side="top", fill="both", expand="true")

        self.rect = {}
        for column in range(self.columns):
            for row in range(self.rows):
                x1 = column * self.cell_width
                y1 = row * self.cell_height
                x2 = x1 + self.cell_width
                y2 = y1 + self.cell_height
                self.rect[row, column] = self.canvas.create_rectangle(
                    x1, y1, x2, y2, fill="white", tags="rect", outline="black")

        self.langton_ant = langton_ant
        self.draw_result(500)
Example #17
0
    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)
Example #18
0
    def __init__(self):
        Frame.__init__(self)
        self.place(x=0, y=0)
        self.leap = Leap.Controller()
        self.painter = TouchPointListener()

        self.botonLimpiar = Button(self,
                                   text="Limpiar",
                                   fg="white",
                                   bg="red",
                                   command=self.painter.limpiar)
        self.botonLimpiar.pack(side=TOP)

        self.botonCapturar = Button(self,
                                    text="Identificar Numero",
                                    fg="blue",
                                    bg="white",
                                    command=self.painter.capturar)
        self.botonCapturar.pack(side=TOP)

        self.leap.add_listener(self.painter)
        self.pack(expand=YES, fill=BOTH)
        self.master.title("Prueba 1")
        self.master.geometry("500x500+0+0")

        self.leap.enable_gesture(Leap.Gesture.TYPE_SWIPE)
        self.leap.config.set("Gesture.Swipe.MinLength", 100.0)
        self.leap.config.set("Gesture.Swipe.MinVelocity", 750)
        self.leap.config.save()

        self.paintCanvas = Canvas(self, width="500", height="500", bg="white")

        self.paintCanvas.pack()
        self.painter.set_canvas(self.paintCanvas)
Example #19
0
 def __init__(self,parent,bg="white"):
     self.canvas=Canvas(parent,bg=bg)
     print("parent",parent.cget("width"),parent.cget("height"))
     self.magnitude=Scale(parent,length=250,orient="horizontal",
                      label="Magnitude", sliderlength=20,
                      showvalue=0,from_=0,to=5,
                      tickinterval=25)
Example #20
0
    def createCanvas( self ):
        "Create and return our scrolling canvas frame."
        f = Frame( self )

        canvas = Canvas( f, width=self.cwidth, height=self.cheight,
                         bg=self.bg )

        # Scroll bars
        xbar = Scrollbar( f, orient='horizontal', command=canvas.xview )
        ybar = Scrollbar( f, orient='vertical', command=canvas.yview )
        canvas.configure( xscrollcommand=xbar.set, yscrollcommand=ybar.set )

        # Resize box
        resize = Label( f, bg='white' )

        # Layout
        canvas.grid( row=0, column=1, sticky='nsew')
        ybar.grid( row=0, column=2, sticky='ns')
        xbar.grid( row=1, column=1, sticky='ew' )
        resize.grid( row=1, column=2, sticky='nsew' )

        # Resize behavior
        f.rowconfigure( 0, weight=1 )
        f.columnconfigure( 1, weight=1 )
        f.grid( row=0, column=0, sticky='nsew' )
        f.bind( '<Configure>', lambda event: self.updateScrollRegion() )

        # Mouse bindings
        canvas.bind( '<ButtonPress-1>', self.clickCanvas )
        canvas.bind( '<B1-Motion>', self.dragCanvas )
        canvas.bind( '<ButtonRelease-1>', self.releaseCanvas )

        return f, canvas
Example #21
0
 def __init__(self,
              parent,
              board,
              width=PALETTE_WIDTH,
              height=PALETTE_HEIGHT):
     """
 |board|: the board on to which items will be added from this palette.
 |width|: the width of this palette.
 |height|: the height of this palette.
 """
     assert isinstance(board, Board), 'board must be a Board'
     Frame.__init__(self, parent, background=PALETTE_BACKGROUND_COLOR)
     self.board = board
     # canvas on which items are displayed
     self.canvas = Canvas(self,
                          width=width,
                          height=height,
                          highlightthickness=0,
                          background=PALETTE_BACKGROUND_COLOR)
     self.width = width
     self.height = height
     # x-position of last item added on the LEFT side of this palette
     self.current_left_x = PALETTE_PADDING
     # x-position of last item added on the RIGHT side of this palette
     self.current_right_x = self.width
     # line to separate left and right sides of palette
     self.left_right_separation_line_id = None
     # setup ui
     self.canvas.pack()
     self.pack()
Example #22
0
def addScrollingFigure(figure, frame):
    global canvas, mplCanvas, interior, interior_id, cwid
    # set up a canvas with scrollbars
    canvas = Canvas(frame)
    canvas.grid(row=1, column=1, sticky=Tkconstants.NSEW)

    xScrollbar = Scrollbar(frame, orient=Tkconstants.HORIZONTAL)
    yScrollbar = Scrollbar(frame)

    xScrollbar.grid(row=2, column=1, sticky=Tkconstants.EW)
    yScrollbar.grid(row=1, column=2, sticky=Tkconstants.NS)

    canvas.config(xscrollcommand=xScrollbar.set)
    xScrollbar.config(command=canvas.xview)
    canvas.config(yscrollcommand=yScrollbar.set)
    yScrollbar.config(command=canvas.yview)

    # plug in the figure
    figAgg = FigureCanvasTkAgg(figure, canvas)
    mplCanvas = figAgg.get_tk_widget()

    # and connect figure with scrolling region
    cwid = canvas.create_window(0, 0, window=mplCanvas, anchor=Tkconstants.NW)
    printBboxes("Init")
    changeSize(figure, 1)
Example #23
0
    def init_gui(self, tk_root):
        # GUI
        frame = Frame(tk_root)

        canvas_width = 600
        canvas_height = 600

        self.canvas = Canvas(frame, width=canvas_width, height=canvas_height)
        self.canvas.pack()
        frame.pack()

        self.quit_button = Button(frame,
                                  text="QUIT",
                                  fg="red",
                                  command=frame.quit)
        self.quit_button.pack(side=LEFT)
        self.jump_button = Button(frame, text="JUMP", command=self.jump)
        self.jump_button.pack(side=LEFT)

        self.text_counter = StringVar()
        self.text_counter.set('Round: {}'.format(self.jump_counter))
        self.label_counter = Label(frame,
                                   textvariable=self.text_counter,
                                   justify=LEFT)
        self.label_counter.pack()

        self.text_meet_counter = StringVar(self.meet_counter)
        self.label_meet_counter = Label(frame,
                                        textvariable=self.text_meet_counter,
                                        justify=LEFT)
        self.label_meet_counter.pack()
Example #24
0
    def initUI(self):
        self.parent.title("TNN visualization")
        self.pack(fill=BOTH, expand=1)

        canvas = Canvas(self, bg="#000")

        width, height = 500, 500
        canvas.config(width=width, height=height)
        canvas.create_line(400, 0, 0, 400, width=1, fill="#fff")

        data = clusterize_data()

        #for i in range(30):
        #    x, y = randint(1, height), randint(1, height)
        #    canvas.create_oval(x, y, x+4, y+4, outline="#0f0", fill="#0f0")

        min, max = -3, 3
        range_data = max - min
        step = 500.0 / range_data

        for d in data:
            x, y = (max - d[0]) * step, (max - d[1]) * step
            x, y = 500 - x, 500 - y
            canvas.create_oval(x, y, x + 4, y + 4, outline="#0f0", fill="#0f0")

        canvas.pack(fill=BOTH, expand=1)
Example #25
0
    def __init__(self, parent, tile_size, grid_vm=None):
        Frame.__init__(self, parent, relief=RAISED, borderwidth=1)
        self.parent = parent
        self.tile_size = tile_size
        self.grid_vm = grid_vm
        self.columnconfigure(0, weight=1)
        self.columnconfigure(1, pad=3)
        self.rowconfigure(0, weight=1)
        self.rowconfigure(1, pad=3)
        hbar = Scrollbar(self, orient=HORIZONTAL)
        vbar = Scrollbar(self, orient=VERTICAL)
        canvas = Canvas(self, xscrollcommand=hbar.set, yscrollcommand=vbar.set)
        self.canvas = canvas
        self.lines = []

        canvas.bind_all("<MouseWheel>", self._on_mousewheel_vertical)
        canvas.bind_all("<Shift-MouseWheel>", self._on_mousewheel_horizontal)

        # Set up scroll bars
        hbar.pack(side=BOTTOM, fill=X)
        hbar.config(command=canvas.xview)
        vbar.pack(side=RIGHT, fill=Y)
        vbar.config(command=canvas.yview)

        canvas.grid(column=0, row=0, sticky=N + W + E + S)
        hbar.grid(column=0, row=1, sticky=W + E)
        vbar.grid(column=1, row=0, sticky=N + S)

        if grid_vm:
            self.set_vm(grid_vm)
Example #26
0
    def __init__(self,
                 rows,
                 cols,
                 width=500,
                 height=250,
                 side=25,
                 block_buffer=10,
                 title='Grid',
                 background='tan',
                 draw_fingers=False):
        assert (rows <= MAX_ROWS)
        assert (cols <= MAX_COLS)

        tk = Tk()
        tk.withdraw()
        top = Toplevel(tk)
        top.wm_title(title)
        top.protocol('WM_DELETE_WINDOW', top.destroy)

        self.width = width
        self.height = height
        self.rows = rows
        self.cols = cols
        self.canvas = Canvas(top,
                             width=self.width,
                             height=self.height,
                             background=background)
        self.canvas.pack()
        self.side = side
        self.block_buffer = block_buffer
        self.draw_fingers = draw_fingers
        self.cells = {}
        self.robot = []
        self.draw_environment()
Example #27
0
    def __init__(self, master):
        # Set main window's title
        master.title("ADNS3080ImageGrabber")

        frame = Frame(master)
        frame.grid(row=0, column=0)

        self.comPortStr = StringVar()
        ports = serial_ports()
        if not ports:
            ports = ['No serial ports found']
        self.comPortStr.set(ports[0])  # Set first port as default

        comports = apply(OptionMenu, (frame, self.comPortStr) + tuple(ports))
        comports.grid(row=0, column=0)

        self.baudrateStr = StringVar()
        self.baudrateStr.set('115200')

        baudrates = apply(OptionMenu, (frame, self.baudrateStr) + tuple(Serial.BAUDRATES))
        baudrates.grid(row=0, column=1)

        button = Button(frame, text="Open", command=self.open)
        button.grid(row=0, column=2)

        button = Button(frame, text="Close", command=self.close)
        button.grid(row=0, column=3)

        self.canvas = Canvas(master, width=self.grid_size*self.num_pixels, height=self.grid_size*self.num_pixels)
        self.canvas.grid(row=1)
Example #28
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)
Example #29
0
def plot(text, words, rowheight=15, rowwidth=800):
    """
    Generate a lexical dispersion plot.

    @param text: The source text
    @type text: C{list} or C{enum} of C{str}
    @param words: The target words
    @type words: C{list} of C{str}
    @param rowheight: Pixel height of a row
    @type rowheight: C{int}
    @param rowwidth: Pixel width of a row
    @type rowwidth: C{int}

    """
    canvas = Canvas(width=rowwidth, height=rowheight * len(words))
    text = list(text)
    scale = float(rowwidth) / len(text)
    position = 0
    for word in text:
        for i in range(len(words)):
            x = position * scale
            if word == words[i]:
                y = i * rowheight
                canvas.create_line(x, y, x, y + rowheight - 1)
        position += 1
    canvas.pack()
    canvas.mainloop()
Example #30
0
    def plot_results(self):
        grid_x = (self.canvas_width -
                  2 * self.canvas_margin) / (self.grid_size)
        grid_y = (self.canvas_height -
                  2 * self.canvas_margin) / (self.grid_size)
        pin_dx = grid_x / 6
        pin_dy = grid_y / 6

        master = Tk()

        w = Canvas(master, width=self.canvas_width, height=self.canvas_height)
        w.pack()

        for node in self.graph:
            i, j = self.id_to_coord(node)
            if node[-1] == 's':
                i += 0.5
                j += 0.5
            nx, ny = self.get_xy(i, j)
            if node[-1] == 's':
                fill_col = 'green'
                w.create_rectangle(nx - pin_dx,
                                   ny - pin_dy,
                                   nx + pin_dx,
                                   ny + pin_dy,
                                   fill=fill_col)
            else:
                fill_col = 'black'
                w.create_oval(nx - 2, ny - 2, nx + 2, ny + 2, fill=fill_col)

        self.draw_routes(w)

        w.update()
        w.postscript(file='sol35.ps', colormode='color')
        mainloop()