コード例 #1
0
ファイル: timeoutsdialog.py プロジェクト: iske/PySolFC
    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 = ttk.Frame(top_frame)
        frame.pack(expand=True, fill='both', padx=5, pady=10)
        frame.columnconfigure(0, weight=1)

        self.demo_sleep_var = Tkinter.DoubleVar()
        self.demo_sleep_var.set(app.opt.timeouts['demo'])
        self.hint_sleep_var = Tkinter.DoubleVar()
        self.hint_sleep_var.set(app.opt.timeouts['hint'])
        self.raise_card_sleep_var = Tkinter.DoubleVar()
        self.raise_card_sleep_var.set(app.opt.timeouts['raise_card'])
        self.highlight_piles_sleep_var = Tkinter.DoubleVar()
        self.highlight_piles_sleep_var.set(app.opt.timeouts['highlight_piles'])
        self.highlight_cards_sleep_var = Tkinter.DoubleVar()
        self.highlight_cards_sleep_var.set(app.opt.timeouts['highlight_cards'])
        self.highlight_samerank_sleep_var = Tkinter.DoubleVar()
        self.highlight_samerank_sleep_var.set(app.opt.timeouts['highlight_samerank'])
        #
        lframe = ttk.LabelFrame(frame, text=_('Set delays in seconds'),
                                 padding=(10, 5))
        lframe.pack(expand=True, fill='both', padx=4)
        row = 0
        for title, var in (
            (_('Demo:'),                self.demo_sleep_var),
            (_('Hint:'),                self.hint_sleep_var),
            (_('Raise card:'),          self.raise_card_sleep_var),
            (_('Highlight piles:'),     self.highlight_piles_sleep_var),
            (_('Highlight cards:'),     self.highlight_cards_sleep_var),
            (_('Highlight same rank:'), self.highlight_samerank_sleep_var),
            ):
            ttk.Label(lframe, text=title, anchor='w'
                       ).grid(row=row, column=0, sticky='we')
            widget = PysolScale(lframe, from_=0.2, to=9.9, value=var.get(),
                                resolution=0.1, orient='horizontal',
                                length="3i", variable=var, takefocus=0)
            widget.grid(row=row, column=1)
            row += 1
        #
        focus = self.createButtons(bottom_frame, kw)
        self.mainloop(focus, kw.timeout)
        #
        self.demo_timeout = self.demo_sleep_var.get()
        self.hint_timeout = self.hint_sleep_var.get()
        self.raise_card_timeout = self.raise_card_sleep_var.get()
        self.highlight_piles_timeout = self.highlight_piles_sleep_var.get()
        self.highlight_cards_timeout = self.highlight_cards_sleep_var.get()
        self.highlight_samerank_timeout = self.highlight_samerank_sleep_var.get()
コード例 #2
0
ファイル: wizarddialog.py プロジェクト: TrevorLowing/PyGames
    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 = ttk.Frame(top_frame)
        frame.pack(expand=True, fill="both", padx=10, pady=10)
        frame.columnconfigure(0, weight=1)

        notebook = ttk.Notebook(frame)
        notebook.pack(expand=True, fill="both")

        for w in WizardWidgets:
            if isinstance(w, basestring):
                frame = ttk.Frame(notebook)
                notebook.add(frame, text=w, sticky="nsew", padding=5)
                frame.columnconfigure(1, weight=1)
                row = 0
                continue

            ttk.Label(frame, text=w.label).grid(row=row, column=0)

            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)
                callback = lambda e, w=w: self.presetSelected(e, w)
                cb = PysolCombo(
                    frame,
                    values=tuple(values),
                    textvariable=w.variable,
                    exportselection=False,
                    selectcommand=callback,
                    state="readonly",
                    width=32,
                )
                cb.grid(row=row, column=1, sticky="ew", padx=2, pady=2)
            elif w.widget == "entry":
                if w.variable is None:
                    w.variable = Tkinter.StringVar()
                en = ttk.Entry(frame, textvariable=w.variable)
                en.grid(row=row, column=1, sticky="ew", padx=2, pady=2)
            elif w.widget == "menu":
                if w.variable is None:
                    w.variable = Tkinter.StringVar()
                values = [_(v) for v in w.values]
                cb = PysolCombo(
                    frame,
                    values=tuple(values),
                    textvariable=w.variable,
                    exportselection=False,
                    state="readonly",
                    width=32,
                )
                cb.grid(row=row, column=1, sticky="ew", padx=2, pady=2)
            elif w.widget == "spin":
                if w.variable is None:
                    w.variable = Tkinter.IntVar()
                else:
                    # delete all trace callbacks
                    for mod, cbname in w.variable.trace_vinfo():
                        w.variable.trace_vdelete(mod, cbname)
                from_, to = w.values
                ##s = Spinbox(frame, textvariable=w.variable, from_=from_, to=to)
                s = PysolScale(frame, from_=from_, to=to, resolution=1, orient="horizontal", variable=w.variable)
                s.grid(row=row, column=1, sticky="ew", padx=2, pady=2)
            elif w.widget == "check":
                if w.variable is None:
                    w.variable = Tkinter.BooleanVar()
                ch = ttk.Checkbutton(frame, variable=w.variable, takefocus=False)
                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"):
                v = _(v)
            w.variable.set(v)

            row += 1

        focus = self.createButtons(bottom_frame, kw)
        self.mainloop(focus, kw.timeout)
コード例 #3
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()),
            ]

        #
        frame = ttk.Frame(top_frame)
        frame.pack(expand=True, fill='both', padx=5, pady=5)
        frame.columnconfigure(1, weight=1)
        #
        row = 0
        w = ttk.Checkbutton(frame, variable=self.sound,
                            text=_("Sound enabled"))
        w.grid(row=row, column=0, columnspan=2, sticky='ew')
        #
        if os.name == "nt" and pysolsoundserver:
            row += 1
            w = ttk.Checkbutton(frame, variable=self.sound_mode,
                                text=_("Use DirectX for sound playing"),
                                command=self.mOptSoundDirectX)
            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
            ttk.Label(frame, text=_('Sample volume:'), anchor='w'
                      ).grid(row=row, column=0, sticky='ew')
            w = PysolScale(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='w', padx=5)
            row += 1
            ttk.Label(frame, text=_('Music volume:'), anchor='w'
                      ).grid(row=row, column=0, sticky='ew')
            w = PysolScale(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='w', padx=5)

        else:
            # remove "Apply" button
            kw.strings[1] = None
        #
        frame = ttk.LabelFrame(top_frame, text=_('Enable samples'))
        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 = ttk.Checkbutton(frame, text=t, variable=v)
            w.grid(row=row, column=col, sticky='ew', padx=3, pady=1)
            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)
コード例 #4
0
ファイル: selectcardset.py プロジェクト: iske/PySolFC
    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 = ttk.Frame(top_frame)
        frame.pack(fill="both", expand=True, padx=5, pady=10)
        #
        #
        row = 0
        info_frame = ttk.LabelFrame(frame, text=_('About cardset'))
        info_frame.grid(row=row, column=0, columnspan=2, sticky='ew',
                        padx=0, pady=5, ipadx=5, ipady=5)
        row += 1
        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)
        frow = 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:
                l = ttk.Label(info_frame, text=n,
                              anchor='w', justify='left')
                l.grid(row=frow, column=0, sticky='nw', padx=4)
                l = ttk.Label(info_frame, text=t,
                              anchor='w', justify='left')
                l.grid(row=frow, column=1, sticky='nw', padx=4)
                frow += 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) # store the image
                l = ttk.Label(info_frame, image=im, padding=5)
                l.grid(row=0, column=2, rowspan=frow+1, sticky='ne')
                l = ttk.Label(info_frame, image=self.back_image,
                              padding=(0,5,5,5)) # left margin = 0
                l.grid(row=0, column=3, rowspan=frow+1, sticky='ne')

                info_frame.columnconfigure(2, weight=1)
                info_frame.rowconfigure(frow, weight=1)
            except:
                traceback.print_exc()
                pass
        if USE_PIL:
            padx = 4
            pady = 0
            settings_frame = ttk.LabelFrame(frame, text=_('Settings'))
            settings_frame.grid(row=row, column=0, columnspan=2, sticky='ew',
                                padx=0, pady=5, ipadx=5, ipady=5)
            row += 1
            var = Tkinter.IntVar()
            self.x_offset = PysolScale(
                settings_frame, label=_('X offset:'),
                from_=5, to=40, resolution=1,
                orient='horizontal', variable=var,
                value=cardset.CARD_XOFFSET,
                #command=self._updateScale
                )
            self.x_offset.grid(row=0, column=0, sticky='ew',
                               padx=padx, pady=pady)
            var = Tkinter.IntVar()
            self.y_offset = PysolScale(
                settings_frame, label=_('Y offset:'),
                from_=5, to=40, resolution=1,
                orient='horizontal', variable=var,
                value=cardset.CARD_YOFFSET,
                #command=self._updateScale
                )
            self.y_offset.grid(row=1, column=0, sticky='ew',
                               padx=padx, pady=pady)
            row += 1

        ##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=row, column=0, sticky='nsew')
        sb = ttk.Scrollbar(frame)
        sb.grid(row=row, 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:
            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)
コード例 #5
0
ファイル: selectcardset.py プロジェクト: iske/PySolFC
 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
     self.cardset_values = None
     #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 = ttk.PanedWindow(top_frame, orient='horizontal')
     paned_window.pack(expand=True, fill='both')
     left_frame = ttk.Frame(paned_window)
     right_frame = ttk.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 = PysolScale(
             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 = PysolScale(
             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 = ttk.Checkbutton(
             left_frame, text=_('Auto scaling'),
             variable=self.auto_scale,
             takefocus=False,
             command=self._updateAutoScale
             )
         check.grid(row=3, column=0, columnspan=2, sticky='ew',
                    padx=padx, pady=pady)
         #
         self.preserve_aspect = Tkinter.BooleanVar()
         self.preserve_aspect.set(app.opt.preserve_aspect_ratio)
         self.aspect_check = ttk.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='ew',
                                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)
コード例 #6
0
ファイル: selectcardset.py プロジェクト: iske/PySolFC
class SelectCardsetDialogWithPreview(MfxDialog):
    Tree_Class = SelectCardsetTree
    TreeDataHolder_Class = SelectCardsetTree
    TreeData_Class = SelectCardsetData

    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
        self.cardset_values = None
        #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 = ttk.PanedWindow(top_frame, orient='horizontal')
        paned_window.pack(expand=True, fill='both')
        left_frame = ttk.Frame(paned_window)
        right_frame = ttk.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 = PysolScale(
                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 = PysolScale(
                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 = ttk.Checkbutton(
                left_frame, text=_('Auto scaling'),
                variable=self.auto_scale,
                takefocus=False,
                command=self._updateAutoScale
                )
            check.grid(row=3, column=0, columnspan=2, sticky='ew',
                       padx=padx, pady=pady)
            #
            self.preserve_aspect = Tkinter.BooleanVar()
            self.preserve_aspect.set(app.opt.preserve_aspect_ratio)
            self.aspect_check = ttk.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='ew',
                                   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 destroy(self):
        self.tree.updateNodesWithTree(self.tree.rootnodes, None)
        self.tree.destroy()
        self.preview.unbind_all()
        self.preview_images = []
        MfxDialog.destroy(self)

    def initKw(self, kw):
        if USE_PIL:
            s = (_("&Info / Settings..."), 10)
        else:
            s = (_("&Info..."), 10)
        kw = KwStruct(kw,
                      strings = (s, 'sep',
                                 _("&OK"), _("&Cancel"),),
                      default=0,
                      resizable=True,
                      )
        return MfxDialog.initKw(self, kw)

    def mDone(self, button):
        if button in (0, 1):            # Load/Cancel
            self.key = self.tree.selection_key
            self.tree.n_expansions = 1  # save xyview in any case
            if USE_PIL:
                auto_scale = bool(self.auto_scale.get())
                if button == 1:
                    self.app.menubar.tkopt.auto_scale.set(auto_scale)
                if auto_scale:
                    self.scale_values = (self.app.opt.scale_x,
                                         self.app.opt.scale_y,
                                         auto_scale,
                                         bool(self.preserve_aspect.get()))
                else:
                    self.scale_values = (self.scale_x.get(),
                                         self.scale_y.get(),
                                         auto_scale,
                                         self.app.opt.preserve_aspect_ratio)
        if button == 10:                # Info
            cs = self.manager.get(self.tree.selection_key)
            if not cs:
                return
            ##title = CARDSET+" "+cs.name
            title = CARDSET.capitalize()+" "+cs.name
            d = CardsetInfoDialog(self.top, title=title, cardset=cs,
                                  images=self.preview_images)
            self.cardset_values = d.cardset_values
            return
        MfxDialog.mDone(self, button)

    def _updateAutoScale(self, v=None):
        if self.auto_scale.get():
            self.aspect_check.config(state='normal')
            self.scale_x.state('disabled')
            self.scale_y.state('disabled')
        else:
            self.aspect_check.config(state='disabled')
            self.scale_x.state('!disabled')
            self.scale_y.state('!disabled')

    def _updateScale(self, v):
        self.updatePreview()

    def updatePreview(self, key=None):
        if key == self.preview_key:
            return
        if key is None:
            key = self.key
        canvas = self.preview.canvas
        canvas.deleteAllItems()
        self.preview_images = []
        cs = self.manager.get(key)
        if not cs:
            self.preview_key = -1
            return
        names, columns = cs.getPreviewCardNames()
        try:
            #???names, columns = cs.getPreviewCardNames()
            for n in names:
                f = os.path.join(cs.dir, n + cs.ext)
                self.preview_images.append(loadImage(file=f))
        except:
            self.preview_key = -1
            self.preview_images = []
            return
        i, x, y, sx, sy, dx, dy = 0, 10, 10, 0, 0, cs.CARDW + 10, cs.CARDH + 10
        if USE_PIL:
            xf = self.scale_x.get()
            yf = self.scale_y.get()
            dx = int(dx*xf)
            dy = int(dy*yf)
            self.scale_images = []
        for image in self.preview_images:
            if USE_PIL:
                image = image.resize(xf, yf)
                self.scale_images.append(image)
            MfxCanvasImage(canvas, x, y, anchor="nw", image=image)
            sx, sy = max(x, sx), max(y, sy)
            i = i + 1
            if i % columns == 0:
                x, y = 10, y + dy
            else:
                x = x + dx
        canvas.config(scrollregion=(0, 0, sx+dx, sy+dy),
                      width=sx+dx, height=sy+dy)
        #canvas.config(xscrollincrement=dx, yscrollincrement=dy)
        canvas.event_generate('<Configure>') # update bg image
        self.preview_key = key
        self.key = key
コード例 #7
0
ファイル: fontsdialog.py プロジェクト: iske/PySolFC
    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.weight_var.set(self.font_weight == 'bold')
        self.slant_var = Tkinter.BooleanVar()
        self.slant_var.set(self.font_slant == 'italic')
        self.size_var = Tkinter.IntVar()
        self.size_var.set(self.font_size)
        #
        frame = ttk.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 = ttk.Entry(frame)
        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 = ttk.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 = ttk.Checkbutton(frame, text=_('Bold'),
                              command=self.fontupdate,
                              variable=self.weight_var)
        cb1.grid(row=2, column=0, columnspan=2, sticky='we')
        cb2 = ttk.Checkbutton(frame, text=_('Italic'),
                              command=self.fontupdate,
                              variable=self.slant_var)
        cb2.grid(row=3, column=0, columnspan=2, sticky='we')

        sc = PysolScale(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')
        #
        font_families = list(tkFont.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)