Make gkeep understand list indentation, tweaks to the countdown bar in
[kiosk.git] / gkeep_renderer.py
index 0285cf13fa70b64af3e2eda480013195014e237e..bad6830e09b85247e333846f8357e6d8f4593251 100644 (file)
@@ -37,7 +37,7 @@ class gkeep_renderer(renderer.debuggable_abstaining_renderer):
         return "gkeep"
 
     def periodic_render(self, key):
-        strikethrough = re.compile('\u2611([^\n]*)\n', re.UNICODE)
+        strikethrough = re.compile('(\u2611[^\n]*)\n', re.UNICODE)
         linkify = re.compile(r'.*(https?:\/\/\S+).*')
 
         self.keep.sync()
@@ -51,18 +51,33 @@ class gkeep_renderer(renderer.debuggable_abstaining_renderer):
             contents = note.text + "\n"
             self.debug_print("Note title '%s'" % title)
             if contents != '' and not contents.isspace():
-                contents = strikethrough.sub(r'<font color="#999999">` <del>\1</del></font>\n', contents)
-                contents = contents.replace('`', '\u2611')
+                contents = strikethrough.sub('', contents)
+                contents = contents.replace(u'\u2610',
+                                            u'<LI><INPUT TYPE="checkbox">&nbsp;')
+
                 #self.debug_print("Note contents:\n%s" % contents)
                 contents = linkify.sub(r'<a href="\1">\1</a>', contents)
+
                 individual_lines = contents.split("\n")
                 num_lines = len(individual_lines)
                 max_length = 0
+                indent = 0
+                contents = ""
                 for x in individual_lines:
                     length = len(x)
                     if length > max_length:
                         max_length = length
-                contents = contents.replace("\n", "<BR>\n")
+                    spaces = len(x) - len(x.lstrip(' '))
+                    spaces /= 2
+                    x = x.lstrip(' ')
+                    if spaces > indent:
+                        x = "<UL>" + x
+                    elif spaces < indent:
+                        x = "</UL>" + x
+                    indent = spaces
+                    contents = contents + x + "\n"
+
+                individual_lines = contents.split("\n")
                 color = note.color.name.lower()
                 if color in list(self.colors_by_name.keys()):
                     color = self.colors_by_name[color]
@@ -71,7 +86,8 @@ class gkeep_renderer(renderer.debuggable_abstaining_renderer):
                 f = file_writer.file_writer(filename)
                 f.write("""
 <STYLE type="text/css">
-a:link { color:#88bfbf; }
+  a:link { color:#88bfbf; }
+  ul { list-style-type:none; }
 </STYLE>
 <DIV STYLE="border-radius: 25px; border-style: solid; padding: 20px; background-color: %s; color: #eeeeee; font-size: x-large;">
 <p style="color: #ffffff; font-size:larger"><B>%s</B></p>
@@ -81,20 +97,20 @@ a:link { color:#88bfbf; }
                                      (num_lines, max_length))
                     f.write("<TABLE BORDER=0 WIDTH=100%%><TR valign=\"top\">")
                     f.write("<TD WIDTH=50%% style=\"color:#eeeeee; font-size:large\">\n")
-                    f.write("<FONT>")
+                    f.write("<FONT><UL>")
                     count = 0
                     for x in individual_lines:
-                        f.write(x + "<BR>\n")
+                        f.write(x + "\n")
                         count += 1
                         if count == num_lines / 2:
-                            f.write("</FONT></TD>\n")
+                            f.write("</UL></FONT></TD>\n")
                             f.write("<TD WIDTH=50%% style=\"color:#eeeeee; font-size:large\">\n")
-                            f.write("<FONT>")
-                    f.write("</FONT></TD></TR></TABLE></DIV>\n");
+                            f.write("<FONT><UL>")
+                    f.write("</UL></FONT></TD></TR></TABLE></DIV>\n");
                 else:
                     self.debug_print("%d lines (max=%d chars): one column" %
                                      (num_lines, max_length))
-                    f.write("<FONT>%s</FONT>" % contents)
+                    f.write("<FONT><UL>%s</UL></FONT>" % contents)
                 f.write("</DIV>")
                 f.close()
             else: