Skip to content

Commit

Permalink
QT download progress (default on Win32)
Browse files Browse the repository at this point in the history
* Updated tcx2web.exe in place of tcx2garmin
* Removed unnecessary antd code dependency on dbm
  • Loading branch information
mlt committed Aug 8, 2012
1 parent cab6217 commit 4bc0199
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 8 deletions.
27 changes: 27 additions & 0 deletions src/Makefile
@@ -0,0 +1,27 @@
#!/usr/bin/make -f

SUBDIRS = core

all: $(SUBDIRS)
#doc

$(SUBDIRS):
$(MAKE) -C $@

apidoc:
sphinx-apidoc --force -o doc/source .

#export PYTHONPATH:= "${OSGEO4W_ROOT}/apps/qgis/python;${OSGEO4W_ROOT}/apps/qgis/python/plugins;${HOME}/.qgis/python/plugins;${OSGEO4W_ROOT}/apps/python27/lib/site-packages"
#export PATH:= "${PATH}:${OSGEO4W_ROOT}/bin:${OSGEO4W_ROOT}/bin:${OSGEO4W_ROOT}/apps/qgis/bin:${OSGEO4W_ROOT}/apps/qgis/plugins:${OSGEO4W_ROOT}/apps/Python27/Scripts"

doc: apidoc
$(MAKE) -C doc html
# cd doc && cmd \\/c make.bat html

# @PATH=${PATH} echo %PATH%
# @PATH=${PATH} $(MAKE) -C doc html

zip:
7z a -r -x!.ropeproject -x!doc schwinn810.zip ".\*.py"

.PHONY: subdirs $(SUBDIRS) apidoc doc
5 changes: 5 additions & 0 deletions src/core/Makefile
@@ -0,0 +1,5 @@
#!/usr/bin/make -f

include ../top.make

all: ui_progress.py
91 changes: 91 additions & 0 deletions src/core/progress.ui
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="windowModality">
<enum>Qt::NonModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>230</width>
<height>108</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Download</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="pointlLayout">
<item>
<widget class="QLabel" name="pointLabel">
<property name="text">
<string>Point</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="pointCountLabel">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QProgressBar" name="pointBar">
<property name="value">
<number>0</number>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="tracklLayout">
<item>
<widget class="QLabel" name="trackLabel">
<property name="text">
<string>Track</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="trackCountLabel">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QProgressBar" name="trackBar">
<property name="value">
<number>0</number>
</property>
</widget>
</item>
</layout>
<zorder>pointBar</zorder>
<zorder>horizontalLayoutWidget</zorder>
<zorder>trackBar</zorder>
<zorder>horizontalLayoutWidget_2</zorder>
<zorder>trackCountLabel</zorder>
</widget>
<resources/>
<connections/>
</ui>
34 changes: 34 additions & 0 deletions src/core/progress_qt.py
@@ -0,0 +1,34 @@
""" Simple QT progress indicator """

from PyQt4.QtGui import QDialog, QMessageBox
from PyQt4.QtCore import Qt
from ui_progress import Ui_Dialog

# Shall we use QProgressDialog instead?

class QtProgress(QDialog):

def __init__(self):
super(QtProgress, self).__init__()
self.ui = Ui_Dialog()
self.ui.setupUi(self)

self.show()
self._update()

def _update(self):
pass
# while Gtk.events_pending(): Gtk.main_iteration()

def track(self, name, at, end, points):
self.ui.trackBar.setMaximum(end)
self.ui.trackBar.setValue(at-1)
self.ui.trackCountLabel.setText("{:d}/{:d}".format(at, end))
self._update()

def point(self, at, end):
if at % 100 == 0:
self.ui.pointBar.setMaximum(end)
self.ui.pointBar.setValue(at-1)
self.ui.pointCountLabel.setText("{:d}/{:d}".format(at, end))
self._update()
22 changes: 16 additions & 6 deletions src/download.py
Expand Up @@ -3,7 +3,7 @@
from core.device import Device, SerialException
from core.writer_csv import Writer
from core.progress_text import TextProgress
import argparse, os
import argparse, os, sys
import logging

_log = logging.getLogger(__name__)
Expand All @@ -29,7 +29,7 @@ def main():
help='Dump all replies in a binary form into a single file schwinn810.bin in TEMP dir')
parser.add_argument('--delete', action='store_true',
help='Delete all data from watches after download?')
parser.add_argument('--progress', choices=['text', 'gtk'],
parser.add_argument('--progress', choices=['none', 'text', 'gtk', 'qt'],
default=['text'],
help='Progress indicator')
# parser.add_argument('--add-year', dest='add_year', action='store_true',
Expand All @@ -39,22 +39,32 @@ def main():

args = parser.parse_args()

d = Device(args.port[0])
d.debug = args.debug
try:
d = Device(args.port[0])
d.debug = args.debug
w = Writer(args.dir[0], args.hook[0])
p = TextProgress()
p = None
if args.progress != 'none':
p = TextProgress() # default progress
if args.progress == 'gtk':
try:
from core.progress_gtk import GtkProgress
p = GtkProgress()
except ImportError:
_log.error('Failed to create GTK backend')
elif args.progress == 'qt':
try:
from PyQt4.QtGui import QApplication
from core.progress_qt import QtProgress
app = QApplication(sys.argv)
p = QtProgress()
except ImportError:
_log.error('Failed to create QT backend')
d.read(w, p)
d.close()
except SerialException as e:
_log.fatal("Port can't be opened :(")
exit(-1)
sys.exit(-1)

print("Done")

Expand Down
1 change: 1 addition & 0 deletions src/schwinn810.cmd
Expand Up @@ -6,6 +6,7 @@ SET "DIR=%USERPROFILE%\Documents\My Runs"
download.exe ^
--port COM1 ^
--hook %~dp0\babelize.cmd ^
--progress qt ^
--dir "%DIR%"

SET "GPSBABEL=C:\Program Files\GPSBabel\gpsbabel.exe"
Expand Down
3 changes: 2 additions & 1 deletion src/setup.py
Expand Up @@ -4,6 +4,7 @@
# C:\Python27\python setup.py build
# 7z a -xr!*.py* build\exe.win32-2.7\library.zip C:\Python27\Lib\site-packages\pytz

sys.path.append('web')

# Dependencies are automatically detected, but it might need fine tuning.
#"build_exe": "schwinn810_win32",
Expand All @@ -27,4 +28,4 @@
executables = [Executable("download.py", base=base), \
Executable("settings.py", base=base), \
Executable("csv2tcx.py", base=base), \
Executable("tcx2garmin.py", base=base)])
Executable("web/tcx2web.py", base=base)])
5 changes: 5 additions & 0 deletions src/top.make
@@ -0,0 +1,5 @@
# handy stuff

ui_%.py : %.ui
python -m PyQt4.uic.pyuic -x -o $@ $^

1 change: 0 additions & 1 deletion src/web/antd/plugin.py
Expand Up @@ -28,7 +28,6 @@


import logging
import dbm
import os

_log = logging.getLogger("antd.plugin")
Expand Down

0 comments on commit 4bc0199

Please sign in to comment.