def __init__(self, parent, title, app, **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)
     self.app = app
     #
     self.update_stats_var = tkinter.BooleanVar()
     self.update_stats_var.set(app.opt.update_player_stats != 0)
     self.confirm_var = tkinter.BooleanVar()
     self.confirm_var.set(app.opt.confirm != 0)
     self.win_animation_var = tkinter.BooleanVar()
     self.win_animation_var.set(app.opt.win_animation != 0)
     #
     frame = tkinter.Frame(top_frame)
     frame.pack(expand=True, fill='both', padx=5, pady=10)
     widget = tkinter.Label(
         frame,
         text=_("\nPlease enter your name"),
         # justify='left', anchor='w',
         takefocus=0)
     widget.grid(row=0, column=0, columnspan=2, sticky='ew', padx=0, pady=5)
     w = kw.get("e_width", 30)  # width in characters
     self.player_var = tkinter.Entry(frame, exportselection=1, width=w)
     self.player_var.insert(0, app.opt.player)
     self.player_var.grid(row=1, column=0, sticky='ew', padx=0, pady=5)
     widget = tkinter.Button(frame,
                             text=_('Choose...'),
                             command=self.selectUserName)
     widget.grid(row=1, column=1, padx=5, pady=5)
     widget = tkinter.Checkbutton(frame,
                                  variable=self.confirm_var,
                                  anchor='w',
                                  text=_("Confirm quit"))
     widget.grid(row=2, column=0, columnspan=2, sticky='ew', padx=0, pady=5)
     widget = tkinter.Checkbutton(frame,
                                  variable=self.update_stats_var,
                                  anchor='w',
                                  text=_("Update statistics and logs"))
     widget.grid(row=3, column=0, columnspan=2, sticky='ew', padx=0, pady=5)
     #  widget = tkinter.Checkbutton(frame, variable=self.win_animation_var,
     #                               text="Win animation")
     #  widget.pack(side='top', padx=kw.padx, pady=kw.pady)
     frame.columnconfigure(0, weight=1)
     #
     self.player = self.player_var.get()
     self.confirm = self.confirm_var.get()
     self.update_stats = self.update_stats_var.get()
     self.win_animation = self.win_animation_var.get()
     #
     focus = self.createButtons(bottom_frame, kw)
     self.mainloop(focus, kw.timeout)
Beispiel #2
0
    def _Button(self, text, image_file, toggle, frame):
        if image_file is not None:
            im = Tk.PhotoImage(master=self, file=image_file)
        else:
            im = None

        if not toggle:
            b = Tk.Button(master=frame,
                          text=text,
                          padx=2,
                          pady=2,
                          image=im,
                          command=lambda: self._button_click(text))
        else:
            # There is a bug in tkinter included in some python 3.6 versions
            # that without this variable, produces a "visual" toggling of
            # other near checkbuttons
            # https://bugs.python.org/issue29402
            # https://bugs.python.org/issue25684
            var = Tk.IntVar()
            b = Tk.Checkbutton(master=frame,
                               text=text,
                               padx=2,
                               pady=2,
                               image=im,
                               indicatoron=False,
                               command=lambda: self._button_click(text),
                               variable=var)
        b._ntimage = im
        b.pack(side=Tk.LEFT)
        return b
Beispiel #3
0
    def body(self, master):
        tk.Label(master, text='Connection name:').grid(row=0)
        tk.Label(master, text='Catalog type:').grid(row=1)
        tk.Label(master, text='Root path:').grid(row=2)

        self.name = ttk.Entry(master)
        self.name.grid(row=0, column=1, sticky='ew')
        self.name.insert(0, self.connection_name)

        self.catalog_cbox = ttk.Combobox(master, values=config.catalog_types)
        self.catalog_cbox.grid(row=1, column=1, sticky='ew')
        self.catalog_cbox.set(self.catalog_type)

        self.root_path_entry = tk.Entry(master)
        self.root_path_entry.grid(row=2, column=1, sticky='ew')
        self.root_path_entry.insert(0, self.root_path)

        self.isdefault_var = tk.IntVar()
        self.isdefault_var.set(self.isdefault)
        self.set_default = tk.Checkbutton(master,
                                          text='make default connection',
                                          variable=self.isdefault_var)
        self.set_default.grid(row=3, column=1)

        self.catalog_config_frame = tk.Frame(master)
        self.catalog_config_frame.grid(row=4, sticky='nsew')

        self.catalog_type_changed(catalog_config=self.catalog_config)
        self.catalog_cbox.bind('<<ComboboxSelected>>',
                               self.catalog_type_changed)

        self.result = None
Beispiel #4
0
    def __init__(self, master, cfg, columns_def):
        tk.Frame.__init__(self, master)

        self.cfg = cfg
        self.columns_def = columns_def

        if 'display_columns' not in self.cfg[config.SETTINGS]:
            dcols = [k for k in self.columns_def.keys() if k != '#0']
            self.cfg[config.SETTINGS]['display_columns'] = ','.join(dcols)

        displayed = self.cfg[config.SETTINGS]['display_columns'].split(',')

        self.columns = {}

        j = 0
        for k, cd in self.columns_def.items():
            if k == "#0":
                continue

            v = tk.BooleanVar()
            v.set(k in displayed)
            b = tk.Checkbutton(self,
                               text=cd.name,
                               variable=v,
                               command=self.button_pressed)
            self.columns[k] = v
            b.grid(row=0, column=j)

            j += 1
Beispiel #5
0
    def addFitCheckBoxes(self, model):
        '''
        Add the fitting checkboxes for the given model to the frame
        '''
        self.deleteFitCheckBoxes()

        self.compGrids = []
        self.compCBs = []
        self.compVisible = []
        self.parVars = {}

        ii = 0
        comps = model.components.keys()
        fitparams = [p for p in model.params if not getattr(model, p).frozen]
        for comp in comps:
            showpars = [p for p in model.components[comp].params \
                if not p in pulsar.nofitboxpars and getattr(model, p).quantity is not None]
            #Don't bother showing components without any fittable parameters
            if len(showpars) == 0:
                continue

            self.compVisible.append(tk.IntVar())
            self.compCBs.append(
                tk.Checkbutton(self,
                               text=comp,
                               variable=self.compVisible[ii],
                               command=self.updateLayout))

            self.compGrids.append([])
            for pp, par in enumerate(showpars):
                self.parVars[par] = tk.IntVar()
                self.compGrids[ii].append(
                    tk.Checkbutton(
                        self,
                        text=par,
                        variable=self.parVars[par],
                        command=lambda p=par: self.changedFitCheckBox(p)))
                if par in fitparams:
                    self.compCBs[ii].select()
                    self.compGrids[ii][pp].select()
            ii += 1

        self.updateLayout()
Beispiel #6
0
    def get_widget(self, master):
        def changed(*args):
            master.disenables_changed(self)

        return tk.Checkbutton(master,
                              text=self.text,
                              variable=self.var,
                              onvalue=True,
                              offvalue=False,
                              command=changed)
Beispiel #7
0
    def get_widget(self, master):
        def changed(*args):
            if self.state_change_cb is not None:
                self.state_change_cb(self.var.get())

            master.disenables_changed(self)

        return tk.Checkbutton(master,
                              variable=self.var,
                              onvalue=True,
                              offvalue=False,
                              command=changed,
                              anchor='w')
    def _Button(self, text, image_file, toggle, frame):
        if image_file is not None:
            im = Tk.PhotoImage(master=self, file=image_file)
        else:
            im = None

        if not toggle:
            b = Tk.Button(master=frame, text=text, padx=2, pady=2, image=im,
                          command=lambda: self._button_click(text))
        else:
            b = Tk.Checkbutton(master=frame, text=text, padx=2, pady=2,
                               image=im, indicatoron=False,
                               command=lambda: self._button_click(text))
        b._ntimage = im
        b.pack(side=Tk.LEFT)
        return b
Beispiel #9
0
    def body(self, master):
        a = 'e'
        tk.Label(master, text='Connection name:', anchor=a).grid(row=0,
                                                                 sticky='ew')
        tk.Label(master, text='Catalog type:', anchor=a).grid(row=1,
                                                              sticky='ew')
        tk.Label(master, text='Root path:', anchor=a).grid(row=2, sticky='ew')
        tk.Label(master, text='Default connection:',
                 anchor=a).grid(row=3, sticky='ew')

        self.name = ttk.Entry(master)
        self.name.grid(row=0, column=1, sticky='ew')
        self.name.insert(0, self.connection_name)
        self.name.focus_set()

        self.catalog_cbox = ttk.Combobox(master,
                                         state='readonly',
                                         values=config.catalog_types + [])

        self.catalog_cbox.grid(row=1, column=1, sticky='ew')
        self.catalog_cbox.set(self.catalog_type)

        self.root_path_entry = tk.Entry(master)
        self.root_path_entry.grid(row=2, column=1, sticky='ew')
        self.root_path_entry.insert(0, self.root_path)

        self.isdefault_var = tk.IntVar()
        self.isdefault_var.set(self.isdefault)
        self.set_default = tk.Checkbutton(master,
                                          variable=self.isdefault_var,
                                          anchor='w')
        self.set_default.grid(row=3, column=1, sticky='ew')

        self.catalog_config_frame = tk.Frame(master)
        self.catalog_config_frame.grid(row=4, column=1, sticky='nsew')

        self.catalog_type_changed(catalog_config=self.catalog_config)
        self.catalog_cbox.bind('<<ComboboxSelected>>',
                               self.catalog_type_changed)

        self.result = None

        return self.name
Beispiel #10
0
    def createWidgets(self):
        # Action Button
        Tk.Button(self, text='Regénération cache',
                  command=self.populate).pack(side=Tk.TOP, fill=Tk.X)

        # Listbox for thumbcache entries
        #self.thumblist = ThumbsListbox(self, height=25, width=35)
        self.thumblist = ThumbsListboxMulti(self,
                                            headings=(('index', {
                                                'width': 60,
                                                'anchor': Tk.E
                                            }), ('hash', {
                                                'width': 200,
                                                'anchor': Tk.CENTER
                                            }), ('size', {
                                                'width': 100,
                                                'anchor': Tk.CENTER
                                            })),
                                            style='ThumbList.Treeview',
                                            height=25)
        self.thumblist.pack(side=Tk.LEFT, fill=Tk.Y)

        # radiobuttons
        self.cachefile = Tk.StringVar()
        for label, cachefile in THMBC_DBS.items():
            Tk.Radiobutton(self,
                           text=label,
                           variable=self.cachefile,
                           value=cachefile,
                           command=self.populate).pack(anchor=Tk.W)
        self.cachefile.set(THMBC_DBS['256x256'])

        # checkbox empty
        self.empty = Tk.BooleanVar()
        Tk.Checkbutton(self,
                       text='Images vides',
                       variable=self.empty,
                       command=self.populate).pack(anchor=Tk.W)
Beispiel #11
0
    def __init__(self, x, y, yerr=None, mode="gauss", config=None):
        self.windowTitle = "PyA interactive GV"
        self.f = Figure()
        self.a = self.f.add_subplot(111)

        self._config = {"modelLS":'r--', \
                        "dataLS":'bp', \
                        "dataLSerr":'b+', \
                        "activeCompLS":'k-', \
                        "inactiveCompLS":'y--', \
                        "plotIndComps":True, \
                        "rangeLS":'m--', \
                        "defaultFreeVoigt":["A", "ad", "al", "mu"], \
                        "default_alad":0.1, \
                        "defaultFreeGauss":["A", "sig", "mu"], \
                        "defaultWheelAdd":0.01, \
                        "defaultWheelMult": 2}

        # Modify configuration according to input
        if config is not None:
            for k in six.iterkeys(self._config):
                if k in config:
                    # Value has been modified
                    self._config[k] = config[k]

        # Tk root
        self.root = tk.Tk()

        # Create data plot
        self._x = x
        self._y = y
        self._yerr = yerr
        if self._yerr is None:
            self.a.plot(x, y, self._config["dataLS"])
        else:
            self.a.errorbar(x,
                            y,
                            yerr=self._yerr,
                            fmt=self._config["dataLSerr"])

        # The input mode determines how clicks on the mouse wheel are
        # interpreted.
        self._inputMode = "newComp"

        # Component count/assignment starts at 1
        self._activeComponent = 1
        self._compoCount = 0

        # Create model and parameter lists
        self._mode = mode
        if self._mode == "voigt":
            self._model = fuf.MultiVoigt1d(1)
            self._compPars = ["mu", "ad", "al", "A"]
        elif self._mode == "gauss":
            self._model = fuf.MultiGauss1d(1)
            self._compPars = ["mu", "sig", "A"]
        else:
            raise(PE.PyAValError("No such mode: " + str(self._mode), \
                                 solution="Choose either 'voigt' or 'gauss'."))
        self._model["off"] = 1.0

        # List used to cache points used to add component
        # as long as component is not completely specified
        self._pointCache = []

        # What to consider in the fit
        self._rangeIndices = np.arange(self._x.size, dtype=np.int)

        # A frame containing the mpl plot
        self.plotFrame = tk.Frame()
        self.plotFrame.pack(fill=tk.BOTH, side=tk.LEFT, expand=True)
        self.canvas = FigureCanvasTkAgg(self.f, master=self.plotFrame)

        # A frame containing the box with selected points
        # and control buttons
        self.pointFrame = tk.Frame(self.root)
        self.pointFrame.pack(side=tk.LEFT, fill=tk.BOTH)

        # Manage active component
        self.activeCompoFrame = tk.Frame(self.pointFrame)
        self.activeCompoFrame.pack(side=tk.TOP)
        self.currentComponentLabel = tk.Label(self.activeCompoFrame,
                                              text="Active component")
        self.currentComponentLabel.pack(side=tk.TOP)
        # De- and increase no. of active component
        self.downACB = tk.Button(self.activeCompoFrame,
                                 text="-",
                                 command=self._downAC)
        self._acstring = tk.StringVar()
        self._acstring.set(str(self._activeComponent))
        self.ACLabel = tk.Label(self.activeCompoFrame,
                                textvariable=self._acstring)
        self.upACB = tk.Button(self.activeCompoFrame,
                               text="+",
                               command=self._upAC)
        self.downACB.pack(side=tk.LEFT)
        self.ACLabel.pack(side=tk.LEFT)
        self.upACB.pack(side=tk.RIGHT)

        # Show and work with parameters
        self.parameterFrame = tk.Frame(self.pointFrame,
                                       relief=tk.RAISED,
                                       borderwidth=1)
        self.parameterFrame.pack(side=tk.TOP)
        # Headline
        tk.Label(self.parameterFrame,
                 text="Parameters (active comp.)").pack(side=tk.TOP)
        # List of parameters to show
        pars = ["off"]
        pars.extend(self._compPars)
        self._parSelect = tk.IntVar()
        # Frames for individual parameters
        self._parFrames = []
        self._parValues = []
        self._parFreeVars = []

        for i, p in enumerate(pars):
            self._parFrames.append(tk.Frame(self.parameterFrame))
            self._parFrames[-1].pack(side=tk.TOP)
            b = tk.Radiobutton(self._parFrames[-1],
                               text="",
                               variable=self._parSelect,
                               value=i)
            b.pack(side=tk.LEFT, anchor=tk.W)
            l = tk.Label(self._parFrames[-1], text=("%3s" % p), width=3)
            l.pack(side=tk.LEFT, anchor=tk.W)
            self._parValues.append(tk.StringVar())
            self._parValues[-1].set("0.0")
            l = tk.Label(self._parFrames[-1],
                         textvariable=self._parValues[-1],
                         width=10)
            l.pack(side=tk.LEFT)

            self._parFreeVars.append(tk.IntVar())
            c = tk.Checkbutton(self._parFrames[-1], text="free", variable=self._parFreeVars[-1], \
                               command=self._freeCheckboxClicked)
            c.pack(side=tk.LEFT)

        # Wheel modification
        self._wheelModFrame = tk.Frame(self.pointFrame,
                                       relief=tk.RAISED,
                                       borderwidth=1)
        self._wheelModFrame.pack(side=tk.TOP)
        # Headline
        tk.Label(self._wheelModFrame, text="Mouse wheel").pack(side=tk.TOP)
        self._multAddSelect = tk.IntVar()
        self._multAddSelect.set(1)
        multiFrame = tk.Frame(self._wheelModFrame)
        addFrame = tk.Frame(self._wheelModFrame)
        multiFrame.pack(side=tk.TOP)
        addFrame.pack(side=tk.TOP)
        tk.Radiobutton(multiFrame,
                       text="multiply [%]",
                       variable=self._multAddSelect,
                       value=1,
                       width=9,
                       anchor=tk.W).pack(side=tk.LEFT)
        tk.Radiobutton(addFrame,
                       text="add",
                       variable=self._multAddSelect,
                       value=2,
                       width=9,
                       anchor=tk.W).pack(side=tk.LEFT)
        self._multNumber = tk.StringVar()
        self._addNumber = tk.StringVar()
        self._multNumber.set(str(self._config["defaultWheelMult"]))
        self._addNumber.set(str(self._config["defaultWheelAdd"]))
        self._multNumberEntry = tk.Entry(multiFrame,
                                         textvariable=self._multNumber,
                                         width=10)
        self._multNumberEntry.pack(side=tk.RIGHT)
        self._addNumberEntry = tk.Entry(addFrame,
                                        textvariable=self._addNumber,
                                        width=10)
        self._addNumberEntry.pack(side=tk.RIGHT)

        # Common width
        if self._mode == "gauss":
            commonSigFrame = tk.Frame(self.pointFrame)
            commonSigFrame.pack(side=tk.TOP)
            self._commonSig = tk.IntVar()
            c = tk.Checkbutton(commonSigFrame, text="Common width (sig)", variable=self._commonSig, \
                               command=self._commonSigClicked)
            c.pack(side=tk.LEFT)

        # Fit button
        self._fitButton = tk.Button(self.pointFrame,
                                    text="Fit",
                                    command=self._fitModel)
        self._fitButton.pack(side=tk.TOP, fill=tk.X)

        # Range button
        self._rangeButton = tk.Button(self.pointFrame,
                                      text="Set fit range",
                                      command=self._rangeButtonClicked)
        self._rangeButton.pack(side=tk.TOP, fill=tk.X)

        # Remove button
        self.removeButton = tk.Button(master=self.pointFrame, text="Remove component", \
                                      command=self._removeButtonClicked)
        self.removeButton.pack(side=tk.TOP, fill=tk.X)

        # a tk.DrawingArea
        self.canvas.get_tk_widget().pack()
        self.cid = self.f.canvas.mpl_connect('button_press_event',
                                             self._mouseButtonClicked)
        self.mwe = self.f.canvas.mpl_connect('scroll_event', self._mouseWheel)

        self.toolbar = NavigationToolbar2TkAgg(self.canvas, self.plotFrame)
        self.toolbar.update()
        self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)

        def _quit():
            # stops main loop
            self.root.quit()
            # this is necessary on Windows to prevent
            # Fatal Python Error: PyEval_RestoreThread: NULL tstate
            self.root.destroy()

        self.quitButton = tk.Button(master=self.pointFrame,
                                    text='Quit',
                                    command=_quit)
        self.quitButton.pack(side=tk.BOTTOM, fill=tk.X)
    def __init__(self, parent, title, init_font, **kw):
        # print init_font
        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)

        self.font_family = 'Helvetica'
        self.font_size = 12
        self.font_weight = 'normal'
        self.font_slant = 'roman'

        if init_font is not None:
            assert 2 <= len(init_font) <= 4
            assert isinstance(init_font[1], int)
            self.font_family, self.font_size = init_font[:2]
            if len(init_font) > 2:
                if init_font[2] in ['bold', 'normal']:
                    self.font_weight = init_font[2]
                elif init_font[2] in ['italic', 'roman']:
                    self.font_slant = init_font[2]
                else:
                    raise ValueError('invalid font style: ' + init_font[2])
                if len(init_font) > 3:
                    if init_font[3] in ['bold', 'normal']:
                        self.font_weight = init_font[3]
                    elif init_font[2] in ['italic', 'roman']:
                        self.font_slant = init_font[3]
                    else:
                        raise ValueError('invalid font style: ' + init_font[3])

        # self.family_var = tkinter.StringVar()
        self.weight_var = tkinter.BooleanVar()
        self.slant_var = tkinter.BooleanVar()
        self.size_var = tkinter.IntVar()

        frame = tkinter.Frame(top_frame)
        frame.pack(expand=True, fill='both', padx=5, pady=10)
        frame.columnconfigure(0, weight=1)
        # frame.rowconfigure(1, weight=1)
        self.entry = tkinter.Entry(frame, bg='white')
        self.entry.grid(row=0, column=0, columnspan=2, sticky='news')
        self.entry.insert('end', _('abcdefghABCDEFGH'))
        self.list_box = tkinter.Listbox(frame, width=36, exportselection=False)
        sb = tkinter.Scrollbar(frame)
        self.list_box.configure(yscrollcommand=sb.set)
        sb.configure(command=self.list_box.yview)
        self.list_box.grid(row=1, column=0, sticky='news')  # rowspan=4
        sb.grid(row=1, column=1, sticky='ns')
        bind(self.list_box, '<<ListboxSelect>>', self.fontupdate)
        # self.list_box.focus()
        cb1 = tkinter.Checkbutton(frame,
                                  anchor='w',
                                  text=_('Bold'),
                                  command=self.fontupdate,
                                  variable=self.weight_var)
        cb1.grid(row=2, column=0, columnspan=2, sticky='we')
        cb2 = tkinter.Checkbutton(frame,
                                  anchor='w',
                                  text=_('Italic'),
                                  command=self.fontupdate,
                                  variable=self.slant_var)
        cb2.grid(row=3, column=0, columnspan=2, sticky='we')

        sc = tkinter.Scale(
            frame,
            from_=6,
            to=40,
            resolution=1,
            # label='Size',
            orient='horizontal',
            command=self.fontupdate,
            variable=self.size_var)
        sc.grid(row=4, column=0, columnspan=2, sticky='news')
        #
        self.size_var.set(self.font_size)
        self.weight_var.set(self.font_weight == 'bold')
        self.slant_var.set(self.font_slant == 'italic')
        font_families = list(tkinter_font.families())
        font_families.sort()
        selected = -1
        n = 0
        self.list_box.insert('end', *font_families)
        for font in font_families:
            if font.lower() == self.font_family.lower():
                selected = n
                break
            n += 1
        if selected >= 0:
            self.list_box.select_set(selected)
            self.list_box.see(selected)
        #
        focus = self.createButtons(bottom_frame, kw)
        self.mainloop(focus, kw.timeout)

        self.font = (self.font_family, self.font_size, self.font_slant,
                     self.font_weight)
Beispiel #13
0
    def __init__(self, parent, title, app, **kw):
        self.app = app
        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)
        #
        self.saved_opt = app.opt.copy()
        self.sound = tkinter.BooleanVar()
        self.sound.set(app.opt.sound != 0)
        self.sound_mode = tkinter.BooleanVar()
        self.sound_mode.set(app.opt.sound_mode != 0)
        self.sample_volume = tkinter.IntVar()
        self.sample_volume.set(app.opt.sound_sample_volume)
        self.music_volume = tkinter.IntVar()
        self.music_volume.set(app.opt.sound_music_volume)
        self.samples = [
            ('areyousure',    _('Are You Sure'),   tkinter.BooleanVar()),

            ('deal',          _('Deal'),           tkinter.BooleanVar()),
            ('dealwaste',     _('Deal waste'),     tkinter.BooleanVar()),

            ('turnwaste',     _('Turn waste'),     tkinter.BooleanVar()),
            ('startdrag',     _('Start drag'),     tkinter.BooleanVar()),

            ('drop',          _('Drop'),           tkinter.BooleanVar()),
            ('droppair',      _('Drop pair'),      tkinter.BooleanVar()),
            ('autodrop',      _('Auto drop'),      tkinter.BooleanVar()),

            ('flip',          _('Flip'),           tkinter.BooleanVar()),
            ('autoflip',      _('Auto flip'),      tkinter.BooleanVar()),
            ('move',          _('Move'),           tkinter.BooleanVar()),
            ('nomove',        _('No move'),        tkinter.BooleanVar()),

            ('undo',          _('Undo'),           tkinter.BooleanVar()),
            ('redo',          _('Redo'),           tkinter.BooleanVar()),

            ('autopilotlost', _('Autopilot lost'), tkinter.BooleanVar()),
            ('autopilotwon',  _('Autopilot won'),  tkinter.BooleanVar()),

            ('gamefinished',  _('Game finished'),  tkinter.BooleanVar()),
            ('gamelost',      _('Game lost'),      tkinter.BooleanVar()),
            ('gamewon',       _('Game won'),       tkinter.BooleanVar()),
            ('gameperfect',   _('Perfect game'),   tkinter.BooleanVar()),

            ('extra',         _('Other'),          tkinter.BooleanVar()),
            ]

        #
        frame = tkinter.Frame(top_frame)
        frame.pack(expand=True, fill='both', padx=5, pady=5)
        frame.columnconfigure(1, weight=1)
        #
        row = 0
        w = tkinter.Checkbutton(frame, variable=self.sound,
                                text=_("Sound enabled"), anchor='w')
        w.grid(row=row, column=0, columnspan=2, sticky='ew')
        #
        if os.name == "nt" and pysolsoundserver:
            row += 1
            w = tkinter.Checkbutton(frame, variable=self.sound_mode,
                                    text=_("Use DirectX for sound playing"),
                                    command=self.mOptSoundDirectX, anchor='w')
            w.grid(row=row, column=0, columnspan=2, sticky='ew')
        #
        if app.audio.CAN_PLAY_MUSIC:  # and app.startup_opt.sound_mode > 0:
            row += 1
            w = tkinter.Label(frame, text=_('Sample volume:'))
            w.grid(row=row, column=0, sticky='w', padx=5)
            w = tkinter.Scale(frame, from_=0, to=128, resolution=1,
                              orient='horizontal', takefocus=0,
                              length="3i",  # label=_('Sample volume'),
                              variable=self.sample_volume)
            w.grid(row=row, column=1, sticky='ew', padx=5)
            row += 1
            w = tkinter.Label(frame, text=_('Music volume:'))
            w.grid(row=row, column=0, sticky='w', padx=5)
            w = tkinter.Scale(frame, from_=0, to=128, resolution=1,
                              orient='horizontal', takefocus=0,
                              length="3i",  # label=_('Music volume'),
                              variable=self.music_volume)
            w.grid(row=row, column=1, sticky='ew', padx=5)

        else:
            # remove "Apply" button
            kw.strings[1] = None
        #
        frame = tkinter.LabelFrame(top_frame, text=_('Enable samles'),
                                   padx=5, pady=5)
        frame.pack(expand=True, fill='both', padx=5, pady=5)
        frame.columnconfigure(0, weight=1)
        frame.columnconfigure(1, weight=1)
        #
        row = 0
        col = 0
        for n, t, v in self.samples:
            v.set(app.opt.sound_samples[n])
            w = tkinter.Checkbutton(frame, text=t, anchor='w', variable=v)
            w.grid(row=row, column=col, sticky='ew')
            if col == 1:
                col = 0
                row += 1
            else:
                col = 1
        #
        top_frame.columnconfigure(1, weight=1)
        #
        focus = self.createButtons(bottom_frame, kw)
        self.mainloop(focus, kw.timeout)
    def __init__(self, parent, title, app, manager, key=None, **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)
        #
        if key is None:
            key = manager.getSelected()
        self.manager = manager
        self.key = key
        self.app = app
        # padx, pady = kw.padx, kw.pady
        padx, pady = 5, 5
        if self.TreeDataHolder_Class.data is None:
            self.TreeDataHolder_Class.data = self.TreeData_Class(manager, key)
        #
        self.top.wm_minsize(400, 200)
        if self.top.winfo_screenwidth() >= 800:
            w1, w2 = 240, 400
        else:
            w1, w2 = 200, 300
        paned_window = tkinter.PanedWindow(top_frame)
        paned_window.pack(expand=True, fill='both')
        left_frame = tkinter.Frame(paned_window)
        right_frame = tkinter.Frame(paned_window)
        paned_window.add(left_frame)
        paned_window.add(right_frame)

        font = app.getFont("default")
        self.tree = self.Tree_Class(self,
                                    left_frame,
                                    key=key,
                                    default=kw.default,
                                    font=font,
                                    width=w1)
        self.tree.frame.grid(row=0,
                             column=0,
                             sticky='nsew',
                             padx=padx,
                             pady=pady)
        if USE_PIL:
            #
            var = tkinter.DoubleVar()
            var.set(app.opt.scale_x)
            self.scale_x = tkinter.Scale(
                left_frame,
                label=_('Scale X:'),
                from_=0.5,
                to=4.0,
                resolution=0.1,
                orient='horizontal',
                variable=var,
                # value=app.opt.scale_x,
                command=self._updateScale)
            self.scale_x.grid(row=1,
                              column=0,
                              sticky='ew',
                              padx=padx,
                              pady=pady)
            #
            var = tkinter.DoubleVar()
            var.set(app.opt.scale_y)
            self.scale_y = tkinter.Scale(
                left_frame,
                label=_('Scale Y:'),
                from_=0.5,
                to=4.0,
                resolution=0.1,
                orient='horizontal',
                variable=var,
                # value=app.opt.scale_y,
                command=self._updateScale)
            self.scale_y.grid(row=2,
                              column=0,
                              sticky='ew',
                              padx=padx,
                              pady=pady)
            #
            self.auto_scale = tkinter.BooleanVar()
            self.auto_scale.set(app.opt.auto_scale)
            check = tkinter.Checkbutton(left_frame,
                                        text=_('Auto scaling'),
                                        variable=self.auto_scale,
                                        takefocus=False,
                                        command=self._updateAutoScale)
            check.grid(row=3,
                       column=0,
                       columnspan=2,
                       sticky='w',
                       padx=padx,
                       pady=pady)
            #
            self.preserve_aspect = tkinter.BooleanVar()
            self.preserve_aspect.set(app.opt.preserve_aspect_ratio)
            self.aspect_check = tkinter.Checkbutton(
                left_frame,
                text=_('Preserve aspect ratio'),
                variable=self.preserve_aspect,
                takefocus=False,
                # command=self._updateScale
            )
            self.aspect_check.grid(row=4,
                                   column=0,
                                   sticky='w',
                                   padx=padx,
                                   pady=pady)
            self._updateAutoScale()
        #
        left_frame.rowconfigure(0, weight=1)
        left_frame.columnconfigure(0, weight=1)
        #
        self.preview = MfxScrolledCanvas(right_frame, width=w2)
        self.preview.setTile(app, app.tabletile_index, force=True)
        self.preview.pack(fill='both', expand=True, padx=padx, pady=pady)
        self.preview.canvas.preview = 1
        # create a preview of the current state
        self.preview_key = -1
        self.preview_images = []
        self.scale_images = []
        self.updatePreview(key)
        #
        focus = self.createButtons(bottom_frame, kw)
        focus = self.tree.frame
        self.mainloop(focus, kw.timeout)
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
Beispiel #16
0
    def __init__(self, parent, title, app, **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(expand=True, fill='both', padx=10, pady=10)
        frame.columnconfigure(0, weight=1)

        notebook = TabPageSet(frame)
        notebook.pack(expand=True, fill='both')

        for w in WizardWidgets:
            if isinstance(w, basestring):
                notebook.AddPage(w)
                frame = tkinter.Frame(notebook.pages[w]['page'])
                frame.pack(expand=True, fill='both', padx=2, pady=4)
                frame.columnconfigure(1, weight=1)
                row = 0
                continue

            tkinter.Label(frame, text=w.label).grid(row=row, column=0, padx=2)

            if w.widget == 'preset':
                if w.variable is None:
                    w.variable = tkinter.StringVar()
                values = [_(v) for v in w.values]
                default = _(w.default)
                values.remove(default)
                values.sort()
                values.insert(0, default)

                def callback(v, w=w):
                    return self.presetSelected(v, w)

                om = tkinter.OptionMenu(frame,
                                        w.variable,
                                        command=callback,
                                        *values)
                om.grid(row=row, column=1, sticky='ew', padx=2)
            elif w.widget == 'entry':
                if w.variable is None:
                    w.variable = tkinter.StringVar()
                en = tkinter.Entry(frame, textvariable=w.variable)
                en.grid(row=row, column=1, sticky='ew', padx=2)
            elif w.widget == 'menu':
                if w.variable is None:
                    w.variable = tkinter.StringVar()
                values = [_(v) for v in w.values]
                om = tkinter.OptionMenu(frame, w.variable, *values)
                om.grid(row=row, column=1, sticky='ew', padx=2)
            elif w.widget == 'spin':
                if w.variable is None:
                    w.variable = tkinter.IntVar()
                from_, to = w.values
                s = tkinter.Scale(frame,
                                  from_=from_,
                                  to=to,
                                  resolution=1,
                                  orient='horizontal',
                                  length=200,
                                  variable=w.variable)
                s.grid(row=row, column=1, sticky='ew', padx=2)
            elif w.widget == 'check':
                if w.variable is None:
                    w.variable = tkinter.BooleanVar()
                ch = tkinter.Checkbutton(frame,
                                         variable=w.variable,
                                         takefocus=False,
                                         anchor='w')
                ch.grid(row=row, column=1, sticky='ew', padx=2, pady=2)

            if w.current_value is None:
                v = w.default
            else:
                v = w.current_value
            if w.widget in ('menu', 'preset', 'entry'):
                v = _(v)
            w.variable.set(v)

            row += 1

        notebook.ChangePage()

        focus = self.createButtons(bottom_frame, kw)
        self.mainloop(focus, kw.timeout)
    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)