summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2015-11-15 00:54:59 +0200
committerKai Huuhko <kai.huuhko@gmail.com>2015-11-15 02:00:37 +0200
commitc1494beea27f2140ef059c95f139ae3007c355aa (patch)
treefbe74cd1079a440485902682fc625db34158ef39
parent5f3012d1fb85725ad98dded245c1b2f36381153d (diff)
Add paged scrolling
This setting is not currently being stored across application restarts.
-rw-r--r--lekha/app.py83
1 files changed, 70 insertions, 13 deletions
diff --git a/lekha/app.py b/lekha/app.py
index c130612..d5cc968 100644
--- a/lekha/app.py
+++ b/lekha/app.py
@@ -65,6 +65,9 @@ from efl.elementary.genlist import Genlist, GenlistItem, GenlistItemClass, \
65 ELM_OBJECT_SELECT_MODE_ALWAYS 65 ELM_OBJECT_SELECT_MODE_ALWAYS
66from efl.elementary.menu import Menu 66from efl.elementary.menu import Menu
67from efl.elementary.popup import Popup 67from efl.elementary.popup import Popup
68from efl.elementary.check import Check
69from efl.elementary.hover import Hover
70from efl.elementary.list import List, ELM_LIST_EXPAND
68 71
69import PyPDF2 72import PyPDF2
70 73
@@ -83,6 +86,8 @@ class AppWindow(StandardWindow):
83 self.docs = [] 86 self.docs = []
84 self.doc_specs = doc_specs 87 self.doc_specs = doc_specs
85 88
89 self.settings = {"scroll_by_page": False}
90
86 super(AppWindow, self).__init__( 91 super(AppWindow, self).__init__(
87 "main", "Lekha", 92 "main", "Lekha",
88 size=(400 * SCALE, 400 * SCALE), 93 size=(400 * SCALE, 400 * SCALE),
@@ -99,6 +104,7 @@ class AppWindow(StandardWindow):
99 "document-open", "Open", lambda x, y: Fs(self.document_open)) 104 "document-open", "Open", lambda x, y: Fs(self.document_open))
100 tb.item_append( 105 tb.item_append(
101 "view-fullscreen", "Fullscreen", lambda x, y: self.fullscreen_set(True)) 106 "view-fullscreen", "Fullscreen", lambda x, y: self.fullscreen_set(True))
107 it = tb.item_append("preferences-system", "Settings", self._settings_open)
102 108
103 tabs = self.tabs = Tabs( 109 tabs = self.tabs = Tabs(
104 main_box, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) 110 main_box, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
@@ -128,14 +134,27 @@ class AppWindow(StandardWindow):
128 134
129 def _event_handler(self, obj, src, tp, ev): 135 def _event_handler(self, obj, src, tp, ev):
130 if tp == EVAS_CALLBACK_MOUSE_WHEEL: 136 if tp == EVAS_CALLBACK_MOUSE_WHEEL:
131 if ev.direction == 0: 137 content = self.tabs.currentContent
132 if ( 138 if not content:
133 self.tabs.currentContent and 139 return True
134 self.tabs.currentContent.scroll_freeze_get()): 140 if content.scroll_freeze_get():
141 if ev.direction == 0:
135 if ev.z == 1: 142 if ev.z == 1:
136 self.tabs.currentContent.zoom_out() 143 content.zoom_out()
137 else: 144 else:
138 self.tabs.currentContent.zoom_in() 145 content.zoom_in()
146 ev.event_flags |= EVAS_EVENT_FLAG_ON_HOLD
147 elif self.settings["scroll_by_page"]: # TODO: setting for this
148 if ev.direction == 0:
149 visible = content.visible_pages
150 if not visible:
151 return True
152 visible = visible[0]
153 if ev.z == 1:
154 content.page_show_by_num(visible+1)
155 else:
156 content.page_show_by_num(visible-1)
157 ev.event_flags |= EVAS_EVENT_FLAG_ON_HOLD
139 elif tp == EVAS_CALLBACK_KEY_UP: 158 elif tp == EVAS_CALLBACK_KEY_UP:
140 key = ev.key 159 key = ev.key
141 if key == "plus": 160 if key == "plus":
@@ -150,13 +169,21 @@ class AppWindow(StandardWindow):
150 elif key == "F11": 169 elif key == "F11":
151 self.fullscreen = not self.fullscreen 170 self.fullscreen = not self.fullscreen
152 elif key == "Control_L" or key == "Control_R": 171 elif key == "Control_L" or key == "Control_R":
153 self.tabs.currentContent.scroll_thaw() 172 if self.tabs.currentContent:
173 self.tabs.currentContent.scroll_thaw()
174 else:
175 return True
176 ev.event_flags |= EVAS_EVENT_FLAG_ON_HOLD
154 elif tp == EVAS_CALLBACK_KEY_DOWN: 177 elif tp == EVAS_CALLBACK_KEY_DOWN:
155 key = ev.key 178 key = ev.key
156 if key == "Control_L" or key == "Control_R": 179 if key == "Control_L" or key == "Control_R":
157 self.tabs.currentContent.scroll_freeze() 180 if self.tabs.currentContent:
181 self.tabs.currentContent.scroll_freeze()
182 else:
183 return True
184 ev.event_flags |= EVAS_EVENT_FLAG_ON_HOLD
158 185
159 ev.event_flags |= EVAS_EVENT_FLAG_ON_HOLD 186 return True
160 187
161 @staticmethod 188 @staticmethod
162 def _fullscreen_cb(win): 189 def _fullscreen_cb(win):
@@ -207,6 +234,31 @@ class AppWindow(StandardWindow):
207 doc.callback_add("title,changed", title_changed) 234 doc.callback_add("title,changed", title_changed)
208 self.tabs.append(tab) 235 self.tabs.append(tab)
209 236
237 def _settings_open(self, obj, it):
238 h = Hover(self)
239 t = it.track_object
240 h.pos = t.bottom_center
241 del t
242 del it.track_object
243
244 l = List(h)
245 l.mode = ELM_LIST_EXPAND
246 h.part_content_set("bottom", l)
247 l.show()
248
249 chk = Check(self, text="Scroll By Page")
250 chk.state = self.settings["scroll_by_page"]
251 def _scroll_by_page_cb(obj):
252 self.settings["scroll_by_page"] = obj.state
253 h.dismiss()
254 chk.callback_changed_add(_scroll_by_page_cb)
255
256 l.item_append(None, chk)
257 l.go()
258
259 h.show()
260 #chk.callback_clicked_add()
261
210 262
211class OutLine(GenlistItemClass): 263class OutLine(GenlistItemClass):
212 264
@@ -240,6 +292,7 @@ class Document(Table):
240 self.pages = [] 292 self.pages = []
241 self.doc = None 293 self.doc = None
242 self.doc_title = os.path.splitext(os.path.basename(path))[0] 294 self.doc_title = os.path.splitext(os.path.basename(path))[0]
295 self.visible_pages = []
243 296
244 super(Document, self).__init__( 297 super(Document, self).__init__(
245 parent, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) 298 parent, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
@@ -507,8 +560,8 @@ class Document(Table):
507 560
508 self.zoom *= viewport_width/widest 561 self.zoom *= viewport_width/widest
509 562
510 @staticmethod 563 def _viewport_in(self, obj, ei, n):
511 def _viewport_in(obj, ei, n): 564 self.visible_pages.append(obj.page_num)
512 l = obj.page_num_label 565 l = obj.page_num_label
513 b = n.content 566 b = n.content
514 b.pack_end(l) 567 b.pack_end(l)
@@ -516,8 +569,8 @@ class Document(Table):
516 l.show() 569 l.show()
517 n.show() 570 n.show()
518 571
519 @staticmethod 572 def _viewport_out(self, obj, ei, n):
520 def _viewport_out(obj, ei, n): 573 self.visible_pages.remove(obj.page_num)
521 l = obj.page_num_label 574 l = obj.page_num_label
522 b = n.content 575 b = n.content
523 b.unpack(l) 576 b.unpack(l)
@@ -549,6 +602,10 @@ class Document(Table):
549 break 602 break
550 603
551 def page_show_by_num(self, pg_num): 604 def page_show_by_num(self, pg_num):
605 if pg_num < 0:
606 pg_num = 0
607 elif pg_num > self.page_count - 1:
608 pg_num = -1
552 pg_id, pg = self.pages[pg_num] 609 pg_id, pg = self.pages[pg_num]
553 self.page_show(pg) 610 self.page_show(pg)
554 611