Permalink
Browse files

Download progress GTK backend

  • Loading branch information...
1 parent 7589729 commit 1c5f2edfbf0b463974742ecb5db3feac1d7f1905 @mlt committed Aug 2, 2012
Showing with 164 additions and 11 deletions.
  1. +112 −0 src/core/progress.glade
  2. +32 −0 src/core/progress_gtk.py
  3. +20 −11 src/download.py
View
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <object class="GtkWindow" id="progressWindow">
+ <property name="can_focus">False</property>
+ <property name="border_width">4</property>
+ <child>
+ <object class="GtkBox" id="verticalBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">4</property>
+ <child>
+ <object class="GtkBox" id="pointBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkLabel" id="pointLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Point</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="pointCountLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="justify">right</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkProgressBar" id="pointBar">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="show_text">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="trackBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkLabel" id="trackLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Track</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="trackCountLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="justify">right</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkProgressBar" id="trackBar">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="show_text">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
View
@@ -0,0 +1,32 @@
+""" Simple GTK progress indicator """
+
+import os.path
+from gi.repository import Gtk
+
+class GtkProgress:
+
+ def __init__(self):
+ dir = os.path.dirname(__file__)
+ builder = Gtk.Builder()
+ builder.add_from_file("{:s}/progress.glade".format(dir))
+ self.window = builder.get_object("progressWindow")
+ self.trackCountLabel = builder.get_object("trackCountLabel")
+ self.trackBar = builder.get_object("trackBar")
+ self.pointCountLabel = builder.get_object("pointCountLabel")
+ self.pointBar = builder.get_object("pointBar")
+ self.window.show_all()
+ self._update()
+
+ def _update(self):
+ while Gtk.events_pending(): Gtk.main_iteration()
+
+ def track(self, name, at, end, points):
+ self.trackBar.set_fraction(float(at-1)/end)
+ self.trackCountLabel.set_text("{:d}/{:d}".format(at, end))
+ self._update()
+
+ def point(self, at, end):
+ if at % 100 == 0:
+ self.pointBar.set_fraction(float(at)/end)
+ self.pointCountLabel.set_text("{:d}/{:d}".format(at, end))
+ self._update()
View
@@ -17,19 +17,21 @@ def main():
""")
parser = argparse.ArgumentParser(description='Download tracks from Schwinn 810 GPS sport watch with HRM.')
- parser.add_argument('--port', nargs=1, dest='port',
- default=[ {'posix': '/dev/ttyUSB0', 'nt': 'COM5'}[os.name] ],
- # default=['COM5'] if os.name=='nt' else ['/dev/ttyUSB0'],
- help='Virtual COM port created by cp201x for Schwinn 810 GPS watch')
+ parser.add_argument('--port', nargs=1,
+ default=[ {'posix': '/dev/ttyUSB0', 'nt': 'COM5'}[os.name] ],
+ help='Virtual COM port created by cp201x for Schwinn 810 GPS watch')
parser.add_argument('--hook', nargs=1, default = [ None ],
- help='Callback upon track extraction')
- parser.add_argument('--dir', nargs=1, dest='dir',
- default=['.'],
- help='Where to store data')
+ help='Callback upon track extraction')
+ parser.add_argument('--dir', nargs=1,
+ default=['.'],
+ help='Where to store data')
parser.add_argument('--debug', action='store_true',
help='Dump all replies in a binary form into a single file schwinn810.bin in TEMP dir')
- parser.add_argument('--delete', dest='delete', action='store_true',
- help='Delete all data from watches after download?')
+ parser.add_argument('--delete', action='store_true',
+ help='Delete all data from watches after download?')
+ parser.add_argument('--progress', choices=['text', 'gtk'],
+ default=['text'],
+ help='Progress indicator')
# parser.add_argument('--add-year', dest='add_year', action='store_true',
# help='Creates subfolder in dir named after the current year')
# parser.add_argument('--add-id', dest='add_id', action='store_true',
@@ -41,7 +43,14 @@ def main():
d.debug = args.debug
try:
w = Writer(args.dir[0], args.hook[0])
- d.read(w, TextProgress())
+ p = TextProgress()
+ if args.progress == 'gtk':
+ try:
+ from core.progress_gtk import GtkProgress
+ p = GtkProgress()
+ except ImportError:
+ _log.error('Failed to create GTK backend')
+ d.read(w, p)
d.close()
except SerialException as e:
_log.fatal("Port can't be opened :(")

0 comments on commit 1c5f2ed

Please sign in to comment.