From 22fc7017bed424b37206b13bf6a457a976998eda Mon Sep 17 00:00:00 2001 From: joelnir Date: Sun, 3 Jan 2016 23:26:03 +0100 Subject: [PATCH] Improved Looks Added a determined font and color as well as the ability to switch between big and small fonts. Also limited files that should be displayed in the "open notes" prompt. --- .gitignore | 1 + __pycache__/config.cpython-35.pyc | Bin 910 -> 1204 bytes __pycache__/note_reader.cpython-35.pyc | Bin 2421 -> 2458 bytes config.py | 18 ++++++++-- main_window.py | 45 +++++++++++++++++++++++-- note_reader.py | 2 +- 6 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e99e36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc \ No newline at end of file diff --git a/__pycache__/config.cpython-35.pyc b/__pycache__/config.cpython-35.pyc index 01bfb86d1eda24f5bd7f537cf9c01383804a8d96..7967a000c81e3d4552d3dbc91645a5c05eca7f1d 100644 GIT binary patch delta 475 zcmYk1%}N_l6vxke+^AzxHP+95WHj2CDAFz}RVbL0Nw6dnafVXwMy7L;ap;(ln?W?2 zF2zluWLbOwH-gaT@B!|&oB9fYLhm)3-pl>}f9G%x=iKijzsB;jnT+xC`s&kP0`MFD zJBHw0@w$J0EB7>t!jgs&zW)}m)ZJj4(HH=!_0V!=J=ZUl^4y1Wqe~>C| z`f;Z%L%$txtsF&MDcMD}H{6G1#Eculp1u*zW~9tYnUgXvq^PoK$>kU&E6TdjD>;WF#{4{1F{`}xOmw_<#v@!W`-zkh7=iw6eWgCMusRJ zh7@^*C|-sX1%@a-h7?7HU`^%C0*tPVTHJpAA+EvkuD$^wk+)b~i;D7#ekuCpm!uXe zq~;csR4U{bDI_Q6Ddgo(p3fvD=%>k41yNPR4YW;@e{v@CI?k00MWR4nk?3Sg7I#LK P$&D*@Y+9aLNGy>cJnV diff --git a/config.py b/config.py index 755a2d1..9e967e8 100644 --- a/config.py +++ b/config.py @@ -36,11 +36,13 @@ ICONS= {"GREEN": "green.png", "RED": "red.png"} MENU_OPTIONS = { "SINGLE": "Set Single Layout", "DOUBLE": "Set Double Layout", - "LOAD": "Load Notes" + "LOAD": "Load Notes", + "BIG": "Big Font", + "SMALL": "Small Font" } #Error messages -ERRORS = {"NOTES_EMPTY": ("Error", "Notes empty or can not be loaded!")} +ERRORS = {"NOTES_EMPTY": ("Error", "Notes empty or can't be loaded!")} #Max file size for notes MAX_FILE_SIZE = 1000000000 #1 Giga-Byte @@ -48,3 +50,15 @@ MAX_FILE_SIZE = 1000000000 #1 Giga-Byte #TO be added to title to alert user that timer is running RUNNING_ALERT = "RUNNING" +#Font for notes +FONT = {"NAME": "Arial", "SMALL": 12, "BIG": 16} + +#Color scheme +COLOR = {"TEXT": "black", "TEXT_BG": "ivory"} + +#Files tht should be displayed and opened a notes +TEXT_FILES = [ + ("Text Files", ("*.txt", "*.log", "*.asc", "*.conf", "*.cfg")), + ('All','*') + ] + diff --git a/main_window.py b/main_window.py index f6a7035..bc65969 100644 --- a/main_window.py +++ b/main_window.py @@ -1,5 +1,6 @@ import tkinter from tkinter import messagebox +from tkinter import font import socket import os @@ -14,7 +15,8 @@ runtime_info = { "icon_active": False, "active_split": -1, "notes": [], - "double_layout": False + "double_layout": False, + "big_font": False } root = tkinter.Tk() @@ -327,6 +329,25 @@ def set_title_notes(window, index, split_name = False): update_title(title, window) + +def menu_font_size(text_font, menu): + if runtime_info["big_font"]: + runtime_info["big_font"] = False + menu.entryconfig(1, label=config.MENU_OPTIONS["BIG"]) + else: + runtime_info["big_font"] = True + menu.entryconfig(1, label=config.MENU_OPTIONS["SMALL"]) + + update_font_size(text_font) + +def update_font_size(text_font): + if runtime_info["big_font"]: + font_size = config.FONT["BIG"] + else: + font_size = config.FONT["SMALL"] + + text_font.config(size=font_size) + def init_UI(root): """Draws default UI and creates event bindings.""" @@ -349,7 +370,8 @@ def init_UI(root): text1 = tkinter.Text( box1, yscrollcommand=scroll1.set, - wrap=tkinter.WORD + wrap=tkinter.WORD, + cursor="arrow" ) text1.insert(tkinter.END, config.DEFAULT_MSG) text1.config(state=tkinter.DISABLED) @@ -358,7 +380,8 @@ def init_UI(root): text2 = tkinter.Text( box2, yscrollcommand=scroll2.set, - wrap=tkinter.WORD + wrap=tkinter.WORD, + cursor="arrow" ) text2.insert(tkinter.END, config.DEFAULT_MSG) text2.config(state=tkinter.DISABLED) @@ -367,6 +390,16 @@ def init_UI(root): scroll1.config(command=text1.yview) scroll2.config(command=text2.yview) + #Set font and color for text + text_font = font.Font( + family=config.FONT["NAME"], + size=config.FONT["SMALL"] + ) + text1.config(font=text_font) + text2.config(font=text_font) + text1.config(fg=config.COLOR["TEXT"], bg=config.COLOR["TEXT_BG"]) + text2.config(fg=config.COLOR["TEXT"], bg=config.COLOR["TEXT_BG"]) + set_single_layout(root, box1, box2) #create popup menu @@ -377,6 +410,12 @@ def init_UI(root): lambda: menu_change_layout(root, box1, box2, popup) ) ) #Needs to be at index 0 + popup.add_command( + label=config.MENU_OPTIONS["BIG"], + command=( + lambda: menu_font_size(text_font, popup) + ) + ) #Needs to be at index 1 popup.add_command( label=config.MENU_OPTIONS["LOAD"], command=(lambda: menu_load_notes(root, text1, text2, com_socket)) diff --git a/note_reader.py b/note_reader.py index 8a57647..373e02c 100644 --- a/note_reader.py +++ b/note_reader.py @@ -114,7 +114,7 @@ def select_file(): Otherwise returns absolute path to selected file. """ - file = file_dia.askopenfilename() + file = file_dia.askopenfilename(filetypes=config.TEXT_FILES) if file: return file