示例#1
0
def apply_settings(settings, window, box1, box2, text1, text2, com_socket):
    """
	Applies the given settings to the given components.
	Settings must be a correctly formatted dictionary.
	"""
    runtime_info["settings"] = settings

    # Server port change
    if not (runtime_info["server_port"] == int(settings["server_port"])):
        runtime_info["server_port"] = int(settings["server_port"])
        runtime_info["force_reset"] = True

    text_font = (settings["font"], int(settings["font_size"]))

    if setting_handler.decode_boolean_setting(settings["double_layout"]):
        set_double_layout(window, box1, box2)
    else:
        set_single_layout(window, box1, box2)

    text1.config(font=text_font)
    text2.config(font=text_font)
    text1.config(fg=settings["text_color"], bg=settings["background_color"])
    text2.config(fg=settings["text_color"], bg=settings["background_color"])

    old_note_length = len(runtime_info["notes"])

    if settings["notes"] and noter.file_exists(settings["notes"]):
        new_notes = noter.get_notes(settings["notes"], settings["separator"])

        if new_notes:
            # Notes loaded correctly
            runtime_info["notes"] = new_notes

            new_note_length = len(new_notes)

            if not (new_note_length == old_note_length):
                show_info(
                    ("Notes Loaded", ("Loaded notes with " +
                                      str(new_note_length) + " splits.")))

                if not runtime_info["timer_running"]:
                    runtime_info["active_split"] = -1

            update_GUI(window, com_socket, text1, text2)
        else:
            show_info(config.ERRORS["NOTES_EMPTY"], True)
示例#2
0
def apply_settings(settings, window, box1, box2, text1, text2, com_socket):
	"""
	Applies the given settings to the given components.
	Settings must be a correctly formatted dictionary.
	"""
	runtime_info["settings"] = settings

	# Server port change
	if not (runtime_info["server_port"] == int(settings["server_port"])):
		runtime_info["server_port"] = int(settings["server_port"])
		runtime_info["force_reset"] = True

	text_font = (settings["font"], int(settings["font_size"]))

	if setting_handler.decode_boolean_setting(settings["double_layout"]):
		set_double_layout(window, box1, box2)
	else:
		set_single_layout(window, box1, box2)

	text1.config(font=text_font)
	text2.config(font=text_font)
	text1.config(fg=settings["text_color"], bg=settings["background_color"])
	text2.config(fg=settings["text_color"], bg=settings["background_color"])

	old_note_length = len(runtime_info["notes"])

	if settings["notes"] and noter.file_exists(settings["notes"]):
		new_notes = noter.get_notes(settings["notes"], settings["separator"])

		if new_notes:
				# Notes loaded correctly
				runtime_info["notes"] = new_notes

				new_note_length = len(new_notes)

				if not (new_note_length == old_note_length):
					show_info(("Notes Loaded",
							   ("Loaded notes with " + str(new_note_length) + " splits.")))

					if not runtime_info["timer_running"]:
						runtime_info["active_split"] = -1

				update_GUI(window, com_socket, text1, text2)
		else:
			show_info(config.ERRORS["NOTES_EMPTY"], True)
示例#3
0
def init_UI(root):
    """Draws default UI and creates event bindings."""

    # Create communication socket
    com_socket = con.init_socket()

    # Load Settings
    settings = setting_handler.load_settings()
    runtime_info["server_port"] = int(settings["server_port"])
    runtime_info["settings"] = settings

    # Graphical components
    root.geometry(settings["width"] + "x" + settings["height"])

    box1 = tkinter.Frame(root)
    box2 = tkinter.Frame(root)

    scroll1 = tkinter.Scrollbar(box1, width=config.SCROLLBAR_WIDTH)
    scroll2 = tkinter.Scrollbar(box2, width=config.SCROLLBAR_WIDTH)
    scroll1.pack(side=tkinter.RIGHT, fill=tkinter.Y)
    scroll2.pack(side=tkinter.RIGHT, fill=tkinter.Y)

    text1 = tkinter.Text(box1,
                         yscrollcommand=scroll1.set,
                         wrap=tkinter.WORD,
                         cursor="arrow")
    text1.insert(tkinter.END, config.DEFAULT_MSG)
    text1.config(state=tkinter.DISABLED)
    text1.pack(fill=tkinter.BOTH, expand=True)

    text2 = tkinter.Text(box2,
                         yscrollcommand=scroll2.set,
                         wrap=tkinter.WORD,
                         cursor="arrow")
    text2.insert(tkinter.END, config.DEFAULT_MSG)
    text2.config(state=tkinter.DISABLED)
    text2.pack(fill=tkinter.BOTH, expand=True)

    scroll1.config(command=text1.yview)
    scroll2.config(command=text2.yview)

    # Set font and color for text
    text_font = (settings["font"], int(settings["font_size"]))

    text1.config(font=text_font)
    text2.config(font=text_font)
    text1.config(fg=settings["text_color"], bg=settings["background_color"])
    text2.config(fg=settings["text_color"], bg=settings["background_color"])

    if setting_handler.decode_boolean_setting(settings["double_layout"]):
        set_double_layout(root, box1, box2)
    else:
        set_single_layout(root, box1, box2)

    # create popup menu
    popup = tkinter.Menu(root, tearoff=0)
    popup.add_command(
        label=config.MENU_OPTIONS["LOAD"],
        command=(lambda: menu_load_notes(root, text1, text2, com_socket)))
    popup.add_command(label=config.MENU_OPTIONS["SETTINGS"],
                      command=(lambda: menu_open_settings(
                          root, box1, box2, text1, text2, com_socket)))

    # Set default window icon and title
    root.tk.call('wm', 'iconphoto', root._w, red_icon)
    update_title(config.DEFAULT_WINDOW["TITLE"], root)

    # Check if notes can be loaded from settings
    settings = setting_handler.load_settings()

    if settings["notes"] and noter.file_exists(settings["notes"]):
        notes = noter.get_notes(settings["notes"], settings["separator"])

        if notes:
            runtime_info["notes"] = notes
            update_GUI(root, com_socket, text1, text2)

    # Event binds
    root.bind("<Configure>", (lambda e: adjust_content(root, box1, box2)))
    root.bind("<Button-3>", (lambda e: show_popup(e, popup)))
    root.bind("<Right>",
              (lambda e: right_arrow(root, com_socket, text1, text2)))
    root.bind("<Left>", (lambda e: left_arrow(root, com_socket, text1, text2)))

    # Window close bind
    root.protocol("WM_DELETE_WINDOW", (lambda: do_on_close(root)))

    # call update loop
    update(root, com_socket, text1, text2)

    root.geometry(settings["width"] + "x" + settings["height"])
示例#4
0
def init_UI(root):
	"""Draws default UI and creates event bindings."""

	# Create communication socket
	com_socket = con.init_socket()

	# Load Settings
	settings = setting_handler.load_settings()
	runtime_info["server_port"] = int(settings["server_port"])
	runtime_info["settings"] = settings

	# Graphical components
	root.geometry(settings["width"] + "x" + settings["height"])

	box1 = tkinter.Frame(root)
	box2 = tkinter.Frame(root)

	scroll1 = tkinter.Scrollbar(box1, width=config.SCROLLBAR_WIDTH)
	scroll2 = tkinter.Scrollbar(box2, width=config.SCROLLBAR_WIDTH)
	scroll1.pack(side=tkinter.RIGHT, fill=tkinter.Y)
	scroll2.pack(side=tkinter.RIGHT, fill=tkinter.Y)

	text1 = tkinter.Text(
		box1,
		yscrollcommand=scroll1.set,
		wrap=tkinter.WORD,
		cursor="arrow"
	)
	text1.insert(tkinter.END, config.DEFAULT_MSG)
	text1.config(state=tkinter.DISABLED)
	text1.pack(fill=tkinter.BOTH, expand=True)

	text2 = tkinter.Text(
		box2,
		yscrollcommand=scroll2.set,
		wrap=tkinter.WORD,
		cursor="arrow"
	)
	text2.insert(tkinter.END, config.DEFAULT_MSG)
	text2.config(state=tkinter.DISABLED)
	text2.pack(fill=tkinter.BOTH, expand=True)

	scroll1.config(command=text1.yview)
	scroll2.config(command=text2.yview)

	# Set font and color for text
	text_font = (settings["font"], int(settings["font_size"]))

	text1.config(font=text_font)
	text2.config(font=text_font)
	text1.config(fg=settings["text_color"], bg=settings["background_color"])
	text2.config(fg=settings["text_color"], bg=settings["background_color"])

	if setting_handler.decode_boolean_setting(settings["double_layout"]):
		set_double_layout(root, box1, box2)
	else:
		set_single_layout(root, box1, box2)

	# create popup menu
	popup = tkinter.Menu(root, tearoff=0)
	popup.add_command(
		label=config.MENU_OPTIONS["LOAD"],
		command=(lambda: menu_load_notes(root, text1, text2, com_socket))
	)
	popup.add_command(
		label=config.MENU_OPTIONS["SETTINGS"],
		command=(lambda: menu_open_settings(root, box1, box2, text1, text2, com_socket))
	)

	# Set default window icon and title
	root.tk.call('wm', 'iconphoto', root._w, red_icon)
	update_title(config.DEFAULT_WINDOW["TITLE"], root)

	# Check if notes can be loaded from settings
	settings = setting_handler.load_settings()

	if settings["notes"] and noter.file_exists(settings["notes"]):
		notes = noter.get_notes(settings["notes"], settings["separator"])

		if notes:
			runtime_info["notes"] = notes
			update_GUI(root, com_socket, text1, text2)

	# Event binds
	root.bind("<Configure>", (lambda e: adjust_content(root, box1, box2)))
	root.bind("<Button-3>", (lambda e: show_popup(e, popup)))
	root.bind("<Right>", (lambda e: right_arrow(root, com_socket, text1, text2)))
	root.bind("<Left>", (lambda e: left_arrow(root, com_socket, text1, text2)))

	# Window close bind
	root.protocol("WM_DELETE_WINDOW", (lambda: do_on_close(root)))

	# call update loop
	update(root, com_socket, text1, text2)

	root.geometry(settings["width"] + "x" + settings["height"])