Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added project/__init__.py
Empty file.
Empty file.
41 changes: 41 additions & 0 deletions project/functionality/clipboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from typing import Any


class Clipboard:
"""
This class represents an individual clipboard, to be used for cutting,
copying and pasting data.

TODO: Unused at the moment but might come in handy later for intercepting
cuts, copies and pastes.
"""

# instance = None
#
# def __new__(cls, *args, **kwargs):
# if not Clipboard.instance:
# Clipboard.instance = super().__new__(cls, *args, **kwargs)
# return Clipboard.instance

def __init__(self):
self.data = None

def set_data(self, value):
"""
Sets the data contained in this clipboard.

:param value: The data to place in the clipboard.
"""
self.data = value

def get_data(self) -> Any:
"""
Retrieve the data in this clipboard.

:return: The data in this clipboard.
"""
return self.data


# A shared instance of Clipboard that can be imported across different modules.
shared_clipboard = Clipboard()
13 changes: 13 additions & 0 deletions project/functionality/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Constants:
"""
This class is intended to house constant values used throughout the
program.
"""

# These values are used to determine whether a key press should count as
# text input or not in EditorWindow.on_key_press. They're used to check
# whether Ctrl or Alt were held during the key press.
forbidden_flags = (
0x04, # Ctrl
0x20000 # Alt
)
30 changes: 30 additions & 0 deletions project/functionality/events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from typing import Callable


class Event:
"""
This class represents an event emitter to which callbacks can be assigned.

Example:
def test_callback(value):
print(value)

new_event = Event()
new_event.add_callback(test_callback)
new_event('test input')

# This will output 'test input'
"""

def __init__(self):
self.callbacks = set()

def add_callback(self, callback: Callable):
self.callbacks.add(callback)

def take_callback(self, callback: Callable):
self.callbacks.remove(callback)

def __call__(self, *args, **kwargs):
for callback in self.callbacks:
callback(*args, **kwargs)
Empty file added project/testing/__init__.py
Empty file.
64 changes: 64 additions & 0 deletions project/testing/test_editor_window.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# This file is used to test the editor window in isolation.
# It will be removed during release.

import tkinter as tk
from project.windows.editor_window import EditorWindow, EditorContextMenu
from project.windows.editor_window_events import NewWordEventData


class TestEditorWindow(EditorWindow):
"""
A version of the editor window specifically made for testing.
"""

def __init__(self, master):
super().__init__(master)

self.text_box.tag_config('Underlined', underline=1)
self.previous_word: NewWordEventData = None

def underline_new_word(event_data: NewWordEventData):
if self.previous_word:
self.text_box.tag_remove(
'Underlined',
self.previous_word.start, self.previous_word.end
)

self.text_box.tag_add(
'Underlined', event_data.start, event_data.end
)

self.previous_word = event_data

self.new_word.add_callback(underline_new_word)

# self.test_button = tk.Button(
# master=self,
# text='test',
# command=self.test
# )

# self.test_button.grid(row=1, column=0, sticky=tk.NSEW)

# self.text_box.bind('<Button-3>', self.test)

# def test(self, *args):
# pass
# # print(self.get_text())
# # print(f'"{self.get_word_under_mouse()}"')
# # context_menu = EditorContextMenu(self)
# # context_menu.show()


if __name__ == '__main__':
root = tk.Tk()

# Hide root window.
root.withdraw()

editor_window = TestEditorWindow(root)

# This will close the hidden root window when the editor window is closed.
editor_window.protocol('WM_DELETE_WINDOW', root.destroy)

root.mainloop()
195 changes: 0 additions & 195 deletions project/windows/EditorWindow.py

This file was deleted.

Loading