Пример #1
0
 def setTopImage(self, image, cw=0, ch=0):
     try:
         if image and isinstance(image, str):
             image = loadImage(file=image)
     except Tkinter.TclError:
         return 0
     if len(self.__tops) == 1 and image is self.__tops[0]:
         return 1
     for id in self.__tops:
         self.delete(id)
     self.__tops = []
     # must keep a reference to the image, otherwise Python will
     # garbage collect it...
     self.__topimage = image
     if image is None:
         return 1
     iw, ih = image.width(), image.height()
     if cw <= 0:
         ##cw = max(int(self.cget("width")), self.winfo_width())
         cw = self.winfo_width()
     if ch <= 0:
         ##ch = max(int(self.cget("height")),  self.winfo_height())
         ch = self.winfo_height()
     ###print iw, ih, cw, ch
     x = (cw-iw)/2-self.xmargin+self.xview()[0]*int(self.cget('width'))
     y = (ch-ih)/2-self.ymargin+self.yview()[0]*int(self.cget('height'))
     id = self._x_create("image", x, y, image=image, anchor="nw")
     self.tk.call(self._w, "raise", id)
     self.__tops.append(id)
     return 1
Пример #2
0
 def updatePreview(self, key):
     if key == self.preview_key:
         return
     canvas = self.preview
     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 Exception:
         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
     for image in self.preview_images:
         MfxCanvasImage(canvas, x, y, anchor="nw", image=image)
         sx, sy = max(x, sx), max(y, sy)
         i += 1
         if i % columns == 0:
             x, y = 10, y + dy
         else:
             x += dx
     canvas.config(width=sx+dx, height=sy+dy)
     canvas.set_scroll_region(0, 0, sx+dx, sy+dy)
     self.preview_key = key
Пример #3
0
 def updatePreview(self, key):
     if key == self.preview_key:
         return
     canvas = self.preview
     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
     for image in self.preview_images:
         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(width=sx+dx, height=sy+dy)
     canvas.set_scroll_region(0, 0, sx+dx, sy+dy)
     self.preview_key = key
Пример #4
0
 def _loadImage(self, name):
     file = os.path.join(self.dir, name)
     image = None
     for ext in IMAGE_EXTENSIONS:
         file = os.path.join(self.dir, name+ext)
         if os.path.isfile(file):
             image = loadImage(file=file)
             break
     return image
Пример #5
0
 def showImage(self, src, alt, ismap, align, width, height):
     url = self.basejoin(src)
     try:
         img = loadImage(file=url)
     except:
         img = None
     if img:
         padx, pady = 10, 10
         padx, pady = 0, 20
         if string.lower(align) == "left":
             padx = 0
         self.text.image_create(index="insert", image=img, padx=padx, pady=pady)
         self.images.append(img)     # keep a reference
Пример #6
0
 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.event_generate('<Configure>') # update bg image
     #canvas.config(xscrollincrement=dx, yscrollincrement=dy)
     self.preview_key = key
     self.key = key
Пример #7
0
 def setTile(self, image, stretch=0, save_aspect=0):
     ##print 'setTile:', image, stretch
     if image:
         if Image:
             try:
                 self._bg_img = Image.open(image)
             except:
                 return 0
         else:
             try:
                 self._bg_img = loadImage(file=image, dither=1)
             except:
                 return 0
         self._stretch_bg_image = stretch
         self._save_aspect_bg_image = save_aspect
         self.setBackgroundImage()
     else:
         for id in self.__tiles:
             self.delete(id)
         self.__tiles = []
         self._bg_img = None
     return 1
Пример #8
0
    def __init__(self, parent, title, app, player, gameid, **kw):

        font_name = app.getFont('default')
        font = tkFont.Font(parent, font_name)
        tkfont = tkFont.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:
            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
        id = 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
        id = 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
        id = 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)
Пример #9
0
 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:
             l = Tkinter.Label(info_frame, text=n,
                               anchor='w', justify='left')
             l.grid(row=row, column=0, sticky='nw')
             l = Tkinter.Label(info_frame, text=t,
                               anchor='w', justify='left')
             l.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:
             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:
         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)
Пример #10
0
    def createGraph(self, event):
        if self.mapped:
            return
        self.mapped = True

        canvas = self.canvas

        self.text_height = self.dialog.font_metrics['linespace']
        measure = self.dialog.tkfont.measure
        self.text_width_1 = measure('XX.XX')
        self.text_width_2 = measure('XX.XX.XX')

        dir = os.path.join('images', 'stats')
        try:
            fn = self.app.dataloader.findImage('progression', dir)
            self.bg_image = loadImage(fn)
            canvas.create_image(0, 0, image=self.bg_image, anchor='nw')
        except:
            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
        id = 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
        id = 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
        id = 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'))

        self.updateGraph()
Пример #11
0
    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)