-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor.py
110 lines (77 loc) · 3.32 KB
/
editor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from sys import argv
from os.path import isfile
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.config import Config
from channel import ClosableChannel
from filehandler import (
FileWriter,
initialize_history,
read_from_file
)
from posacts import Actuality, HashStoreChannelListener, LatestActualityListener
from widgets.tree import TreeWidget
from widgets.history import HistoryWidget
from dsn.historiography.legato import HistoriographyNoteNoutHash, HistoriographyNoteNout, HistoriographyNoteCapo
from hashstore import NoutHashStore
from memoization import Memoization, Stores
import fonts # NOQA: import with the side-effect of configuring all fonts
Config.set('kivy', 'exit_on_escape', '0')
class EditorGUI(App):
def __init__(self, filename):
super(EditorGUI, self).__init__()
self.m = Memoization()
self.historiography_note_nout_store = NoutHashStore(
HistoriographyNoteNoutHash, HistoriographyNoteNout, HistoriographyNoteCapo)
self.filename = filename
self.setup_channels()
self.stores = Stores(self.possible_timelines, self.historiography_note_nout_store)
self.do_initial_file_read()
def setup_channels(self):
# This is the main channel of PosActs for our application.
self.history_channel = ClosableChannel() # No relation with the T.V. channel of the same name
self.possible_timelines = HashStoreChannelListener(self.history_channel).possible_timelines
self.lnh = LatestActualityListener(self.history_channel)
def do_initial_file_read(self):
if isfile(self.filename):
# ReadFromFile before connecting to the Writer to ensure that reading from the file does not write to it
read_from_file(self.filename, self.history_channel)
FileWriter(self.history_channel, self.filename)
else:
# FileWriter first to ensure that the initialization becomes part of the file.
FileWriter(self.history_channel, self.filename)
initialize_history(self.history_channel)
def add_tree_and_stuff(self, history_channel):
horizontal_layout = BoxLayout(spacing=10, orientation='horizontal')
tree = TreeWidget(
m=self.m,
stores=self.stores,
size_hint=(.5, 1),
history_channel=history_channel,
)
history_widget = HistoryWidget(
m=self.m,
stores=self.stores,
size_hint=(.5, 1),
)
horizontal_layout.add_widget(history_widget)
horizontal_layout.add_widget(tree)
self.vertical_layout.add_widget(horizontal_layout)
tree.cursor_channel.connect(history_widget.parent_cursor_update)
tree.focus = True
return tree
def build(self):
self.vertical_layout = GridLayout(spacing=10, cols=1)
tree = self.add_tree_and_stuff(self.history_channel)
tree.report_new_tree_to_app = self.add_tree_and_stuff
# we kick off with the state so far
tree.receive_from_channel(Actuality(self.lnh.nout_hash))
return self.vertical_layout
def main():
if len(argv) != 2:
print("Usage: ", argv[0], "FILENAME")
exit()
EditorGUI(argv[1]).run()
if __name__ == "__main__":
main()