-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
158 lines (106 loc) · 4.58 KB
/
Copy pathapp.py
File metadata and controls
158 lines (106 loc) · 4.58 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
"""Interpunction Application."""
from kivy.app import App
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup
from kivy.uix.listview import ListItemButton
from kivy.properties import ObjectProperty, ListProperty
from kivy.factory import Factory
from kivy import Config
import process_text
Config.set('graphics', 'multisamples', '0')
Config.set('input', 'mouse', 'mouse,multitouch_on_demand')
class TextHandler(BoxLayout):
"""View for parsing the text."""
text_input = ObjectProperty()
def process_text(self, pattern_list, word_token):
"""`on_press` handler for button."""
text = self.text_input.text
processor = process_text.ProcessText(text, pattern_list, word_token)
self.text_input.text = processor.process()
class ConfigurationHandler(BoxLayout):
"""View for editing interpunction signs."""
pass
class InterpunctionButton(ListItemButton):
"""Interpunction button."""
interpunction_sign = ListProperty()
class CopyPastePopup(Popup):
"""Copy Paste Popup."""
def __init__(self, text_input, **kwargs):
"""Initialize the CopyPastePopup."""
super(CopyPastePopup, self).__init__(**kwargs)
self.text_input = text_input
def copy_press(self):
"""Event when the copy button is pressed."""
self.text_input.copy(data=self.text_input.selection_text)
self.dismiss()
def paste_press(self):
"""Event when the paste button is pressed."""
self.text_input.paste()
self.dismiss()
class RightClickFunctionalityTextBox(TextInput):
"""Special text input for handling mouse right click."""
def on_touch_down(self, touch):
"""On touch down event for every text input."""
if touch.button == 'right':
popup = CopyPastePopup(self)
popup.open()
else:
super(RightClickFunctionalityTextBox, self).on_touch_down(touch)
class MainMenu(BoxLayout):
"""Main menu for the application."""
pattern_list = ObjectProperty()
text_input = ObjectProperty()
def __init__(self, **kwargs):
"""Initalize the main menu."""
super(MainMenu, self).__init__(**kwargs)
self.pattern_list = process_text.PATTERN_LIST
self.word_token = process_text.WORD_TOKEN
self.selected_interpunction_sign = None
def change_configuration(self):
"""`on_press` handler for button."""
self.clear_widgets()
configuration_handler = Factory.ConfigurationHandler()
del configuration_handler.interpunction_signs.adapter.data[:]
configuration_handler.interpunction_signs.adapter.data.extend(self.pattern_list)
configuration_handler.text_box.text = self.word_token
self.add_widget(configuration_handler)
def change_word_token(self, word_token):
"""`on_press` handler for changing word token."""
self.word_token = word_token
self.change_configuration()
def open_text_handler(self):
"""`on_press` handler for button."""
self.clear_widgets()
self.add_widget(Factory.TextHandler())
def select_interpunction_sign(self, interpunction_sign):
"""`on_press` handler when interpunction sign is pressed."""
if self.selected_interpunction_sign is None:
self.selected_interpunction_sign = interpunction_sign
elif self.selected_interpunction_sign[0] == interpunction_sign[0]:
self.selected_interpunction_sign = None
else:
self.selected_interpunction_sign = interpunction_sign
def delete_interpunction_sing(self):
"""`on_press` handler when delete interpunction sign button is pressed."""
if self.selected_interpunction_sign is not None and \
len(self.pattern_list) > self.selected_interpunction_sign[0]:
del self.pattern_list[self.selected_interpunction_sign[0]]
self.selected_interpunction_sign = None
self.change_configuration()
def add_interpunction_sing(self, text):
"""`on_press` handler for adding interpunction sign button is pressed."""
self.pattern_list.insert(0, text)
self.change_configuration()
def args_converter(self, index, data_item):
"""Convert the data that it is coming in the ListViewAdapter."""
interpunction_sign = data_item
return {'interpunction_sign': (index, interpunction_sign)}
class InterpunctionApp(App):
"""Interpunction Application."""
pass
def main():
"""Main entry."""
InterpunctionApp().run()
if __name__ == '__main__':
main()