-
Notifications
You must be signed in to change notification settings - Fork 1
/
pagesscreen.py
192 lines (166 loc) · 6.1 KB
/
pagesscreen.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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
from uiux import Screen_
from kivy.lang import Builder
from weakref import ref, proxy
from kivy.uix.widget import Widget
from kivy.animation import Animation
from listitems import PagesScreenItem
from kivy.uix.screenmanager import SlideTransition
from kivy.properties import ObjectProperty, ListProperty
class ConfigPanel(Widget):
state = None
def on_touch_down(self, touch):
if self.collide_point(*touch.pos):
return super(ConfigPanel, self).on_touch_down(touch)
else:
widget = self.parent
_anim = Animation(x=0, y=0, duration=0.2)
_anim.bind(on_complete=lambda *_: widget.remove_widget(self))
widget._anim = ref(_anim)
_anim.start(widget)
widget.polestar = lambda : None
return True
class PagesScreen(Screen_):
pages = ListProperty([])
list_view = ObjectProperty(None)
_item = ObjectProperty(proxy(PagesScreenItem))
def __init__(self, **kwargs):
self.register_event_type('on_what')
self.register_event_type('on_new_item')
self.register_event_type('on_settings')
self.register_event_type('on_selected_page')
self.register_event_type('on_root_directory')
super(PagesScreen, self).__init__(**kwargs)
def on_enter(self):
if self.root_directory:
cursor = self.root_directory.cursor()
cursor.execute("""
UPDATE [table of contents]
SET bookmark=0;
""")
def _args_converter(self, row_index, an_obj):
return {'page_number': an_obj[0],
'text': an_obj[1],
'size_hint_y': None}
def on_root_directory(self, *args):
cursor = self.root_directory.cursor()
cursor.execute("""
SELECT page_number, page
FROM [table of contents]
ORDER BY page_number;
""")
self.pages = cursor.fetchall()
def on_selected_page(self, text, index):
manager = self.manager
cursor = self.root_directory.cursor()
cursor.execute("""
SELECT COUNT(what)
FROM [notebook]
WHERE page=? AND ix<4 AND what<>'';
""",
(text,))
i = cursor.fetchall()[0][0]
if i < 3:
screen_name = 'List Screen'
else:
screen_name = 'QuickView Screen'
screen = manager.get_screen(screen_name).proxy_ref
screen.page = text
screen.page_number = index
kwargs = {'direction': 'left', 'duration': 0.2}
self.dispatch('on_screen_change', screen_name, kwargs)
del kwargs
def on_settings(self, *args):
polestar = self.polestar()
if not polestar:
polestar = ConfigPanel()
self.add_widget(polestar)
self.polestar = ref(polestar)
_anim = Animation(x=self.size[0]*0.75, duration=0.2)
self._anim = ref(_anim)
_anim.start(self)
def on_new_item(self, instance, text):
text = text.lstrip()
if text:
for page in self.pages:
if page[1] == text:
#raise error?
break
else:
cursor = self.root_directory.cursor()
cursor.execute("""
INSERT INTO [table of contents](page_number, page)
VALUES((SELECT IFNULL(MAX(ROWID), 0) FROM [table of contents])+1, ?);
""",
(text,))
#cursor.execute('commit')
self.dispatch('on_root_directory')
instance.text = ''
instance.focus = False
def on_what(self, instance, value):
cursor = self.root_directory.cursor()
cursor.execute("""
UPDATE [table of contents]
SET page=?
WHERE page_number=?;
""",
(instance.text, instance.page_number))
def on_delete(self, instance):
cursor = self.root_directory.cursor()
cursor.execute("""
DELETE FROM [table of contents]
WHERE page_number=? AND page=?;
""",
(instance.page_number, instance.text))
self.dispatch('on_root_directory')
self.polestar = lambda : None
def on_leave(self, *args):
cursor = self.root_directory.cursor()
screen = self.manager.current_screen
cursor.execute("""
UPDATE [table of contents]
SET bookmark=1
WHERE page_number=? AND page=?;
""",
(screen.page_number, screen.page))
Builder.load_string("""
#:import NavBar uiux.NavBar
#:import Button_ uiux.Button_
#:import NewItemWidget uiux.NewItemWidget
#:import DNDListView listviews.DNDListView
<ConfigPanel>:
size_hint: 0.75, 1
pos_hint: {'right':0, 'y':0}
canvas.before:
Color:
rgb: app.smoke_white
Rectangle:
pos: self.pos
size: self.size
<PagesScreen>:
name: 'Pages Screen'
list_view: list_view_id
NavBar:
id: navbar_id
text: 'Lists'
font_size: root.width*0.1
#Button_:
# font_size: self.height*0.8
# font_name: 'breezi_font-webfont.ttf'
# size_hint: 0.09375, .682
# pos_hint: {'center_x': 0.08, 'center_y': 0.5}
# text: 'E'
# on_press: root.dispatch('on_settings')
DNDListView:
id: list_view_id
data: root.pages
selection_mode: 'None'
list_item: root._item
args_converter: root._args_converter
size_hint: 1, .8
pos_hint: {'top': 0.8873}
NewItemWidget:
hint_text: 'Create New List...'
size_hint: 1, .086
pos_hint: {'y': 0}
on_text_validate: root.dispatch('on_new_item', *args[1:])
""")