├── utils ├── __init__.py ├── pathhelpers.py ├── pathutils.py ├── datetimehelpers.py └── peewee.py ├── res ├── .DS_Store ├── drawable │ ├── 0.png │ ├── 10.png │ ├── 20.png │ ├── 30.png │ ├── 40.png │ ├── 50.png │ ├── 60.png │ ├── 70.png │ ├── 80.png │ ├── 90.png │ ├── 100.png │ ├── 110.png │ ├── 120.png │ ├── 130.png │ ├── 140.png │ ├── 150.png │ ├── 160.png │ ├── 170.png │ ├── 180.png │ ├── 190.png │ ├── 200.png │ └── logo.png └── layout │ ├── main.xml │ └── addmealscreen.xml ├── data └── caloriesdb.db3 ├── screenshot ├── calories1.jpg └── calories2.jpg ├── README.md ├── caloriesdb.py └── main.py /utils/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/.DS_Store -------------------------------------------------------------------------------- /data/caloriesdb.db3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/data/caloriesdb.db3 -------------------------------------------------------------------------------- /res/drawable/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/0.png -------------------------------------------------------------------------------- /res/drawable/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/10.png -------------------------------------------------------------------------------- /res/drawable/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/20.png -------------------------------------------------------------------------------- /res/drawable/30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/30.png -------------------------------------------------------------------------------- /res/drawable/40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/40.png -------------------------------------------------------------------------------- /res/drawable/50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/50.png -------------------------------------------------------------------------------- /res/drawable/60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/60.png -------------------------------------------------------------------------------- /res/drawable/70.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/70.png -------------------------------------------------------------------------------- /res/drawable/80.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/80.png -------------------------------------------------------------------------------- /res/drawable/90.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/90.png -------------------------------------------------------------------------------- /res/drawable/100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/100.png -------------------------------------------------------------------------------- /res/drawable/110.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/110.png -------------------------------------------------------------------------------- /res/drawable/120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/120.png -------------------------------------------------------------------------------- /res/drawable/130.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/130.png -------------------------------------------------------------------------------- /res/drawable/140.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/140.png -------------------------------------------------------------------------------- /res/drawable/150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/150.png -------------------------------------------------------------------------------- /res/drawable/160.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/160.png -------------------------------------------------------------------------------- /res/drawable/170.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/170.png -------------------------------------------------------------------------------- /res/drawable/180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/180.png -------------------------------------------------------------------------------- /res/drawable/190.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/190.png -------------------------------------------------------------------------------- /res/drawable/200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/200.png -------------------------------------------------------------------------------- /res/drawable/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/res/drawable/logo.png -------------------------------------------------------------------------------- /screenshot/calories1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/screenshot/calories1.jpg -------------------------------------------------------------------------------- /screenshot/calories2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qpython-android/qpy-calcount/HEAD/screenshot/calories2.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | QPyCalCount is a sample project for QPython which show how to use QSL4A features. 4 | 5 | 6 | ## Runtime Screenshot 7 | 8 | ![Main screen](https://github.com/qpython-android/qpy-calcount/blob/master/screenshot/calories2.jpg?raw=true "Main screen") 9 | ![Add a Meal](https://github.com/qpython-android/qpy-calcount/blob/master/screenshot/calories1.jpg?raw=true "Add a Meal") 10 | 11 | 12 | 13 | ## How to run 14 | 15 | Please checkout this project and put it on the /sdcard/qpython/projects. 16 | 17 | You need to install qsl4ahelper-qpython2/qsl4ahelper-qpython with QPYPI before running it. 18 | 19 | ``` 20 | pip install qsl4ahelper-qpython2 21 | 22 | ``` 23 | 24 | Then you can run it from QPython's Quick Start. 25 | 26 | 27 | ## Introduction 28 | 29 | Author: Hariharan Srinath 30 | 31 | It's based on the [FullScreenWrapper2: An Python SL4A GUI framework for Android](http://srinathh.github.io/opensource/fullscreenwrapper/) 32 | 33 | ## We need your help 34 | It could be ported to QPython3 easily. You can try to port qsl4ahelper-qpython2 to qpython3 first. That will be great if you are interested in helping this. 35 | -------------------------------------------------------------------------------- /utils/pathhelpers.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Created on Jul 24, 2012 3 | 4 | @author: Admin 5 | ''' 6 | 7 | import os.path 8 | import pathutils 9 | 10 | RESOURCE_TYPE_LAYOUT = ["res","layout"] 11 | RESOURCE_TYPE_DRAWABLE = ["res","drawable"] 12 | RESOURCE_TYPE_DATA = ["data",] 13 | 14 | def get_resource_pathname(resource_filename, resource_type): 15 | retpath = pathutils.get_exec_file_dir() 16 | for subdir in resource_type: 17 | retpath = os.path.join(retpath,subdir) 18 | 19 | return os.path.join(retpath,resource_filename) 20 | 21 | def get_drawable_pathname(drawable_filename): 22 | return "file://"+get_resource_pathname(drawable_filename, RESOURCE_TYPE_DRAWABLE) 23 | 24 | def get_layout_pathname(layout_filename): 25 | return get_resource_pathname(layout_filename, RESOURCE_TYPE_LAYOUT) 26 | 27 | def get_data_pathname(data_filename): 28 | return get_resource_pathname(data_filename, RESOURCE_TYPE_DATA) 29 | 30 | def read_layout_xml(layout_filename): 31 | fil = open(get_layout_pathname(layout_filename)) 32 | xmldata = fil.read() 33 | fil.close() 34 | return xmldata 35 | 36 | if __name__ == '__main__': 37 | print get_data_pathname("abc.db3") 38 | -------------------------------------------------------------------------------- /utils/pathutils.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import os.path 4 | 5 | def get_filepath_in_exec_file_dir(filename): 6 | return os.path.join(get_exec_file_dir(), filename) 7 | 8 | def get_exec_file_dir(): 9 | return os.path.dirname(unicode(sys.argv[0])) 10 | 11 | def get_exec_file_parent_dir(): 12 | return os.path.split(unicode(os.path.dirname(sys.argv[0])))[0] 13 | 14 | def get_extension(filename): 15 | return os.path.splitext(unicode(filename))[1] 16 | 17 | def get_extension_lowercase(filename): 18 | return get_extension(unicode(filename)).lower() 19 | 20 | def get_filename_without_extension_or_path(filename): 21 | i = os.path.split(filename)[1] 22 | return os.path.splitext(i)[0] 23 | 24 | def walk_filenames_by_extension(root, extension_list): 25 | """ 26 | Walks down the root directory & matches files with specified extensions. Returns list of file-paths 27 | IMPORTANT: This converts extensions to lowercase before comparison (windows behavior) 28 | """ 29 | ret = [] 30 | for extension in extension_list: 31 | if(extension[0]!="."): 32 | use_ext = "."+extension 33 | else: 34 | use_ext = extension 35 | 36 | for dirpath, dirnames, filenames in os.walk(root): 37 | for filename in filenames: 38 | if get_extension_lowercase(filename)==use_ext.lower(): 39 | ret.append(os.path.join(dirpath,filename)) 40 | 41 | return ret 42 | -------------------------------------------------------------------------------- /utils/datetimehelpers.py: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------- 2 | # Name: module1 3 | # Purpose: 4 | # 5 | # Author: srinath.h 6 | # 7 | # Created: 13/05/2012 8 | # Copyright: (c) srinath.h 2012 9 | # Licence: 10 | #------------------------------------------------------------------------------- 11 | #!/usr/bin/env python 12 | 13 | import datetime 14 | 15 | def get_full_day_datetime_range(curdatetime): 16 | startdatetimerange = datetime.datetime.combine(curdatetime.date(),datetime.time(0,0,0)) 17 | enddatetimerange = datetime.datetime.combine(curdatetime.date(),datetime.time(23,59,59)) 18 | return (startdatetimerange,enddatetimerange) 19 | 20 | def get_full_week_datetime_range(curdatetime): 21 | weekstuff = {6:(0,6),0:(-1,5),1:(-2,4),2:(-3,3),3:(-4,2),4:(-5,1),5:(-6,0)} 22 | curdate = curdatetime.date() 23 | curweekday = curdate.weekday() 24 | startdatetimerange = datetime.datetime.combine(curdate+datetime.timedelta(weekstuff[curweekday][0]),datetime.time(0,0,0)) 25 | enddatetimerange =datetime.datetime.combine(curdate+datetime.timedelta(weekstuff[curweekday][1]),datetime.time(23,59,59)) 26 | return(startdatetimerange,enddatetimerange) 27 | 28 | def get_full_month_datetime_range(curdatetime): 29 | curmonth = curdatetime.month 30 | newmonth = curmonth 31 | wrkdatetime = curdatetime 32 | td = datetime.timedelta(1) 33 | 34 | while(newmonth==curmonth): 35 | wrkdatetime += td 36 | newmonth = wrkdatetime.month 37 | 38 | wrkdatetime -= td 39 | lastdate = wrkdatetime.day 40 | curyear = curdatetime.year 41 | 42 | startdatetimerange = datetime.datetime.combine(datetime.date(curyear, curmonth,1),datetime.time(0,0,0)) 43 | enddatetimerange = datetime.datetime.combine(datetime.date(curyear,curmonth,lastdate),datetime.time(23,59,59)) 44 | return(startdatetimerange,enddatetimerange) 45 | -------------------------------------------------------------------------------- /res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 14 | 19 | 28 | 34 | 43 | 49 | 50 | 55 | 60 |