예제 #1
0
 def _parse_Fonts(self):
     "parse user specified fonts, used in creating customized Styles"
     self.defaultFont = tkFont(font="TkDefaultFont") # system default font
     self.Fonts = {'default': self.defaultFont}
     for node in self.root.findall("Fonts/Font"):
         attrib = node.attrib
         try:
             self.Fonts[attrib['name']] = tkFont(font=tuple(attrib.values())[1:])
         except Exception as e:
             print(f"{e}, create font '{attrib['name']}' failed, using default font!")
예제 #2
0
파일: kkk.py 프로젝트: MemberA2600/Boo-T
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self._textFont = tkFont(name="TextFont")
        self._textFont.configure(
            **tkFont.nametofont("TkDefaultFont").configure())

        toolbar = tk.Frame(self, borderwidth=0)
        container = tk.Frame(self,
                             borderwidth=1,
                             relief="sunken",
                             width=600,
                             height=600)
        container.grid_propagate(False)
        toolbar.pack(side="top", fill="x")
        container.pack(side="bottom", fill="both", expand=True)

        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)
        text = tk.Text(container, font="TextFont")
        text.grid(row=0, column=0, sticky="nsew")

        zoomin = tk.Button(toolbar, text="+", command=self.zoom_in)
        zoomout = tk.Button(toolbar, text="-", command=self.zoom_out)
        zoomin.pack(side="left")
        zoomout.pack(side="left")

        text.insert(
            "end",
            '''Press te + and - buttons to increase or decrease the font size'''
        )
예제 #3
0
 def __init__(self, parent, width=10, height=4, font="TkDefaultFont"):
     super().__init__(
         parent,
         width=width,
         height=height,
         wrap="word",
         font=font,
     )
     self.tag_config(
         "underline",
         underline=1,
     )
     self.tag_config(
         "invert",
         background='black',
         foreground='white',
     )
     self.tag_config(
         "indent",
         lmargin1="10",
         lmargin2="25",
     )
     self.tag_config(
         "hrule",
         relief="sunken",
         borderwidth=1,
         font=tkFont(size=1),
     )
     self['state'] = "disabled"
예제 #4
0
    def setOptions(self, options):
        """
        Sets the submitted Options to the current Tkinter Widget.

        Parameters
        ----------
        options : dict
            A dictonary with the key as the property name and the value as
            the property value.
        """
        for key in options:
            if key == "id":
                self.__id = options[key]
            elif key == "font":
                opts = options[key].replace("'", "").split(", ")
                d = {}
                for opt in opts:
                    arr = opt.split(": ")
                    d[arr[0]] = arr[1]
                self.__font = tkFont(**d)
                self.configure(font=self.__font)
            elif key == "textvariable":
                self[key] = tk.StringVar(value=options[key])
            elif key in self.__numerics:
                self[key] = int(options[key])
            else:
                self[key] = options[key]
예제 #5
0
 def __init__(self, parent, width=10, height=4, font="TkDefaultFont"):
     super().__init__(
         parent,
         width=width,
         height=height,
         wrap="word",
         font=font,
     )
     self.tag_config(
         "underline",
         underline=1,
     )
     self.tag_config(
         "invert",
         background='black',
         foreground='white',
     )
     self.tag_config(
         "indent",
         lmargin1="10",
         lmargin2="25",
     )
     self.tag_config(
         "hrule",
         relief="sunken",
         borderwidth=1,
         font=tkFont(size=1),
     )
     self['state'] = "disabled"
예제 #6
0
    def __init__(self, parent, width=10, height=4, font="TkDefaultFont"):
        self.font = nametofont(font)
        self.bold_font = self.font.copy()
        self.italic_font = self.font.copy()

        self.bold_font['weight'] = 'bold'
        self.italic_font['slant'] = 'italic'

        super().__init__(
            parent,
            width=width,
            height=height,
            wrap="word",
            font=self.font,
        )
        self.tag_config(
            "underline",
            underline=1,
        )
        self.tag_config(
            "bold",
            font=self.bold_font,
        )
        self.tag_config(
            "italic",
            font=self.italic_font,
        )
        self.tag_config(
            "invert",
            background='black',
            foreground='white',
        )
        self.tag_config(
            "indent",
            # Indent the first line slightly, but indent the following
            # lines more to line up with the text.
            lmargin1="10",
            lmargin2="25",
        )
        self.tag_config(
            "hrule",
            relief="sunken",
            borderwidth=1,
            # This makes the line-height very short.
            font=tkFont(size=1),
        )
        self['state'] = "disabled"
    def __init__(self, parent, width=10, height=4, font="TkDefaultFont"):
        self.font = nametofont(font)
        self.bold_font = self.font.copy()
        self.italic_font = self.font.copy()

        self.bold_font['weight'] = 'bold'
        self.italic_font['slant'] = 'italic'

        self.link_commands = {}  # tag-id -> command

        super().__init__(
            parent,
            width=width,
            height=height,
            wrap="word",
            font=self.font,
        )

        self.heading_font = {}
        cur_size = self.font['size']
        for size in range(6, 0, -1):
            self.heading_font[size] = font = self.font.copy()
            cur_size /= 0.8735
            font.configure(weight='bold', size=round(cur_size))
            self.tag_config(
                'heading_{}'.format(size),
                font=font,
            )

        self.tag_config(
            "underline",
            underline=1,
        )
        self.tag_config(
            "bold",
            font=self.bold_font,
        )
        self.tag_config(
            "italic",
            font=self.italic_font,
        )
        self.tag_config(
            "invert",
            background='black',
            foreground='white',
        )
        self.tag_config(
            "indent",
            # Indent the first line slightly, but indent the following
            # lines more to line up with the text.
            lmargin1="10",
            lmargin2="25",
        )
        self.tag_config(
            "hrule",
            relief="sunken",
            borderwidth=1,
            # This makes the line-height very short.
            font=tkFont(size=1),
        )
        self.tag_config(
            "link",
            underline=1,
            foreground='blue',
        )

        # We can't change cursors locally for tags, so add a binding which
        # sets the widget property.
        self.tag_bind(
            "link",
            "<Enter>",
            lambda e: self.configure(cursor=utils.CURSORS['link']),
        )
        self.tag_bind(
            "link",
            "<Leave>",
            lambda e: self.configure(cursor=utils.CURSORS['regular']),
        )

        self['state'] = "disabled"
예제 #8
0
        thread.start()

    return (str(hour) + ':' +
            (str(minute) if minute >= 10 else str("0" + "" + str(minute))) +
            ':' +
            (str(second) if second >= 10 else str("0" + "" + str(second))) +
            str(' ' + meridiem))


the_time = 0
meridiem = ""
master = Tk()
master.wm_title("Snow Alarm")
master.bind("<space>", stop_alarm)
frame = Frame(master)
helv46 = tkFont(size=46)
time_label = Label(frame, text=get_time, font=helv46)
#Create file if it doesn't exist
openPrefs = open("pref.dat", "a")
openPrefs.close()
openPrefs = open("pref.dat", "r")
lines = openPrefs.readlines()
print(lines)
#Fill file if nothing is present
if len(lines) < 1:
    openPrefs.close()
    openPrefs = open("pref.dat", "w")
    openPrefs.write("NoSchoolName\nNoWebsite")
    openPrefs.close()
else:
    openPrefs.close()
예제 #9
0
    def __init__(self, parent, width=10, height=4, font="TkDefaultFont"):
        # Setup all our configuration for inserting text.
        self.font = nametofont(font)
        self.bold_font = self.font.copy()
        self.italic_font = self.font.copy()

        self.bold_font['weight'] = 'bold'
        self.italic_font['slant'] = 'italic'

        self.link_commands = {}  # tag-id -> command

        super().__init__(
            parent,
            width=width,
            height=height,
            wrap="word",
            font=self.font,
            # We only want the I-beam cursor over text.
            cursor=utils.CURSORS['regular'],
        )

        self.heading_font = {}
        cur_size = self.font['size']
        for size in range(6, 0, -1):
            self.heading_font[size] = font = self.font.copy()
            cur_size /= 0.8735
            font.configure(weight='bold', size=round(cur_size))
            self.tag_config(
                'heading_{}'.format(size),
                font=font,
            )

        self.tag_config(
            "underline",
            underline=1,
        )
        self.tag_config(
            "bold",
            font=self.bold_font,
        )
        self.tag_config(
            "italic",
            font=self.italic_font,
        )
        self.tag_config(
            "invert",
            background='black',
            foreground='white',
        )
        self.tag_config(
            "indent",
            # Indent the first line slightly, but indent the following
            # lines more to line up with the text.
            lmargin1="10",
            lmargin2="25",
        )
        self.tag_config(
            "hrule",
            relief="sunken",
            borderwidth=1,
            # This makes the line-height very short.
            font=tkFont(size=1),
        )
        self.tag_config(
            "link",
            underline=1,
            foreground='blue',
        )

        # We can't change cursors locally for tags, so add a binding which
        # sets the widget property.
        self.tag_bind(
            "link",
            "<Enter>",
            lambda e: self.configure(cursor=utils.CURSORS['link']),
        )
        self.tag_bind(
            "link",
            "<Leave>",
            lambda e: self.configure(cursor=utils.CURSORS['regular']),
        )

        self['state'] = "disabled"
예제 #10
0
    def __init__(self,
                 parent,
                 width=10,
                 height=4,
                 font="TkDefaultFont",
                 **kargs):
        # Setup all our configuration for inserting text.
        self.font = nametofont(font)
        self.bold_font = self.font.copy()
        self.italic_font = self.font.copy()

        self.bold_font['weight'] = 'bold'
        self.italic_font['slant'] = 'italic'

        # URL -> tag name and callback ID.
        self._link_commands: Dict[str, Tuple[str, str]] = {}

        super().__init__(
            parent,
            width=width,
            height=height,
            wrap="word",
            font=self.font,
            # We only want the I-beam cursor over text.
            cursor=Cursors.REGULAR,
            **kargs,
        )

        self.heading_font = {}
        cur_size: float = self.font['size']
        for size in range(6, 0, -1):
            self.heading_font[size] = font = self.font.copy()
            cur_size /= 0.8735
            font.configure(weight='bold', size=round(cur_size))
            self.tag_config(
                'heading_{}'.format(size),
                font=font,
            )

        self.tag_config(
            "underline",
            underline=True,
        )
        self.tag_config(
            "bold",
            font=self.bold_font,
        )
        self.tag_config(
            "italic",
            font=self.italic_font,
        )
        self.tag_config(
            "strikethrough",
            overstrike=True,
        )
        self.tag_config(
            "invert",
            background='black',
            foreground='white',
        )
        self.tag_config(
            "code",
            font='TkFixedFont',
        )
        self.tag_config(
            "indent",
            # Indent the first line slightly, but indent the following
            # lines more to line up with the text.
            lmargin1="10",
            lmargin2="25",
        )
        # Indent the first line slightly, but indent the following
        # lines more to line up with the text.
        self.tag_config(
            "list_start",
            lmargin1="10",
            lmargin2="25",
        )
        self.tag_config(
            "list",
            lmargin1="25",
            lmargin2="25",
        )
        self.tag_config(
            "hrule",
            relief="sunken",
            borderwidth=1,
            # This makes the line-height very short.
            font=tkFont(size=1),
        )
        self.tag_config(
            "link",
            underline=True,
            foreground='blue',
        )

        # We can't change cursors locally for tags, so add a binding which
        # sets the widget property.
        self.tag_bind(
            "link",
            "<Enter>",
            lambda e: self.__setitem__('cursor', Cursors.LINK),
        )
        self.tag_bind(
            "link",
            "<Leave>",
            lambda e: self.__setitem__('cursor', Cursors.REGULAR),
        )

        self['state'] = "disabled"
예제 #11
0
    def open_archive_browser(self):
        chosen = self.archive_dropdown.get()
        if chosen == '':
            # If nothing is selected the function returns
            return

        # We build the new tkinter window to be opened
        new_win = tkd.Toplevel()
        new_win.title('Archive browser')
        new_win.wm_attributes('-topmost', 1)

        disp_coords = tk_utils.get_displaced_geom(self.main_frame.root, 400, 460)
        new_win.geometry(disp_coords)
        new_win.focus_get()
        new_win.iconbitmap(os.path.join(getattr(sys, '_MEIPASS', os.path.abspath('.')), media_path + 'icon.ico'))
        new_win.minsize(400, 460)
        title = tkd.Label(new_win, text='Archive browser', font='Helvetica 14')

        # Handle how loading of session data should be treated in the 3 different cases
        if chosen == 'Active session':
            # Load directly from timer module
            session_time = self.main_frame.timer_tab.session_time
            laps = self.main_frame.timer_tab.laps
            drops = self.main_frame.drops_tab.drops
        elif chosen == 'Profile history':
            # Load everything from profile .json, and append data from timer module
            active = self.main_frame.load_state_file()
            laps = []
            session_time = 0
            drops = dict()
            # Concatenate information from each available session
            for key in [x for x in active.keys() if x not in ['active_state', 'extra_data']]:
                session_drops = active[key].get('drops', dict())
                for run_no, run_drop in session_drops.items():
                    drops[str(int(run_no)+len(laps))] = run_drop
                laps.extend(active[key].get('laps', []))
                session_time += active[key].get('session_time', 0)

            # Append data for active session from timer module
            for run_no, run_drop in self.main_frame.drops_tab.drops.items():
                drops[str(int(run_no) + len(laps))] = run_drop
            laps.extend(self.main_frame.timer_tab.laps)
            session_time += self.main_frame.timer_tab.session_time
        else:
            # Load selected session data from profile .json
            active = self.main_frame.load_state_file()
            chosen_archive = active.get(chosen, dict())
            session_time = chosen_archive.get('session_time', 0)
            laps = chosen_archive.get('laps', [])
            drops = chosen_archive.get('drops', dict())

        # Ensure no division by zero errors by defaulting to displaying 0
        avg_lap = sum(laps) / len(laps) if laps else 0
        pct = sum(laps) * 100 / session_time if session_time > 0 else 0

        # Configure the list frame with scrollbars which displays the archive of the chosen session
        list_win = tkd.Frame(new_win)
        list_frame = tkd.Frame(list_win)
        vscroll = ttk.Scrollbar(list_frame, orient=tk.VERTICAL)
        hscroll = ttk.Scrollbar(list_win, orient=tk.HORIZONTAL)
        txt_list = tkd.Text(list_frame, yscrollcommand=vscroll.set, xscrollcommand=hscroll.set, font='courier 10', wrap=tk.WORD, state=tk.NORMAL, cursor='', exportselection=1, name='archivebrowser')
        # txt_list.bind('<FocusOut>', lambda e: txt_list.tag_remove(tk.SEL, "1.0", tk.END))  # Lose selection when shifting focus
        vscroll.pack(side=tk.RIGHT, fill=tk.Y)
        txt_list.pack(side=tk.LEFT, fill=tk.BOTH, expand=1)
        txt_list.tag_configure("HEADER", font=tkFont(family='courier', size=12, weight='bold', underline=True))
        hscroll.config(command=txt_list.xview)
        vscroll.config(command=txt_list.yview)

        # Build header for output file with information and descriptive statistics
        output = [['Statistics'],
                  ['Character name: ', self.extra_data.get('Character name', '')],
                  ['Run type:       ', self.extra_data.get('Run type', '')],
                  ['Game mode:      ', self.extra_data.get('Game mode', 'Single Player')],
                  [''],
                  ['Total session time:   ', utils.other_utils.build_time_str(session_time)],
                  ['Total run time:       ', utils.other_utils.build_time_str(sum(laps))],
                  ['Average run time:     ', utils.other_utils.build_time_str(avg_lap)],
                  ['Fastest run time:     ', utils.other_utils.build_time_str(min(laps, default=0))],
                  ['Number of runs:       ', str(len(laps))],
                  ['Time spent in runs:   ', str(round(pct, 2)) + '%'],
                  ['']]

        # Backwards compatibility with old drop format
        for k, v in drops.items():
            for i in range(len(v)):
                if not isinstance(v[i], dict):
                    drops[k][i] = {'item_name': None, 'input': v[i], 'extra': ''}

        # List all drops collected
        if drops:
            if any(drop for drop in drops.values()):
                output.append(['Collected drops'])
            for run_no, drop in drops.items():
                if drop:
                    str_n = ' ' * max(len(str(len(laps))) - len(str(run_no)), 0) + str(run_no)
                    output.append(['Run ' + str_n, '', *[x['input'] for x in drop]])
            output.append([''])

        if laps:
            output.append(['Run times'])

        # Loop through all runs and add run times and drops for each run
        for n, lap in enumerate(laps, 1):
            str_n = ' ' * max(len(str(len(laps))) - len(str(n)), 0) + str(n)
            droplst = drops.get(str(n), [])
            tmp = ['Run ' + str_n + ': ', utils.other_utils.build_time_str(lap)]
            if droplst:
                tmp += [d['input'] for d in droplst]
            output.append(tmp)

        # Format string list to be shown in the archive browser
        for i, op in enumerate(output, 1):
            tmpstr = ''.join(op[:2])
            if len(op) > 2:
                tmpstr += ' --- ' + ', '.join(op[2:])
            if txt_list.get('1.0', tk.END) != '\n':
                tmpstr = '\n' + tmpstr
            txt_list.insert(tk.END, tmpstr)
            if op[0] in ['Statistics', 'Collected drops', 'Run times']:
                txt_list.tag_add("HEADER", str(i) + ".0", str(i) + ".0 lineend")

        # Add bold tags
        # txt_list.tag_add("BOLD", "1.0", "1.15")
        # txt_list.tag_add("BOLD", "2.0", "2.9")
        # txt_list.tag_add("BOLD", "3.0", "3.10")
        # txt_list.tag_add("BOLD", "5.0", "5.19")
        # txt_list.tag_add("BOLD", "6.0", "6.15")
        # txt_list.tag_add("BOLD", "7.0", "7.17")
        # txt_list.tag_add("BOLD", "8.0", "8.17")
        # txt_list.tag_add("BOLD", "9.0", "9.15")
        # txt_list.tag_add("BOLD", "10.0", "10.19")
        # txt_list.tag_add("BOLD", "1.16", "1.0 lineend")
        # txt_list.tag_add("BOLD", "2.16", "2.0 lineend")
        # txt_list.tag_add("BOLD", "3.16", "3.0 lineend")
        # txt_list.tag_add("BOLD", "5.20", "5.0 lineend")
        # txt_list.tag_add("BOLD", "6.20", "6.0 lineend")
        # txt_list.tag_add("BOLD", "7.20", "7.0 lineend")
        # txt_list.tag_add("BOLD", "8.20", "8.0 lineend")
        # txt_list.tag_add("BOLD", "9.20", "9.0 lineend")
        # txt_list.tag_add("BOLD", "10.20", "10.0 lineend")

        txt_list.tag_add("HEADER", "12.0", "12.0 lineend")

        txt_list.config(state=tk.DISABLED)

        button_frame = tkd.Frame(new_win)
        tkd.Button(button_frame, text='Copy to clipboard', command=lambda: self.copy_to_clipboard(new_win, txt_list.get(1.0, tk.END))).pack(side=tk.LEFT, fill=tk.X)
        tkd.Button(button_frame, text='Save as .txt', command=lambda: self.save_to_txt(txt_list.get(1.0, tk.END))).pack(side=tk.LEFT, fill=tk.X)
        tkd.Button(button_frame, text='Save as .csv', command=lambda: self.save_to_csv(output)).pack(side=tk.LEFT, fill=tk.X)

        # Packs all the buttons and UI in the archive browser. Packing order is very important:
        # TOP: Title first (furthest up), then list frame
        # BOTTOM: Buttons first (furthest down) and then horizontal scrollbar
        title.pack(side=tk.TOP)
        list_win.pack(side=tk.TOP, fill=tk.BOTH, expand=1)
        list_frame.pack(side=tk.TOP, fill=tk.BOTH, expand=1)
        hscroll.pack(side=tk.BOTTOM, fill=tk.X)
        button_frame.pack(side=tk.BOTTOM)


        theme = Theme(self.main_frame.active_theme)
        theme.update_colors()