示例#1
0
    def __init__(self, app, parent, title, **kw):
        self._url = kw['url']
        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.button = kw.default
        frame = ttk.Frame(top_frame)
        frame.pack(fill='both', expand=True, padx=kw.padx, pady=kw.pady)
        msg = ttk.Label(frame, text=kw.text, justify=kw.justify,
                        width=kw.width)
        msg.pack(fill='both', expand=True)

        if sys.version_info >= (2, 4):
            # font_name = msg.lookup('TLabel', 'font')
            font_name = 'TkDefaultFont'
            font = tkinter_font.Font(parent, name=font_name, exists=True)
            font = font.copy()
        else:
            font = tkinter_font.Font(parent, app.getFont('default'))
        font.configure(underline=True)
        url_label = ttk.Label(frame, text=kw.url, font=font,
                              foreground='blue', cursor='hand2')
        url_label.pack()
        url_label.bind('<1>', self._urlClicked)
        #
        focus = self.createButtons(bottom_frame, kw)
        self.mainloop(focus, kw.timeout)
示例#2
0
    def initialize(self):
        self.fn = None
        self.old_fn = None
        self.old_method = None
        self.old_fi = None
        self.AIM = None
        self.rmx = (368, 393)

        # matplotlib figure
        self.f = Figure(figsize=(2, 6))
        self.gs = gridspec.GridSpec(2, 2, width_ratios=[1, 2])
        self.gs.update(wspace=0.2, hspace=0.2)

        self.plt = []
        self.plt.append(self.f.add_subplot(self.gs[0]))
        self.plt.append(self.f.add_subplot(self.gs[1]))
        self.plt.append(
            self.f.add_subplot(self.gs[2],
                               sharex=self.plt[0],
                               sharey=self.plt[0]))
        self.plt.append(self.f.add_subplot(self.gs[3]))
        for i in [0, 2]:
            self.plt[i].set_adjustable('box')

        # hide until have data
        for i in range(4):
            self.plt[i].axis("off")

        # tkinter
        # set default font size for buttons
        self.font = tkFont.Font(size=11)
        self.fontB = tkFont.Font(size=12, weight='bold')

        # frames top (buttons), text, matplotlib (canvas)
        self.main_container = tk.Frame(self.parent, height=10, width=100)
        self.main_container.pack(side="top", fill="both", expand=True)

        self.button_frame = tk.Frame(self.main_container)
        # self.info_frame = tk.Frame(self.main_container)
        self.matplotlib_frame = tk.Frame(self.main_container)

        self.button_frame.pack(side="top", fill="x", expand=True)
        # self.info_frame.pack(side="top", fill="x", expand=True)
        self.matplotlib_frame.pack(side="top", fill="both", expand=True)

        self._menus()
        self._button_area()
        self._plot_canvas()
        self._text_info_box()
示例#3
0
    def __init__(self, parent, title, app, player, gameid, **kw):

        kw = self.initKw(kw)
        title = _('Statistics')
        MfxDialog.__init__(self, parent, title, kw.resizable, kw.default)

        self.font = app.getFont('default')
        self.tkfont = tkinter_font.Font(parent, self.font)
        self.font_metrics = self.tkfont.metrics()
        style = ttk.Style(parent)
        heading_font = style.lookup('Heading', 'font')  # treeview heading
        self.heading_tkfont = tkinter_font.Font(parent, heading_font)

        self.selected_game = None

        top_frame, bottom_frame = self.createFrames(kw)
        notebook = ttk.Notebook(top_frame)
        notebook.pack(expand=True, fill='both', padx=10, pady=10)

        self.notebook_tabs = []

        single_frame = SingleGameFrame(self, notebook, app, player, gameid)
        notebook.add(single_frame, text=_('Current game'))
        self.notebook_tabs.append(single_frame._w)

        all_frame = AllGamesFrame(self, notebook, app, player)
        notebook.add(all_frame, text=_('All games'))
        self.all_games_frame = all_frame
        self.notebook_tabs.append(all_frame._w)

        top_frame = TopFrame(self, notebook, app, player, gameid)
        notebook.add(top_frame, text=TOP_TITLE)
        self.notebook_tabs.append(top_frame._w)

        if player is not None:
            progr_frame = ProgressionFrame(self, notebook, app, player, gameid)
            notebook.add(progr_frame, text=_('Progression'))
            self.notebook_tabs.append(progr_frame._w)

        if StatsDialog.SELECTED_TAB < len(self.notebook_tabs):
            notebook.select(StatsDialog.SELECTED_TAB)
        bind(notebook, '<<NotebookTabChanged>>', self.tabChanged)
        # notebook.enableTraversal()
        self.notebook = notebook

        focus = self.createButtons(bottom_frame, kw)
        self.tabChanged()               # configure buttons state
        self.mainloop(focus, kw.timeout)
 def __init__(self, parent, title, app, player, gameid, **kw):
     self.app = app
     self.selected_game = None
     kw = self.initKw(kw)
     MfxDialog.__init__(self, parent, title, kw.resizable, kw.default)
     top_frame, bottom_frame = self.createFrames(kw)
     self.top_frame = top_frame
     self.createBitmaps(top_frame, kw)
     #
     self.player = player or _("Demo games")
     self.top.wm_minsize(200, 200)
     self.button = kw.default
     #
     # createChart = self.create3DBarChart
     createChart = self.createPieChart
     # createChart = self.createSimpleChart
     #  if parent.winfo_screenwidth() < 800 or parent.winfo_screenheight() <
     #        600:
     #      createChart = self.createPieChart
     #      createChart = self.createSimpleChart
     #
     self.font = self.app.getFont("default")
     self.tk_font = tkinter_font.Font(self.top, self.font)
     self.font_metrics = self.tk_font.metrics()
     self._calc_tabs()
     #
     won, lost = app.stats.getStats(player, gameid)
     createChart(app, won, lost, _("Total"))
     won, lost = app.stats.getSessionStats(player, gameid)
     createChart(app, won, lost, _("Current session"))
     #
     focus = self.createButtons(bottom_frame, kw)
     self.mainloop(focus, kw.timeout)
示例#5
0
    def __init__(self, app, parent, title, **kw):
        self._url = kw['url']
        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.button = kw.default
        frame = ttk.Frame(top_frame)
        frame.pack(fill='both', expand=True, padx=kw.padx, pady=kw.pady)
        msg = ttk.Label(frame,
                        text=kw.text,
                        justify=kw.justify,
                        width=kw.width)
        msg.pack(fill='both', expand=True)

        # font_name = msg.lookup('TLabel', 'font')
        font_name = 'TkDefaultFont'
        font = tkinter_font.Font(parent, name=font_name, exists=True)
        font = font.copy()
        font.configure(underline=True)
        url_label = ttk.Label(frame,
                              text=kw.url,
                              font=font,
                              foreground='blue',
                              cursor='hand2')
        url_label.pack()
        from pysollib.options import calcCustomMouseButtonsBinding
        url_label.bind(calcCustomMouseButtonsBinding('<{mouse_button1}>'),
                       self._urlClicked)
        #
        focus = self.createButtons(bottom_frame, kw)
        self.mainloop(focus, kw.timeout)
 def _calc_tabs(self, arg):
     tw = 15 * self.w
     # tw = 160
     self._tabs = [tw]
     font = tkinter_font.Font(self.canvas, self.font)
     for t in arg[1:]:
         tw = font.measure(t) + 20
         self._tabs.append(tw)
     self._tabs.append(10)
示例#7
0
    def createStyles(self):
        self._style = ttk.Style(master=self)

        self._fonts = {}
        self._fonts['ThumbListFont'] = tkFont.Font(family='Consolas', size=9)

        self._style.configure('ThumbList.Treeview',
                              font=self._fonts['ThumbListFont'],
                              foreground='#555555')
示例#8
0
    def __init__(self,
                 dialog,
                 parent,
                 key,
                 default,
                 font=None,
                 width=-1,
                 height=-1,
                 hbar=2,
                 vbar=3):
        self.dialog = dialog
        self.default = default
        self.n_selections = 0
        self.n_expansions = 0
        #
        disty = 16
        if width < 0:
            width = 400
        if height < 0:
            height = 20 * disty
            if parent and parent.winfo_screenheight() >= 600:
                height = 25 * disty
            if parent and parent.winfo_screenheight() >= 800:
                height = 30 * disty
            height = int(min(height, parent.winfo_screenheight() * .35))
        self.lines = height // disty
        self._calc_MfxTreeInCanvas().__init__(self,
                                              parent,
                                              self.data.rootnodes,
                                              width=width,
                                              height=height,
                                              hbar=hbar,
                                              vbar=vbar)
        self.style.distx = 20
        self.style.disty = disty
        self.style.width = 16  # width of symbol
        self.style.height = 14  # height of symbol
        if font:
            self.style.font = font
            f = tkinter_font.Font(parent, font)
            h = f.metrics()["linespace"]
            self.style.disty = max(self.style.width, h)

        self.draw()
        self.updateSelection(key)
        if self.hbar:
            # print self.data.tree_yview
            # print self.canvas.xview()
            self.canvas.xview_moveto(self.data.tree_xview[0])
        if self.vbar:
            # print self.data.tree_yview
            # print self.canvas.yview()
            self.canvas.yview_moveto(self.data.tree_yview[0])
示例#9
0
    def __init__(self, parent, title, app, player, **kw):

        self.font = app.getFont('default')
        self.tkfont = tkinter_font.Font(parent, self.font)
        style = ttk.Style(parent)
        heading_font = style.lookup('Heading', 'font')  # treeview heading
        self.heading_tkfont = tkinter_font.Font(parent, heading_font)
        self.font_metrics = self.tkfont.metrics()

        self.CHAR_H = self.font_metrics['linespace']
        self.CHAR_W = self.tkfont.measure('M')

        kw = self.initKw(kw)
        title = _('Log')
        MfxDialog.__init__(self, parent, title, kw.resizable, kw.default)

        # self.selected_game = None

        top_frame, bottom_frame = self.createFrames(kw)
        notebook = ttk.Notebook(top_frame)
        notebook.pack(expand=True, fill='both', padx=10, pady=10)

        self.notebook_tabs = []

        full_frame = FullLogFrame(self, notebook, app, player)
        notebook.add(full_frame, text=_('Full log'))
        self.notebook_tabs.append(full_frame._w)

        session_frame = SessionLogFrame(self, notebook, app, player)
        notebook.add(session_frame, text=_('Session log'))
        self.notebook_tabs.append(session_frame._w)

        notebook.select(LogDialog.SELECTED_TAB)
        #  bind(notebook, '<<NotebookTabChanged>>', self.tabChanged)

        self.notebook = notebook

        focus = self.createButtons(bottom_frame, kw)
        # self.tabChanged()               # configure buttons state
        self.mainloop(focus, kw.timeout)
示例#10
0
 def __init__(self, parent, title, app, player, **kw):
     lines = 25
     # if parent and parent.winfo_screenheight() < 600:
     #    lines = 20
     #
     self.font = app.getFont(self.FONT_TYPE)
     font = tkinter_font.Font(parent, self.font)
     self.font_metrics = font.metrics()
     self.CHAR_H = self.font_metrics['linespace']
     self.CHAR_W = font.measure('M')
     self.app = app
     #
     self.player = player
     self.title = title
     self.sort_by = 'name'
     self.selected_game = None
     #
     kwdefault(kw, width=self.CHAR_W * 64, height=lines * self.CHAR_H)
     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.top.wm_minsize(200, 200)
     self.button = kw.default
     #
     self.sc = AllGames_StatsDialogScrolledCanvas(top_frame,
                                                  width=kw.width,
                                                  height=kw.height)
     self.sc.pack(fill='both', expand=True, padx=kw.padx, pady=kw.pady)
     #
     self.nodes = {}
     self.canvas = self.sc.canvas
     self.canvas.dialog = self
     from pysollib.options import calcCustomMouseButtonsBinding
     bind(self.canvas, calcCustomMouseButtonsBinding("<{mouse_button1}>"),
          self.singleClick)
     self.fillCanvas(player, title)
     bbox = self.canvas.bbox("all")
     # print bbox
     # self.canvas.config(scrollregion=bbox)
     dx, dy = 4, 0
     self.canvas.config(scrollregion=(-dx, -dy, bbox[2] + dx, bbox[3] + dy))
     self.canvas.xview_moveto(-dx)
     self.canvas.yview_moveto(self.YVIEW)
     #
     focus = self.createButtons(bottom_frame, kw)
     self.mainloop(focus, kw.timeout)
示例#11
0
 def _start(self):
     super(GUIScreen, self)._start()
     self.root = Tk()
     self.root.geometry("%sx%s" % (self.size[0] * 7, self.size[1] * 15))
     self.root.bind("<Configure>", self.resize)
     if platform.system() == 'Windows':
         self.root.bind("<Control-MouseWheel>", self.change_font)
     else:
         self.root.bind("<Control-4>", self.change_font)
         self.root.bind("<Control-5>", self.change_font)
     self.root.protocol("WM_DELETE_WINDOW", self.closed_window)
     self.text = Text(self.root,
                      font="TkFixedFont",
                      wrap=Tkinter.NONE,
                      state=Tkinter.DISABLED,
                      background="black",
                      foreground="light gray")
     self.text.pack(side=Tkinter.LEFT,
                    fill=Tkinter.BOTH,
                    expand=Tkinter.YES)
     self.font = tkFont.Font(self.root, self.text.cget("font"))
     self.text.config(font=self.font)
     self.__prepare_tags()
示例#12
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)
示例#13
0
def get_text_width(text, font, root=None):
    return tkinter_font.Font(root=root, font=font).measure(text)
示例#14
0
    def __init__(self, *args, **kwargs):
        ttk.Frame.__init__(self, *args, **kwargs)
        self.init_settings()

        self.cookie = cookielib.MozillaCookieJar(self.cookie_filename)
        if (os.path.isfile(self.cookie_filename)):
            self.cookie.load(ignore_discard=True, ignore_expires=True)
        self.opener = urllib.request.build_opener(
            urllib.request.HTTPCookieProcessor(self.cookie))

        self.students = []
        self.username = StringVar()
        self.password = StringVar()
        self.course_listvar = StringVar()
        self.assignment_listvar = StringVar()
        self.student_listvar = StringVar()

        ttk.Label(self, text='Username: '******'Password: '******'*')
        self.password_entry.grid(column=2, row=2, sticky=(W, E))
        self.login_button = ttk.Button(self, text='Login', command=self.login)
        self.login_button.grid(column=2, row=3, stick=E)

        self.course_listbox = Listbox(self,
                                      height=6,
                                      width=35,
                                      listvariable=self.course_listvar,
                                      relief='sunken')
        self.course_listbox.grid(column=3,
                                 row=1,
                                 rowspan=3,
                                 padx=(5, 0),
                                 stick=(N, W, E, S))
        self.course_listbox.configure(exportselection=False)
        self.course_listbox.bind('<<ListboxSelect>>', self.load_assignments)
        s = ttk.Scrollbar(self,
                          orient=VERTICAL,
                          command=self.course_listbox.yview)
        s.grid(column=4, row=1, rowspan=3, sticky=(N, S))
        self.course_listbox['yscrollcommand'] = s.set

        self.assignment_listbox = Listbox(self,
                                          height=6,
                                          width=35,
                                          listvariable=self.assignment_listvar,
                                          relief='sunken')
        self.assignment_listbox.grid(column=5,
                                     row=1,
                                     rowspan=3,
                                     padx=(5, 0),
                                     stick=(N, W, E, S))
        self.assignment_listbox.configure(exportselection=False)
        self.assignment_listbox.bind('<<ListboxSelect>>', self.load_students)
        s = ttk.Scrollbar(self,
                          orient=VERTICAL,
                          command=self.assignment_listbox.yview)
        s.grid(column=6, row=1, rowspan=3, sticky=(N, S))
        self.assignment_listbox['yscrollcommand'] = s.set

        self.student_listbox = Listbox(self,
                                       height=20,
                                       listvariable=self.student_listvar,
                                       relief='sunken',
                                       font=font.Font(family='Consolas',
                                                      size=11))
        self.student_listbox.grid(column=1,
                                  row=4,
                                  columnspan=5,
                                  pady=(10, 5),
                                  stick=(N, W, E, S))
        self.student_listbox.configure(exportselection=False)
        s = ttk.Scrollbar(self,
                          orient=VERTICAL,
                          command=self.student_listbox.yview)
        s.grid(column=6, row=4, pady=(10, 5), sticky=(N, S))
        self.student_listbox['yscrollcommand'] = s.set

        self.readtxt_button = ttk.Button(self,
                                         text='读入成绩',
                                         command=self.read_txt)
        self.readtxt_button.grid(column=1, row=5, stick=E)
        self.dopublish_button = ttk.Button(self,
                                           text='确认发布',
                                           command=self.do_publish)
        self.dopublish_button.grid(column=2, row=5, stick=W)
        self.exportcsv_button = ttk.Button(self,
                                           text='导出成绩',
                                           command=self.export_csv)
        self.exportcsv_button.grid(column=3, row=5, stick=E)

        self.grid_columnconfigure(5, weight=1)
        self.grid_rowconfigure(4, weight=1)

        self.try_load_courses()