add optional comment in playlist and GUI list
Stefan Schuermans

Stefan Schuermans commited on 2014-05-04 09:54:19
Showing 3 changed files, with 41 additions and 15 deletions.

... ...
@@ -18,13 +18,14 @@ class Playlist:
18 18
     - each line is an entry or a stop point: <line> = <entry> | <stop point>
19 19
     - entries are played one after another
20 20
     - playing halts at stop points
21
-    - <entry> = <name> <whitespace> <duration>
22
-    - <stop point> = <name>
21
+    - <entry> = <name> <whitespace> <duration> <opt_comment>
22
+    - <stop point> = <name> <opt_comment>
23 23
     - <name> = [A-Za-Z0-9_]+
24 24
     - <duration> = ((<hours>:)?<minutes>:)?<seconds>
25 25
     - <hours> = [0-9]+
26 26
     - <minutes> = [0-9]+
27
-    - <seconds> = [0-9]+(.[0-9]+)"""
27
+    - <seconds> = [0-9]+(.[0-9]+)
28
+    - <opt_comment> = <whitespace> "#" <whitespace> <some text>"""
28 29
 
29 30
   def __init__(self):
30 31
     """create a new, empty playlist object"""
... ...
@@ -32,8 +33,8 @@ class Playlist:
32 33
                       # entry = dictionary { "type": "normal" or "stop"
33 34
                       #                      "name": string, name of entry
34 35
                       #                      "durtaion": float, in seconds }
35
-    self.reEntry = re.compile("^\s*([A-Za-z0-9_]+)\s+([0-9:.]+)\s*$")
36
-    self.reStop = re.compile("^\s*([A-Za-z0-9_]+)\s*$")
36
+    self.reEntry = re.compile("^\s*([A-Za-z0-9_]+)\s+([0-9:.]+)\s*(#\s*(.*))?$")
37
+    self.reStop = re.compile("^\s*([A-Za-z0-9_]+)\s*(#\s*(.*))?$")
37 38
 
38 39
   def read(self, filename):
39 40
     """read the playlist from filename, replacing the current playlist"""
... ...
@@ -45,17 +46,27 @@ class Playlist:
45 46
         if mEntry:
46 47
           name = mEntry.group(1)
47 48
           duration = time_fmt.str2sec(mEntry.group(2))
49
+          if mEntry.group(4) is not None:
50
+            comment = mEntry.group(4)
51
+          else:
52
+            comment = ""
48 53
           self.entries.append({"type":     "normal",
49 54
                                "name":     name,
50
-                               "duration": duration})
55
+                               "duration": duration,
56
+                               "comment":  comment})
51 57
           #print("DEBUG playlist entry normal %s %f" %
52 58
           #      (self.entries[-1]["name"], self.entries[-1]["duration"]))
53 59
         else:
54 60
           mStop = self.reStop.match(line)
55 61
           if mStop:
56 62
             name = mStop.group(1)
63
+            if mStop.group(3) is not None:
64
+              comment = mStop.group(3)
65
+            else:
66
+              comment = ""
57 67
             self.entries.append({"type": "stop",
58
-                                 "name": name})
68
+                                 "name": name,
69
+                                 "comment":  comment})
59 70
             #print("DEBUG playlist entry stop")
60 71
       f.close()
61 72
     except IOError:
... ...
@@ -70,9 +81,11 @@ class Playlist:
70 81
       if entry["type"] == "normal":
71 82
         name = entry["name"]
72 83
         duration = time_fmt.sec2str(entry["duration"])
84
+        comment = entry["comment"]
73 85
       else:
74 86
         name = entry["name"]
75 87
         duration = "STOP"
76
-      store.append([idx, Pango.Weight.NORMAL, name, duration])
88
+        comment = entry["comment"]
89
+      store.append([idx, Pango.Weight.NORMAL, name, duration, comment])
77 90
       idx = idx + 1
78 91
 
... ...
@@ -1,7 +1,7 @@
1
-Intro 1:00
2
-Robots 15:00
3
-Pause_A
4
-Future 1:2:3
1
+Intro 1:00 # intro comment
2
+Robots 15:00 # robot comment
3
+Pause_A # pause comment
4
+Future 1:2:3 # future comment
5 5
 This_is_a_very_long_name_with_a_very_long_duration 11:12:13.14
6 6
 some_entries 5:6
7 7
 to_make 7:8
... ...
@@ -7,8 +7,8 @@
7 7
     <property name="title" translatable="yes">About BlinkenArea Stage Director</property>
8 8
     <property name="type_hint">dialog</property>
9 9
     <property name="program_name">BlinkenArea Stage Director</property>
10
-    <property name="version">0.1.1</property>
11
-    <property name="copyright" translatable="yes">Copyright 2013-2014 Stefan Schuermans &lt;stefan@blinkenarea.org&gt;
10
+    <property name="version">0.1.2</property>
11
+    <property name="copyright" translatable="yes">Copyright 2013-2014 Stefan Schuermans &lt;stefan@schuermans.info&gt;
12 12
 Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
13 13
 a blinkenarea.org project - https://www.blinkenarea.org/</property>
14 14
     <property name="website">https://www.blinkenarea.org</property>
... ...
@@ -353,7 +353,18 @@ a blinkenarea.org project - https://www.blinkenarea.org/</property>
353 353
                       <attributes>
354 354
                         <attribute name="text">3</attribute>
355 355
                         <attribute name="weight">1</attribute>
356
-                        <attribute name="foreground-rgba">0</attribute>
356
+                      </attributes>
357
+                    </child>
358
+                  </object>
359
+                </child>
360
+                <child>
361
+                  <object class="GtkTreeViewColumn" id="PlaylistColumnComment">
362
+                    <property name="title" translatable="yes">Comment</property>
363
+                    <child>
364
+                      <object class="GtkCellRendererText" id="PlaylistCellRendererTextComment"/>
365
+                      <attributes>
366
+                        <attribute name="text">4</attribute>
367
+                        <attribute name="weight">1</attribute>
357 368
                       </attributes>
358 369
                     </child>
359 370
                   </object>
... ...
@@ -654,6 +665,8 @@ a blinkenarea.org project - https://www.blinkenarea.org/</property>
654 665
       <column type="gchararray"/>
655 666
       <!-- column-name Duration -->
656 667
       <column type="gchararray"/>
668
+      <!-- column-name Comment -->
669
+      <column type="gchararray"/>
657 670
     </columns>
658 671
   </object>
659 672
   <object class="GtkAdjustment" id="Position">
660 673