Ejemplo n.º 1
0
    def __init__(self, figure, master=None, resize_callback=None):
        FigureCanvasAgg.__init__(self, figure)
        self._idle = True
        self._idle_callback = None
        t1, t2, w, h = self.figure.bbox.bounds
        w, h = int(w), int(h)
        self._tkcanvas = Tk.Canvas(master=master,
                                   width=w,
                                   height=h,
                                   borderwidth=0,
                                   highlightthickness=0)
        self._tkphoto = Tk.PhotoImage(master=self._tkcanvas, width=w, height=h)
        self._tkcanvas.create_image(w // 2, h // 2, image=self._tkphoto)
        self._resize_callback = resize_callback
        self._tkcanvas.bind("<Configure>", self.resize)
        self._tkcanvas.bind("<Key>", self.key_press)
        self._tkcanvas.bind("<Motion>", self.motion_notify_event)
        self._tkcanvas.bind("<KeyRelease>", self.key_release)
        for name in "<Button-1>", "<Button-2>", "<Button-3>":
            self._tkcanvas.bind(name, self.button_press_event)
        for name in "<Double-Button-1>", "<Double-Button-2>", "<Double-Button-3>":
            self._tkcanvas.bind(name, self.button_dblclick_event)
        for name in "<ButtonRelease-1>", "<ButtonRelease-2>", "<ButtonRelease-3>":
            self._tkcanvas.bind(name, self.button_release_event)

        # Mouse wheel on Linux generates button 4/5 events
        for name in "<Button-4>", "<Button-5>":
            self._tkcanvas.bind(name, self.scroll_event)
        # Mouse wheel for windows goes to the window with the focus.
        # Since the canvas won't usually have the focus, bind the
        # event to the window containing the canvas instead.
        # See http://wiki.tcl.tk/3893 (mousewheel) for details
        root = self._tkcanvas.winfo_toplevel()
        root.bind("<MouseWheel>", self.scroll_event_windows, "+")

        # Can't get destroy events by binding to _tkcanvas. Therefore, bind
        # to the window and filter.
        def filter_destroy(evt):
            if evt.widget is self._tkcanvas:
                self.close_event()

        root.bind("<Destroy>", filter_destroy, "+")

        self._master = master
        self._tkcanvas.focus_set()
Ejemplo n.º 2
0
 def _createChartInit(self, text):
     w, h = self.tab_x[-1] + 20, self.tab_y[-1] + 20
     c = tkinter.Canvas(self.top_frame, width=w, height=h)
     c.pack(side='top', fill='both', expand=False, padx=20, pady=10)
     self.canvas = c
     # self.fg = c.cget("insertbackground")
     self.fg = c.option_get('foreground', '') or c.cget("insertbackground")
     #
     c.create_rectangle(2, 7, w, h, fill="", outline="#7f7f7f")
     label = tkinter.Label(c,
                           text=text,
                           font=self.font,
                           bd=0,
                           padx=3,
                           pady=1)
     dy = int(self.font_metrics['ascent']) - 10
     dy //= 2
     c.create_window(20, -dy, window=label, anchor="nw")
Ejemplo n.º 3
0
    def __init__(self, input_file, args_level, args_backend, args_display_view):
        """
        Constructor initializes the tkinter display with the IsyntaxFilePath.
        :param input_file: IsyntaxFilePath
        :param args_level: The requested level
        :param args_backend: The requested backend option
        """
        self._mouse_wheel_down, self._mouse_wheel_up = Constants.get_mouse_wheel()
        self._window = tk.Tk()
        if args_display_view:
            self._title = "Python iSyntax Viewer                File: {}                View: " \
                          "Display ".format(input_file)
        else:
            self._title = "Python iSyntax Viewer                File: {}                View: " \
                          "Source ".format(input_file)
        self._window.title(self._title)
        # Configuring self.windows geometry as primary monitors height and width
        self._window.geometry("{}x{}+200+100".format(str(self._window.winfo_screenwidth()),
                                                     str(self._window.winfo_screenheight())))
        self._canvas = tk.Canvas(self._window, background='black')
        
        self._canvas.pack(side='left', expand='yes', fill='both')

        self.menu = tk.Menu(self._window)
        self.menu.add_command(label="Thumbnail", command=self.show_macro_label_image)
        self.menu.add_command(label="Properties", command=self.show_properties)
        self._process_tiles = TileProcessor(input_file, args_level, args_backend, args_display_view)
        self.display_canvas()
        self.register_mouse_events()
        self._window.config(menu=self.menu)
        self._window.mainloop()  # Event processing loop
        self.macro_image_data = None
        self.label_image_data = None

        
        ######
        
        self.start=(0,0)
        self.end=(0,0)
Ejemplo n.º 4
0
    def run(self):
        """Set up the user interface."""
        width = self.width
        height = self.height

        # Build the UI
        self.parent = Tkinter.Tk()
        self.frame = frame = Tkinter.Frame(self.parent,
                                           width=width,
                                           height=height)
        frame.pack(fill=Tkinter.BOTH, expand=Tkinter.YES)
        self.canvas = canvas = Tkinter.Canvas(frame,
                                              width=self.GetFrameSize()[0],
                                              height=self.GetFrameSize()[1])

        canvas.pack(side=Tkinter.TOP, fill=Tkinter.BOTH, expand=Tkinter.YES)
        canvas.create_rectangle(0,
                                0,
                                self.GetMapSize()[0],
                                self.GetMapSize()[1],
                                fill='#888888')

        canvas.bind('<Button-1>', self.ClickHandler)
        canvas.bind('<ButtonRelease-1>', self.ReleaseHandler)
        # Button-4 and Button-5 are scroll wheel up/down events.
        canvas.bind('<Button-4>', functools.partial(self.Zoom, direction=1))
        canvas.bind('<Button-5>', functools.partial(self.Zoom, direction=-1))
        canvas.bind('<Double-Button-1>',
                    functools.partial(self.Zoom, direction=1))
        frame.bind('<Configure>', self.ResizeHandler)
        frame.bind_all('<Key>', self.KeypressHandler)

        def SetReady():
            self.ready = True

        self.parent.after_idle(SetReady)
        self.parent.mainloop()
Ejemplo n.º 5
0
    def __init__(self, session, root=tk.Tk()):
        """
            Main visualisation class. Builds an interactive map of the London tube.
            :param root:
            :param client:
        """
        start_time = datetime.datetime.now()

        self._root = root
        self._session = session
        self.w, self.h = self._root.winfo_screenwidth(
        ), self._root.winfo_screenheight()
        self._root.geometry("%dx%d+0+0" % (self.w, self.h))
        self._root.focus_set()
        self._root.bind("<Escape>", lambda e: e.widget.quit())
        self._root.bind("<Key>", self._key_handler)
        self._root.title('London Tube Map')

        self._canvas = tk.Canvas(self._root)
        self._canvas.bind("<ButtonPress-1>", self._scan_start)
        self._canvas.bind("<ButtonRelease-1>", self._scan_stop)
        self._canvas.bind("<B1-Motion>", self._scan_move)
        self._canvas.pack(fill=tk.BOTH,
                          expand=1)  # Stretch canvas to root window size.

        # We want to scale the longitude and lonitude to fit the image
        # To do this we need the minimum and maximum of the longitude and latitude,
        # we can query for this easily in Grakn!
        with session.transaction().read() as transaction:
            self.min_lat = list(
                execute_and_log(self.COMPUTE_MIN_LAT,
                                transaction))[0].number()
            self.max_lat = list(
                execute_and_log(self.COMPUTE_MAX_LAT,
                                transaction))[0].number()
            self.min_lon = list(
                execute_and_log(self.COMPUTE_MIN_LON,
                                transaction))[0].number()
            self.max_lon = list(
                execute_and_log(self.COMPUTE_MAX_LON,
                                transaction))[0].number()

        # aspect ratio as width over height, which is longitude over latitude
        aspect_ratio = (self.max_lon - self.min_lon) / (self.max_lat -
                                                        self.min_lat)
        self.new_width = self.w
        self.new_height = self.new_width / aspect_ratio

        self._draw_river_thames()

        # We need to associate the id of the station entity in Grakn to the rendered dot on the screen, so that we can
        # find the Grakn id of a station that is clicked on
        self._station_point_ids = dict()
        # Also store the station coords so that we don't have to query Grakn for them again
        self._station_canvas_coords = dict()
        self._station_centrality_points = dict()

        self._draw()

        # self._draw_stations()

        # ===== Event state variables =====
        self._displaying_centrality = False
        self._scale = 1
        self._shortest_path_stations = []
        self._shortest_path_elements = []
        self._scan_delta = (0, 0)
        self._x_pos = 0
        self._y_pos = 0
        self._scanning = False

        end_time = datetime.datetime.now()
        print("- - - - - -\nTime taken: " + str(end_time - start_time))
 def __init__(self, parent, title, cardset, images, **kw):
     kw = self.initKw(kw)
     MfxDialog.__init__(self, parent, title, kw.resizable, kw.default)
     top_frame, bottom_frame = self.createFrames(kw)
     self.createBitmaps(top_frame, kw)
     frame = tkinter.Frame(top_frame)
     frame.pack(fill="both", expand=True, padx=5, pady=10)
     #
     #
     info_frame = tkinter.LabelFrame(frame, text=_('About cardset'))
     info_frame.grid(row=0,
                     column=0,
                     columnspan=2,
                     sticky='ew',
                     padx=0,
                     pady=5,
                     ipadx=5,
                     ipady=5)
     styles = nationalities = year = None
     if cardset.si.styles:
         styles = '\n'.join([CSI.STYLE[i] for i in cardset.si.styles])
     if cardset.si.nationalities:
         nationalities = '\n'.join(
             [CSI.NATIONALITY[i] for i in cardset.si.nationalities])
     if cardset.year:
         year = str(cardset.year)
     row = 0
     for n, t in (
             # ('Version:', str(cardset.version)),
         (_('Type:'), CSI.TYPE[cardset.type]),
         (_('Styles:'), styles),
         (_('Nationality:'), nationalities),
         (_('Year:'), year),
             # (_('Number of cards:'), str(cardset.ncards)),
         (_('Size:'), '%d x %d' % (cardset.CARDW, cardset.CARDH)),
     ):
         if t is not None:
             label = tkinter.Label(info_frame,
                                   text=n,
                                   anchor='w',
                                   justify='left')
             label.grid(row=row, column=0, sticky='nw')
             label = tkinter.Label(info_frame,
                                   text=t,
                                   anchor='w',
                                   justify='left')
             label.grid(row=row, column=1, sticky='nw')
             row += 1
     if images:
         try:
             from random import choice
             im = choice(images)
             f = os.path.join(cardset.dir, cardset.backname)
             self.back_image = loadImage(file=f)
             canvas = tkinter.Canvas(info_frame,
                                     width=2 * im.width() + 30,
                                     height=im.height() + 2)
             canvas.create_image(10, 1, image=im, anchor='nw')
             canvas.create_image(im.width() + 20,
                                 1,
                                 image=self.back_image,
                                 anchor='nw')
             canvas.grid(row=0, column=2, rowspan=row + 1, sticky='ne')
             info_frame.columnconfigure(2, weight=1)
             info_frame.rowconfigure(row, weight=1)
         except Exception:
             pass
     # bg = top_frame["bg"]
     bg = 'white'
     text_w = tkinter.Text(frame,
                           bd=1,
                           relief="sunken",
                           wrap="word",
                           padx=4,
                           width=64,
                           height=16,
                           bg=bg)
     text_w.grid(row=1, column=0, sticky='nsew')
     sb = tkinter.Scrollbar(frame)
     sb.grid(row=1, column=1, sticky='ns')
     text_w.configure(yscrollcommand=sb.set)
     sb.configure(command=text_w.yview)
     frame.columnconfigure(0, weight=1)
     frame.rowconfigure(1, weight=1)
     #
     text = ''
     f = os.path.join(cardset.dir, "COPYRIGHT")
     try:
         text = open(f).read()
     except Exception:
         pass
     if text:
         text_w.config(state="normal")
         text_w.insert("insert", text)
     text_w.config(state="disabled")
     #
     focus = self.createButtons(bottom_frame, kw)
     # focus = text_w
     self.mainloop(focus, kw.timeout)
Ejemplo n.º 7
0
    def __init__(self, dialog, parent, app, player, gameid, **kw):
        ttk.Frame.__init__(self, parent)

        self.mapped = False

        self.dialog = dialog
        self.app = app
        self.player = player
        self.gameid = gameid
        self.items = []
        self.formatter = ProgressionFormatter(app, player, gameid)

        frame = ttk.Frame(self)
        frame.pack(expand=True, fill='both', padx=5, pady=10)
        frame.columnconfigure(0, weight=1)

        # constants
        w = dialog.tkfont.measure('M') * 42
        w = max(w, 500)
        w = min(w, 600)
        self.canvas_width, self.canvas_height = w, 325
        cond = parent.winfo_screenwidth() < 800 or \
            parent.winfo_screenheight() < 600
        if cond:
            self.canvas_width, self.canvas_height = 400, 200
        self.xmargin, self.ymargin = 10, 10
        self.graph_dx, self.graph_dy = 10, 10
        self.played_color = '#ff7ee9'
        self.won_color = '#00dc28'
        self.percent_color = 'blue'
        # create canvas
        self.canvas = canvas = tkinter.Canvas(frame, bg='#dfe8ff', bd=0,
                                              highlightthickness=1,
                                              highlightbackground='black',
                                              width=self.canvas_width,
                                              height=self.canvas_height)
        canvas.pack(side='left', padx=5)

        # right frame
        right_frame = ttk.Frame(frame)
        right_frame.pack(side='left', fill='x', padx=5)
        self.all_games_variable = var = tkinter.StringVar()
        var.set('all')
        b = ttk.Radiobutton(right_frame, text=_('All games'),
                            variable=var, value='all',
                            command=self.updateGraph)
        b.pack(fill='x', expand=True, padx=3, pady=1)
        b = ttk.Radiobutton(right_frame, text=_('Current game'),
                            variable=var, value='current',
                            command=self.updateGraph)
        b.pack(fill='x', expand=True, padx=3, pady=1)

        label_frame = ttk.LabelFrame(right_frame, text=_('Statistics for'))
        label_frame.pack(side='top', fill='x', pady=5)
        self.variable = var = tkinter.StringVar()
        var.set('week')
        for v, t in (
            ('week',  _('Last 7 days')),
            ('month', _('Last month')),
            ('year',  _('Last year')),
            ('all',   _('All time')),
                ):
            b = ttk.Radiobutton(label_frame, text=t, variable=var,
                                value=v, command=self.updateGraph)
            b.pack(fill='x', expand=True, padx=3, pady=1)

        label_frame = ttk.LabelFrame(right_frame, text=_('Show graphs'))
        label_frame.pack(side='top', fill='x', pady=5)
        self.played_graph_var = tkinter.BooleanVar()
        self.played_graph_var.set(True)
        b = ttk.Checkbutton(label_frame, text=_('Played'),
                            command=self.updateGraph,
                            variable=self.played_graph_var)
        b.pack(fill='x', expand=True, padx=3, pady=1)
        self.won_graph_var = tkinter.BooleanVar()
        self.won_graph_var.set(True)
        b = ttk.Checkbutton(label_frame, text=_('Won'),
                            command=self.updateGraph,
                            variable=self.won_graph_var)
        b.pack(fill='x', expand=True, padx=3, pady=1)
        self.percent_graph_var = tkinter.BooleanVar()
        self.percent_graph_var.set(True)
        b = ttk.Checkbutton(label_frame, text=_('% won'),
                            command=self.updateGraph,
                            variable=self.percent_graph_var)
        b.pack(fill='x', expand=True, padx=3, pady=1)

        label_frame = ttk.LabelFrame(right_frame, text=_('Date format'))
        label_frame.pack(side='top', fill='x', pady=5)
        self.date_format = tkinter.StringVar()
        self.date_format.set(self.app.opt.date_format)
        b = ttk.Radiobutton(label_frame, text=_('MM-DD'),
                            command=self.updateDateFormat,
                            variable=self.date_format,
                            value='%m-%d')
        b.pack(fill='x', expand=True, padx=3, pady=1)
        b = ttk.Radiobutton(label_frame, text=_('DD-MM'),
                            command=self.updateDateFormat,
                            variable=self.date_format,
                            value='%d-%m')
        b.pack(fill='x', expand=True, padx=3, pady=1)

        # self.createGraph()
        bind(canvas, '<Map>', self.createGraph)
Ejemplo n.º 8
0
    def __init__(self, dm, master=None, *args, **kwargs):
        tkinter.Frame.__init__(self, master, *args, **kwargs)

        self.dm = dm
        n = dm.n_actuators
        self.dm_pattern = numpy.full((n), 0.5)

        ## We have a lot of Scales so we want a scrollbar.  For this,
        ## create a Canvas and insert the Scales inside.  The Scrollbar is
        ## associated with the canvas and controls the Canvas window.
        ## However, we would be forced to manage the position of the
        ## Scales inside the Canvas so instead we create another Frame to
        ## hold the Scales and place that Frame inside the Canvas.
        ##
        ## This is because in tk, scrollbars are their own widgets that
        ## are associated to other widgets.  They can only be associated
        ## with a small set of Widgets, the ones that support the standard
        ## scrollbar interface, such as Listbox, Text, Canvas, and Entry.
        ## So we can't associated the Scrollbar directly with a Frame.

        self.canvas = tkinter.Canvas(self)
        self.canvas_frame = tkinter.Frame(self.canvas)

        zero_button = tkinter.Button(self.canvas_frame,
                                     text="Set all actuators to 0.5",
                                     command=self.zero)
        zero_button.pack(fill='x')
        self.zero_button = zero_button

        self.sliders = [None] * n
        for i in range(n):
            callback = lambda s, i=i: self.set_actuator(i, float(s))
            slider = tkinter.Scale(self.canvas_frame,
                                   orient='horizontal',
                                   from_=0,
                                   to=1,
                                   resolution=0.01,
                                   label="actuator #%i" % i,
                                   command=callback)
            slider.set(0.5)
            slider.pack(fill='x')
            self.sliders[i] = slider

        self.canvas.pack(side='left', fill='both', expand=True)

        self.scrollbar = tkinter.Scrollbar(self.canvas,
                                           command=self.canvas.yview)
        self.scrollbar.pack(side='right', fill='y')

        self.canvas.configure(yscrollcommand=self.scrollbar.set,
                              scrollregion=self.canvas.bbox('all'))

        self.canvas_window = self.canvas.create_window(
            (0, 0), window=self.canvas_frame, anchor='nw')

        ## Moving scrollbar will trigger configure on canvas_frame.
        ## Resizing DeformableMirror Frame on the Y axis will trigger canvas.
        ## Resizing DeformableMirror Frame on the X axis will trigger both
        ## canvas and canvas_frame.
        self.canvas.bind('<Configure>', self.on_canvas_configure)
        self.canvas_frame.bind('<Configure>', self.on_canvas_frame_configure)
Ejemplo n.º 9
0
    def __init__(self, parent, title, app, player, gameid, **kw):

        font_name = app.getFont('default')
        font = tkinter_font.Font(parent, font_name)
        tkfont = tkinter_font.Font(parent, font)
        font_metrics = font.metrics()
        measure = tkfont.measure
        self.text_height = font_metrics['linespace']
        self.text_width = measure('XX.XX.XX')

        self.items = []
        self.formatter = ProgressionFormatter(app, player, gameid)

        kw = self.initKw(kw)
        MfxDialog.__init__(self, parent, title, kw.resizable, kw.default)
        top_frame, bottom_frame = self.createFrames(kw)
        self.createBitmaps(top_frame, kw)

        frame = tkinter.Frame(top_frame)
        frame.pack(expand=True, fill='both', padx=5, pady=10)
        frame.columnconfigure(0, weight=1)

        # constants
        self.canvas_width, self.canvas_height = 600, 250
        if parent.winfo_screenwidth() < 800 or \
                parent.winfo_screenheight() < 600:
            self.canvas_width, self.canvas_height = 400, 200
        self.xmargin, self.ymargin = 10, 10
        self.graph_dx, self.graph_dy = 10, 10
        self.played_color = '#ff7ee9'
        self.won_color = '#00dc28'
        self.percent_color = 'blue'
        # create canvas
        self.canvas = canvas = tkinter.Canvas(frame,
                                              bg='#dfe8ff',
                                              highlightthickness=1,
                                              highlightbackground='black',
                                              width=self.canvas_width,
                                              height=self.canvas_height)
        canvas.pack(side='left', padx=5)
        #
        dir = os.path.join('images', 'stats')
        try:
            fn = app.dataloader.findImage('progression', dir)
            self.bg_image = loadImage(fn)
            canvas.create_image(0, 0, image=self.bg_image, anchor='nw')
        except Exception:
            pass
        #
        tw = max(measure(_('Games/day')), measure(_('Games/week')),
                 measure(_('% won')))
        self.left_margin = self.xmargin + tw // 2
        self.right_margin = self.xmargin + tw // 2
        self.top_margin = 15 + self.text_height
        self.bottom_margin = 15 + self.text_height + 10 + self.text_height
        #
        x0, y0 = self.left_margin, self.canvas_height - self.bottom_margin
        x1, y1 = self.canvas_width - self.right_margin, self.top_margin
        canvas.create_rectangle(x0, y0, x1, y1, fill='white')
        # horizontal axis
        canvas.create_line(x0, y0, x1, y0, width=3)

        # left vertical axis
        canvas.create_line(x0, y0, x0, y1, width=3)
        t = _('Games/day')
        self.games_text_id = canvas.create_text(x0 - 4,
                                                y1 - 4,
                                                anchor='s',
                                                text=t)

        # right vertical axis
        canvas.create_line(x1, y0, x1, y1, width=3)
        canvas.create_text(x1 + 4, y1 - 4, anchor='s', text=_('% won'))

        # caption
        d = self.text_height
        x, y = self.xmargin, self.canvas_height - self.ymargin
        canvas.create_rectangle(x,
                                y,
                                x + d,
                                y - d,
                                outline='black',
                                fill=self.played_color)
        x += d + 5
        canvas.create_text(x, y, anchor='sw', text=_('Played'))
        x += measure(_('Played')) + 20
        canvas.create_rectangle(x,
                                y,
                                x + d,
                                y - d,
                                outline='black',
                                fill=self.won_color)
        x += d + 5
        canvas.create_text(x, y, anchor='sw', text=_('Won'))
        x += measure(_('Won')) + 20
        canvas.create_rectangle(x,
                                y,
                                x + d,
                                y - d,
                                outline='black',
                                fill=self.percent_color)
        x += d + 5
        canvas.create_text(x, y, anchor='sw', text=_('% won'))

        # right frame
        right_frame = tkinter.Frame(frame)
        right_frame.pack(side='left', fill='x', padx=5)
        self.all_games_variable = var = tkinter.StringVar()
        var.set('all')
        b = tkinter.Radiobutton(right_frame,
                                text=_('All games'),
                                variable=var,
                                value='all',
                                command=self.updateGraph,
                                justify='left',
                                anchor='w')
        b.pack(fill='x', expand=True, padx=3, pady=1)
        b = tkinter.Radiobutton(right_frame,
                                text=_('Current game'),
                                variable=var,
                                value='current',
                                command=self.updateGraph,
                                justify='left',
                                anchor='w')
        b.pack(fill='x', expand=True, padx=3, pady=1)
        label_frame = tkinter.LabelFrame(right_frame, text=_('Statistics for'))
        label_frame.pack(side='top', fill='x', pady=10)
        self.variable = var = tkinter.StringVar()
        var.set('week')
        for v, t in (
            ('week', _('Last 7 days')),
            ('month', _('Last month')),
            ('year', _('Last year')),
            ('all', _('All time')),
        ):
            b = tkinter.Radiobutton(label_frame,
                                    text=t,
                                    variable=var,
                                    value=v,
                                    command=self.updateGraph,
                                    justify='left',
                                    anchor='w')
            b.pack(fill='x', expand=True, padx=3, pady=1)
        label_frame = tkinter.LabelFrame(right_frame, text=_('Show graphs'))
        label_frame.pack(side='top', fill='x')
        self.played_graph_var = tkinter.BooleanVar()
        self.played_graph_var.set(True)
        b = tkinter.Checkbutton(label_frame,
                                text=_('Played'),
                                command=self.updateGraph,
                                variable=self.played_graph_var,
                                justify='left',
                                anchor='w')
        b.pack(fill='x', expand=True, padx=3, pady=1)
        self.won_graph_var = tkinter.BooleanVar()
        self.won_graph_var.set(True)
        b = tkinter.Checkbutton(label_frame,
                                text=_('Won'),
                                command=self.updateGraph,
                                variable=self.won_graph_var,
                                justify='left',
                                anchor='w')
        b.pack(fill='x', expand=True, padx=3, pady=1)
        self.percent_graph_var = tkinter.BooleanVar()
        self.percent_graph_var.set(True)
        b = tkinter.Checkbutton(label_frame,
                                text=_('% won'),
                                command=self.updateGraph,
                                variable=self.percent_graph_var,
                                justify='left',
                                anchor='w')
        b.pack(fill='x', expand=True, padx=3, pady=1)

        self.updateGraph()

        focus = self.createButtons(bottom_frame, kw)
        self.mainloop(focus, kw.timeout)
Ejemplo n.º 10
0
 def createWidgets(self):
   """ Create the widgets of the main window with their layout and also the zoom window and parameter window
   """
   #
   #self.frame_canvas = Tkinter.Frame(self.frame_a)
   ##self.frame_canvas.pack(side=Tkinter.TOP)
   #self.frame_canvas.grid(column=0, row=0, sticky=Tkinter.W + Tkinter.N + Tkinter.E + Tkinter.S)
   #self.frame_canvas.columnconfigure(0, weight=1)
   #self.frame_canvas.rowconfigure(0, weight=1)
   #
   #self.canvas_a =  Tkinter.Canvas(self.frame_a, width=self.canvas_a_width, height=self.canvas_a_height)
   self.canvas_a =  tkinter.Canvas(self.frame_a, width=initial_tkinter_canvas_width, height=initial_tkinter_canvas_height)
   #self.canvas_a.pack(fill=Tkinter.BOTH, expand=1)
   self.canvas_a.grid(column=0, row=0, sticky=tkinter.N+tkinter.E+tkinter.S+tkinter.W)
   self.canvas_a.columnconfigure(0, weight=1)
   self.canvas_a.rowconfigure(0, weight=1)
   self.canvas_a.bind("<ButtonPress-1>", self.action_canvas_a_mouse_button_press)
   self.canvas_a.bind("<B1-Motion>", self.action_canvas_a_mouse_button_motion)
   self.canvas_a.bind("<ButtonRelease-1>", self.action_canvas_a_mouse_button_release)
   #
   self.frame_control = tkinter.Frame(self.frame_a)
   #self.frame_control.pack(side=Tkinter.BOTTOM)
   self.frame_control.grid(column=0, row=1, sticky=tkinter.W + tkinter.S)
   #
   self.frame_button_speed = tkinter.Frame(self.frame_control)
   self.frame_button_speed.grid(column=0, row=0)
   #
   self.button_fast_backward = tkinter.Button(self.frame_button_speed)
   self.button_fast_backward["text"] = "<<-",
   self.button_fast_backward["command"] = self.action_button_fast_backward
   self.button_fast_backward.pack(side=tkinter.LEFT)
   #
   self.button_slow_backward = tkinter.Button(self.frame_button_speed)
   self.button_slow_backward["text"] = "<-",
   self.button_slow_backward["command"] = self.action_button_slow_backward
   self.button_slow_backward.pack(side=tkinter.LEFT)
   #
   self.button_step_backward = tkinter.Button(self.frame_button_speed)
   self.button_step_backward["text"] = "<|",
   self.button_step_backward["command"] = self.action_button_step_backward
   self.button_step_backward.pack(side=tkinter.LEFT)
   #
   self.button_stop = tkinter.Button(self.frame_button_speed)
   self.button_stop["foreground"]   = "red"
   self.button_stop["text"] = "||",
   self.button_stop["command"] = self.action_button_stop
   self.button_stop.pack(side=tkinter.LEFT)
   #
   self.button_step_forward = tkinter.Button(self.frame_button_speed)
   self.button_step_forward["text"] = "|>",
   self.button_step_forward["command"] = self.action_button_step_forward
   self.button_step_forward.pack(side=tkinter.LEFT)
   #
   self.button_slow_forward = tkinter.Button(self.frame_button_speed)
   self.button_slow_forward["text"] = "->",
   self.button_slow_forward["command"] = self.action_button_slow_forward
   self.button_slow_forward.pack(side=tkinter.LEFT)
   #
   self.button_fast_forward = tkinter.Button(self.frame_button_speed)
   self.button_fast_forward["text"] = "->>",
   self.button_fast_forward["command"] = self.action_button_fast_forward
   self.button_fast_forward.pack(side=tkinter.LEFT)
   #
   self.frame_label = tkinter.Frame(self.frame_control)
   self.frame_label.grid(column=0, row=1, sticky=tkinter.W)
   #
   self.label_angle = tkinter.Label(self.frame_label)
   self.label_angle["textvariable"] = self.label1_content
   #self.label_angle.pack(side=Tkinter.TOP)
   #self.label_angle.pack(anchor=Tkinter.NW)
   self.label_angle.grid(column=0, row=0, sticky=tkinter.W)
   #
   self.label_angle_speed = tkinter.Label(self.frame_label)
   self.label_angle_speed["textvariable"] = self.label2_content
   #self.label_angle_speed.pack(side=Tkinter.BOTTOM)
   #self.label_angle_speed.pack(anchor=Tkinter.SW)
   self.label_angle_speed.grid(column=0, row=1, sticky=tkinter.W)
   #
   self.frame_button_options = tkinter.Frame(self.frame_control)
   self.frame_button_options.grid(column=0, row=2, sticky=tkinter.W+tkinter.S)
   #
   self.button_zoom = tkinter.Button(self.frame_button_options)
   self.button_zoom["text"] = "Zoom",
   self.button_zoom["command"] = self.action_button_zoom
   self.button_zoom.pack(side=tkinter.LEFT)
   #
   self.button_overlay = tkinter.Button(self.frame_button_options)
   self.button_overlay["text"] = "Overlay",
   self.button_overlay["command"] = self.action_button_overlay
   self.button_overlay.pack(side=tkinter.LEFT)
   #
   self.button_parameter = tkinter.Button(self.frame_button_options)
   self.button_parameter["text"] = "Parameters",
   self.button_parameter["command"] = self.action_button_parameters
   self.button_parameter.pack(side=tkinter.LEFT)
   #
   self.button_graph = tkinter.Button(self.frame_button_options)
   self.button_graph["text"] = "Graph",
   #self.button_graph["command"] = lambda a=1: self.action_button_check_event(a)
   #self.button_graph.bind("<Button-1>", lambda event: self.action_button_check_event(event))
   #self.button_graph.bind("<Button-1>", self.action_button_check_event) # the event argument is added by default
   self.button_graph.bind("<Button-1>", self.action_button_curve_graph) # the event argument is added by default
   self.button_graph.pack(side=tkinter.LEFT)
   #
   self.button_quit = tkinter.Button(self.frame_button_options)
   self.button_quit["text"] = "Quit",
   #self.button_quit["command"] = self.frame_a.quit
   #self.button_quit["command"] = self.tktop.destroy
   self.button_quit["command"] = self.quit_Two_Canvas
   self.button_quit.pack(side=tkinter.LEFT)
   #
   ## second window with canvas_b
   self.create_zoom_frame()
   self.show_zoom_frame()
   #
   ## third window with parameter text
   self.create_parameter_frame()
   self.hide_parameter_frame()
Ejemplo n.º 11
0
def create_widgets():
    global list_box, canvas, label, zoom_label
    #
    root = tkinter.Tk()
    #
    list_box = tkinter.Listbox(root, exportselection=False)
    list_box.grid(row=0, column=0, rowspan=2, sticky=tkinter.NS)
    cardsets_list = list(cardsets_dict)
    cardsets_list.sort()
    for cs in cardsets_list:
        list_box.insert(tkinter.END, cs)
    list_box.bind('<<ListboxSelect>>', show_cardset)
    #
    sb = tkinter.Scrollbar(root)
    sb.grid(row=0, column=1, rowspan=2, sticky=tkinter.NS)
    list_box.config(yscrollcommand=sb.set)
    sb.config(command=list_box.yview)
    #
    canvas = tkinter.Canvas(root, bg='#5eab6b')
    canvas.grid(row=0, column=2, sticky=tkinter.NSEW)
    canvas.bind('<4>', lambda e: canvas.yview_scroll(-5, 'unit'))
    canvas.bind('<5>', lambda e: canvas.yview_scroll(5, 'unit'))
    #
    sb = tkinter.Scrollbar(root)
    sb.grid(row=0, column=3, sticky=tkinter.NS)
    canvas.config(yscrollcommand=sb.set)
    sb.config(command=canvas.yview)
    #
    if True:
        sb = tkinter.Scrollbar(root, orient=tkinter.HORIZONTAL)
        sb.grid(row=1, column=2, sticky=tkinter.EW)
        canvas.config(xscrollcommand=sb.set)
        sb.config(command=canvas.xview)
    #
    label = tkinter.Label(root)
    label.grid(row=2, column=0, columnspan=4)
    #
    b_frame = tkinter.Frame(root)
    b_frame.grid(row=3, column=0, columnspan=4, sticky=tkinter.EW)
    button = tkinter.Button(b_frame, text='Quit', command=root.quit, width=8)
    button.pack(side=tkinter.RIGHT)
    button = tkinter.Button(b_frame, text='Info', command=show_info, width=8)
    button.pack(side=tkinter.RIGHT)
    if Image:
        global rotate_var, filter_var
        rotate_var = tkinter.IntVar(root)
        filter_var = tkinter.StringVar(root)
        button = tkinter.Button(b_frame, text='  +  ', command=zoom_in)
        button.pack(side=tkinter.LEFT)
        button = tkinter.Button(b_frame, text='  -  ', command=zoom_out)
        button.pack(side=tkinter.LEFT)
        button = tkinter.Button(b_frame, text='  =  ', command=zoom_cancel)
        button.pack(side=tkinter.LEFT)
        button = tkinter.Checkbutton(b_frame,
                                     text='Rotate',
                                     indicatoron=0,
                                     selectcolor=b_frame['bg'],
                                     width=8,
                                     variable=rotate_var,
                                     command=show_cardset)
        button.pack(side=tkinter.LEFT, fill='y')
        om = tkinter.OptionMenu(b_frame,
                                filter_var,
                                'NEAREST',
                                'BILINEAR',
                                'BICUBIC',
                                'ANTIALIAS',
                                command=show_cardset)
        filter_var.set('NEAREST')
        om.pack(side=tkinter.LEFT, fill='y')

        zoom_label = tkinter.Label(b_frame)
        zoom_label.pack(side=tkinter.LEFT)
    #
    root.columnconfigure(2, weight=1)
    root.rowconfigure(0, weight=1)

    root.title('Show Cardsets')

    return root
Ejemplo n.º 12
0
    def make_expts_tab(self, parent):
        """Build a tab for setting experiment info."""
        expt_frame = ttk.Frame(parent)
        # Control pane along the top
        frame = ttk.Frame(expt_frame)

        ttk.Label(frame, text='Edit experiment:').grid(row=0,
                                                       column=0,
                                                       sticky='e')
        experiment = ttk.Combobox(frame,
                                  state='readonly',
                                  width=15,
                                  values=sorted(
                                      self.metadata['experiments'].keys()))
        experiment.bind(
            '<<ComboboxSelected>>',
            lambda e: self.update_expts_tab(expt_id=experiment.get()))
        experiment.grid(row=0, column=1, sticky='w')
        self.experiment_shown = None
        self.experiment_selector = experiment

        ttk.Label(frame, text='Clone experiment as:').grid(row=1,
                                                           column=0,
                                                           sticky='e')
        clone_var = T.StringVar()
        ttk.Entry(frame, textvariable=clone_var, width=15).grid(row=1,
                                                                column=1,
                                                                sticky='we')
        self.clone_expt_button = ttk.Button(
            frame,
            text='Clone',
            command=lambda: self.add_expt(clone_var.get(),
                                          clone=experiment.get()))
        self.clone_expt_button.grid(row=1, column=2, sticky='w')
        if not self.metadata['experiments']:
            self.clone_expt_button.state(['disabled'])

        ttk.Label(frame, text='Add experiment:').grid(row=2,
                                                      column=0,
                                                      sticky='e')
        add_var = T.StringVar()
        ttk.Entry(frame, textvariable=add_var, width=15).grid(row=2,
                                                              column=1,
                                                              sticky='we')
        ttk.Button(frame,
                   text='Add',
                   command=lambda: self.add_expt(add_var.get())).grid(
                       row=2, column=2, sticky='w')

        frame.columnconfigure(0, weight=1)  # Expand at the sides
        frame.columnconfigure(3, weight=1)
        frame.pack(side='top', fill='x', expand=True)
        # Experiment property editing below the control pane; frame per 'item',
        # all in a scrolling canvas
        self.expts_canvas = canvas = T.Canvas(expt_frame, borderwidth=0)
        canvas.pack(side='left', fill='both', expand=True)
        frame = ttk.Frame(canvas)
        scrollbar = ttk.Scrollbar(expt_frame,
                                  orient='vertical',
                                  command=canvas.yview)
        scrollbar.pack(side='right', fill='y')
        canvas.configure(yscrollcommand=scrollbar.set)
        canvas.create_window((0, 0), window=frame, anchor='nw')
        frame.bind("<Configure>", self.on_expts_frame_configure)
        # The contents
        self.expts_boxes = {}
        self.make_expts_part(frame, 'description')
        self.make_expts_part(frame, 'optophysiology')
        self.make_stim_frame(frame)
        for part in [
                'data_collection', 'pharmacology', 'protocol', 'slices',
                'stimulus', 'subject', 'surgery', 'virus',
                'related_publications', 'notes'
        ]:
            self.make_expts_part(frame, part)
        # Show current experiment, if any
        if self.metadata['experiments']:
            experiment.set(experiment['values'][0])
            self.update_expts_tab(expt_id=experiment.get())
        # Add to tabs
        parent.add(expt_frame, text='Experiments')
        return expt_frame