summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2016-03-29 17:02:42 +0300
committerKai Huuhko <kai.huuhko@gmail.com>2016-03-29 17:02:42 +0300
commit57c2fed5c1a86e9f91ff5e2eeb9c69b6fd18f405 (patch)
treea2668bb97dc36ab2d7d246e0a456d3e0db9599e9
parent5751770158c9a27b55599424bb2650f4f4d9e130 (diff)
Improve error message when document fails to load
-rw-r--r--lekha/app.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/lekha/app.py b/lekha/app.py
index 542ebe7..349d8d5 100644
--- a/lekha/app.py
+++ b/lekha/app.py
@@ -58,7 +58,7 @@ from efl.elementary.toolbar import Toolbar, ELM_OBJECT_SELECT_MODE_NONE
58from efl.elementary.fileselector import Fileselector 58from efl.elementary.fileselector import Fileselector
59from efl.elementary.background import Background 59from efl.elementary.background import Background
60from efl.elementary.table import Table 60from efl.elementary.table import Table
61from efl.elementary.entry import Entry 61from efl.elementary.entry import Entry, utf8_to_markup
62from efl.elementary.panel import Panel, ELM_PANEL_ORIENT_LEFT 62from efl.elementary.panel import Panel, ELM_PANEL_ORIENT_LEFT
63from efl.elementary.genlist import Genlist, GenlistItem, GenlistItemClass, \ 63from efl.elementary.genlist import Genlist, GenlistItem, GenlistItemClass, \
64 ELM_GENLIST_ITEM_TREE, ELM_GENLIST_ITEM_NONE, ELM_LIST_COMPRESS, \ 64 ELM_GENLIST_ITEM_TREE, ELM_GENLIST_ITEM_NONE, ELM_LIST_COMPRESS, \
@@ -419,6 +419,8 @@ class Document(Table):
419 self.page_count = self.doc.getNumPages() 419 self.page_count = self.doc.getNumPages()
420 except Exception as e: 420 except Exception as e:
421 log.exception("Document could not be opened because: %r", e) 421 log.exception("Document could not be opened because: %r", e)
422 self.doc = None
423 self.display_error(e)
422 return 424 return
423 t2 = time.clock() 425 t2 = time.clock()
424 log.info("Reading the doc took: %f", t2-t1) 426 log.info("Reading the doc took: %f", t2-t1)
@@ -430,7 +432,7 @@ class Document(Table):
430 def worker_check(t): 432 def worker_check(t):
431 if t.is_alive(): 433 if t.is_alive():
432 return True 434 return True
433 if self.doc and self.page_count: 435 elif self.doc and self.page_count:
434 spn.special_value_add(self.page_count, "Last") 436 spn.special_value_add(self.page_count, "Last")
435 spn.min_max = (1, self.page_count) 437 spn.min_max = (1, self.page_count)
436 438
@@ -442,16 +444,17 @@ class Document(Table):
442 self.populate_pages() 444 self.populate_pages()
443 return False 445 return False
444 446
445 self.load_notify.content.delete()
446 l = Label(
447 self.load_notify, style="marker",
448 text="Document load error", color=(255, 0, 0, 255))
449 self.load_notify.content = l
450 l.show()
451
452 timer = Timer(0.2, worker_check, t) 447 timer = Timer(0.2, worker_check, t)
453 self.parent.callback_delete_request_add(lambda x: timer.delete()) 448 self.parent.callback_delete_request_add(lambda x: timer.delete())
454 449
450 def display_error(self, exc):
451 self.load_notify.content.delete()
452 l = Label(
453 self.load_notify, style="marker",
454 text="Document load error: %s" % utf8_to_markup(str(exc)), color=(255, 0, 0, 255))
455 self.load_notify.content = l
456 l.show()
457
455 def metadata_read(self): 458 def metadata_read(self):
456 try: 459 try:
457 info = self.doc.getDocumentInfo() 460 info = self.doc.getDocumentInfo()