Exemplo n.º 1
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)
Exemplo n.º 2
0
 def __init__(self, parent, title, app, gameid, bookmark=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)
     #
     self.app = app
     self.gameid = gameid
     self.bookmark = bookmark
     self.random = None
     if self.TreeDataHolder_Class.data is None:
         self.TreeDataHolder_Class.data = self.TreeData_Class(app)
     #
     self.top.wm_minsize(400, 200)
     sw = self.top.winfo_screenwidth()
     if sw >= 1100:
         w1, w2 = 250, 600
     elif sw >= 900:
         w1, w2 = 250, 500
     elif sw >= 800:
         w1, w2 = 220, 480
     else:
         w1, w2 = 200, 300
     # print sw, w1, w2
     w2 = max(200, min(w2, 10 + 12 * (app.subsampled_images.CARDW + 10)))
     # print sw, w1, w2
     # padx, pady = kw.padx, kw.pady
     padx, pady = kw.padx // 2, kw.pady // 2
     # PanedWindow
     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)
     # Tree
     font = app.getFont("default")
     self.tree = self.Tree_Class(self,
                                 left_frame,
                                 key=gameid,
                                 default=kw.default,
                                 font=font,
                                 width=w1)
     self.tree.frame.pack(padx=padx, pady=pady, expand=True, fill='both')
     # LabelFrame
     info_frame = tkinter.LabelFrame(right_frame, text=_('About game'))
     stats_frame = tkinter.LabelFrame(right_frame, text=_('Statistics'))
     info_frame.grid(row=0,
                     column=0,
                     padx=padx,
                     pady=pady,
                     ipadx=padx,
                     ipady=pady,
                     sticky='nws')
     stats_frame.grid(row=0,
                      column=1,
                      padx=padx,
                      pady=pady,
                      ipadx=padx,
                      ipady=pady,
                      sticky='nws')
     # Info
     self.info_labels = {}
     for n, t, f, row in (
         ('name', _('Name:'), info_frame, 0),
         ('altnames', _('Alternate names:'), info_frame, 1),
         ('category', _('Category:'), info_frame, 2),
         ('type', _('Type:'), info_frame, 3),
         ('skill_level', _('Skill level:'), info_frame, 4),
         ('decks', _('Decks:'), info_frame, 5),
         ('redeals', _('Redeals:'), info_frame, 6),
             #
         ('played', _('Played:'), stats_frame, 0),
         ('won', _('Won:'), stats_frame, 1),
         ('lost', _('Lost:'), stats_frame, 2),
         ('time', _('Playing time:'), stats_frame, 3),
         ('moves', _('Moves:'), stats_frame, 4),
         ('percent', _('% won:'), stats_frame, 5),
     ):
         title_label = tkinter.Label(f, text=t, justify='left', anchor='w')
         title_label.grid(row=row, column=0, sticky='nw')
         text_label = tkinter.Label(f, justify='left', anchor='w')
         text_label.grid(row=row, column=1, sticky='nw')
         self.info_labels[n] = (title_label, text_label)
     # info_frame.columnconfigure(1, weight=1)
     info_frame.rowconfigure(6, weight=1)
     stats_frame.rowconfigure(6, weight=1)
     # Canvas
     self.preview = MfxScrolledCanvas(right_frame, width=w2)
     self.preview.setTile(app, app.tabletile_index, force=True)
     self.preview.grid(row=1,
                       column=0,
                       columnspan=3,
                       padx=padx,
                       pady=pady,
                       sticky='nsew')
     right_frame.columnconfigure(1, weight=1)
     right_frame.rowconfigure(1, weight=1)
     #
     focus = self.createButtons(bottom_frame, kw)
     # set the scale factor
     self.preview.canvas.preview = 2
     # create a preview of the current game
     self.preview_key = -1
     self.preview_game = None
     self.preview_app = None
     self.updatePreview(gameid, animations=0)
     # focus = self.tree.frame
     self.mainloop(focus, kw.timeout)
 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)
Exemplo n.º 4
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)