From d31486060840339e8c04c95bb6d56acf59d63b8e Mon Sep 17 00:00:00 2001 From: Joelnir Date: Thu, 18 Feb 2016 21:34:02 +0100 Subject: [PATCH] Finished settings menu and automatic note loads Implemented the settings menu to the main window so the settings are applied. Moved the double layout option to the settings instead of the right click menu. Also implemented a system to automatically load the notes that were active when SplitNotes was closed last time. --- .gitignore | 3 +- __pycache__/config.cpython-35.pyc | Bin 2139 -> 2242 bytes __pycache__/ls_connection.cpython-35.pyc | Bin 2787 -> 2799 bytes __pycache__/note_reader.cpython-35.pyc | Bin 2445 -> 2572 bytes config.py | 11 +- ls_connection.py | 8 +- main_window.py | 145 ++++++++++++----------- note_reader.py | 4 + resources/config.cfg | 13 +- setting_handler.py | 48 ++++++-- 10 files changed, 135 insertions(+), 97 deletions(-) diff --git a/.gitignore b/.gitignore index e3cb549..48921a9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.pyc TESTING.py .idea -__pycache__ \ No newline at end of file +__pycache__ +resources/config.cfg \ No newline at end of file diff --git a/__pycache__/config.cpython-35.pyc b/__pycache__/config.cpython-35.pyc index f437d4070142da731ddd6bca1a26057137c360ee..57f22b177946f0c06e599998b0a853fffdedd852 100644 GIT binary patch delta 675 zcmZ9JPfrs;6u{ro-Trl@Ev4YCp@LRS)X2$5l!mqxORLf~Fo~?&zG>OGcFF8kWfJ8p zi1Q8fq&M~E(SsL{-tedw5XU@$cO7r{(<=?NG>Me!H6Aa!{X*3rghc3(H}gbqu546}42QXncYH?9ah#SQdb_gK zCPv3|x{rzY7FpBwL{4A4esvVdj!gHNKOCUl^*x_07ptR4qCf0-)b^Zxe;6)T9WS6_ zN4N4v=BXWbR|9a@#b^Ef6=JTota77bH&(V=R-0$6fELEph4DFmQ(b?^T*?Xq`b@kq z>IW&=BU9a$CfLZ$6Rv(l<|kE+8s?qBrj+LtrWNuEGZL~at9)_nv&zpYk8xw*hcw`N zPremTDB6L`DNlyFG-`7Gq8hc3m(J)Kv#%quJ?T#(?=U_S`y x6IN20OX6kpqDyLfNqmUi&<5gntR}9-XGJZZ{Rff(t~>w$ delta 595 zcmY+9&rcIU6vw|ycb9FUQi_%z{%WWaDnz;3Xd-A^s!~LYF)LEH`_?jX=_a!!>R$L8 zaBjwn;zf^o^+e(yV7#sI)D!;#CuYh8-()`d@3KIJqAjHra?*2UC9OyZo6g@lX2d?99 z1!0#REdKbYZEBe~u~e%@))H&yD?z6li&WzC)mX1Du9RcL;mq+5)h>q_iCAxxpEYcw z$Z654&sObiNz;728`XS!x>w|1d1K5P<>E9-ghTLF> zGmqyx-kYP88*DQ-A3B{-{4{F2X*r6Ykth!EzK@)8^$(fPs-7{4uLhq`KB+LJa9-hp zglrpEzHs6fm0wbBMn)&-dSRr$k}F3^#b(GNk59|;Oj8xmIuGgBC)p{cqUj}`%q{=0cvr3vT)~u@dVCAyI326VH EW8+?ky8r+H diff --git a/__pycache__/ls_connection.cpython-35.pyc b/__pycache__/ls_connection.cpython-35.pyc index ad423dc54c09537931af7cb4d07c9b97723c49f7..62c36198696976a863032f015dd2274e5fad60dd 100644 GIT binary patch delta 405 zcmaDX`d*Y%jF*?|?%$(f=^Htn7{yo^Ab=G}aR9M15EtuDPGpqet6^qHV_|4!V5((d zs9~Ah!kELzI{71`oa`;`;?$zD)S~!;{GyU5uH^i@_>zpG)WnpP3`N|N<(WKL6d8+n zC+9Hv2yg?9D?$)FlTR?o=FqAMdWHB++OcrIn zXvKVs9cWEnYI4afHXtJ{GyN8ehktO0CQA`JP)`xa=|v!8inu@ovW>YU$E_?ld%s(e5zqc|Z!keQcW!~}AJ XAc&9!5xgLRe{wUI5@v90<d!^Wdw4jVb07{!-L)5EtuAPGpqePGe?hW?-siW~gDF z+|HPz&vJ`1r#QYiKRG+KzatcqZ2{`3P_U%`HL@+>>uG$(Zs11(RVe0MVR440eGPkWneiP{Y8G#lTR) z$dJVZCYc%1m?p7_PPS&=5y*0j9cW=*YI4afHXtJ{GyN8ehktO$EtUZPpb$;wB9M2A zI6wr*SY*pVTvi|<2E@f6M=`K7Gs;eOW=ZBocH%~sXUP1`i&*b5G73y?WDi0SzQ^vx zh%7MKnDaXd-;~Q#l^1A96elEfGV{`ln1K8u0T3YzB6vUq-{gKSCCrdI$fXAWuP9ga diff --git a/__pycache__/note_reader.cpython-35.pyc b/__pycache__/note_reader.cpython-35.pyc index 2ae472aa94352865e768f27fb380103706dfde45..2e699234cf79973bc1f83a0a720fee0e39b5596e 100644 GIT binary patch delta 222 zcmeAb?h#QIvOK2^qw3^v YPBkGupbCCQekLA%9yuNz9zh;{04-@Iwg3PC delta 81 zcmeAX=@nKM", (lambda e: adjust_content(root, box1, box2))) root.bind("", (lambda e: show_popup(e, popup))) diff --git a/note_reader.py b/note_reader.py index a0b431f..211a263 100644 --- a/note_reader.py +++ b/note_reader.py @@ -120,3 +120,7 @@ def select_file(): return file else: return False + + +def file_exists(file): + return path.isfile(file) \ No newline at end of file diff --git a/resources/config.cfg b/resources/config.cfg index 05e2cfa..f3580f3 100644 --- a/resources/config.cfg +++ b/resources/config.cfg @@ -1,6 +1,7 @@ -notes= -font=times new roman -font_size=12 -server_port=34 -background_color=#4d73f4 -text_color=#ff8080 +notes=C:/Users/Joel/Documents/EA Games/Mirror's Edge/TdGame/Config/TdEngine.ini +server_port=16834 +text_color=#000000 +double_layout=True +font_size=11 +font=ms sans serif +background_color=#ffffff diff --git a/setting_handler.py b/setting_handler.py index e84ba07..01ba985 100644 --- a/setting_handler.py +++ b/setting_handler.py @@ -18,6 +18,7 @@ settings_icon_path = os.path.join( config.ICONS["SETTINGS"] ) + def load_settings(): """ Tries to load settings from file. @@ -65,10 +66,11 @@ def format_settings(file_rows): for row in file_rows: row = row.strip("\n") - parts = row.split("=") + parts = row.split("=", 1) if len(parts) == SETTING_PART_LENGTH: - settings[parts[0]] = parts[1] + # Strip to remove whitespace at end and beginning + settings[parts[0].strip()] = parts[1].strip() return settings @@ -115,6 +117,10 @@ def validate_settings(settings): if not (settings["font"] in config.AVAILABLE_FONTS): return False + if not ((settings["double_layout"] == "True") or + (settings["double_layout"] == "False")): + return False + return True @@ -156,6 +162,9 @@ def edit_settings(root_wnd, apply_method): bg_color_label = tkinter.Label(settings_wnd, text=config.SETTINGS_OPTIONS["BG_COLOR"], font=config.GUI_FONT) + layout_label = tkinter.Label(settings_wnd, + text=config.SETTINGS_OPTIONS["DOUBLE_LAYOUT"], + font=config.GUI_FONT) port_label = tkinter.Label(settings_wnd, text=config.SETTINGS_OPTIONS["SERVER_PORT"], font=config.GUI_FONT) @@ -163,6 +172,7 @@ def edit_settings(root_wnd, apply_method): text=config.SETTINGS_OPTIONS["DEFAULT_SERVER_PORT"], font=config.GUI_FONT) + # Font Selection selected_font = tkinter.StringVar(settings_wnd) selected_font.set(settings["font"]) @@ -211,7 +221,6 @@ def edit_settings(root_wnd, apply_method): def bg_color_selection(): choosen_color = colorchooser.askcolor() if choosen_color[1]: - print(choosen_color) settings["background_color"] = choosen_color[1] bg_color.configure(background=settings["background_color"]) @@ -223,6 +232,13 @@ def edit_settings(root_wnd, apply_method): port_entry = tkinter.Entry(settings_wnd, width=6, font=config.GUI_FONT) port_entry.insert(0, settings["server_port"]) + # Double Layout Selection + double_layout = tkinter.BooleanVar() + double_layout_btn = tkinter.Checkbutton(settings_wnd, variable=double_layout) + + if decode_boolean_setting(settings["double_layout"]): + double_layout_btn.select() + # Save and cancel buttons def control_and_save(): errors_found = False @@ -232,6 +248,8 @@ def edit_settings(root_wnd, apply_method): chosen_font_size = font_size_entry.get() chosen_port = port_entry.get() + settings["double_layout"] = encode_boolean_setting(double_layout.get()) + if not validate_font_size(chosen_font_size): msgbox.showerror(config.ERRORS["FONT_SIZE"][0], config.ERRORS["FONT_SIZE"][1]) errors_found = True @@ -265,17 +283,19 @@ def edit_settings(root_wnd, apply_method): font_size_label.place(x=15, y=55) text_color_label.place(x=15, y=95) bg_color_label.place(x=15, y=135) - port_label.place(x=15, y=175) - default_port_label.place(x=15, y=200) + layout_label.place(x=15, y=175) + port_label.place(x=15, y=215) + default_port_label.place(x=15, y=240) font_dropdown.place(x=178, y=15) font_size_entry.place(x=180, y=55) text_color.place(x=180, y=95) bg_color.place(x=180, y=135) - port_entry.place(x=180, y=175) + double_layout_btn.place(x=180, y=175) + port_entry.place(x=180, y=215) - save_btn.place(x=110, y=230) - cancel_btn.place(x=190, y=230) + save_btn.place(x=110, y=280) + cancel_btn.place(x=190, y=280) def validate_color(color): @@ -314,4 +334,14 @@ def save_settings(settings): for key in settings.keys(): file_content += key + "=" + settings[key] + "\n" - set_settings_file_content(file_content) \ No newline at end of file + set_settings_file_content(file_content) + + +def decode_boolean_setting(setting): + return setting == "True" + +def encode_boolean_setting(value): + if value: + return "True" + else: + return "False"