Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Hunt <ghunt@ghunt-desktop.(none)>2010-05-23 20:12:54 (GMT)
committer George Hunt <ghunt@ghunt-desktop.(none)>2010-05-23 20:12:54 (GMT)
commit1f8c0e41ce4869531394d0bd6e1b5cb9bd4ddb7b (patch)
tree51960da040d93c6e4e529ced46ffef50c73d307f
parenteffba351b95a6048982597fc6d32b7032b23f771 (diff)
gray scale color scheme, stacks rather than albums, double click for new stack, drag not done
-rw-r--r--MANIFEST27
-rw-r--r--activity/activity.info9
-rw-r--r--activity/activity.info.gh13
-rw-r--r--dbphoto.py24
-rw-r--r--display.py220
-rw-r--r--dist/XoPhoto-2.xobin908436 -> 5581311 bytes
-rw-r--r--sources.py58
-rw-r--r--xophoto.sqlitebin10842112 -> 6885376 bytes
-rw-r--r--xophotoactivity.py73
9 files changed, 321 insertions, 103 deletions
diff --git a/MANIFEST b/MANIFEST
index 3c6b959..9f05c79 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,7 +1,10 @@
xophoto.sqlite
dbphoto.py
photo_toolbar.pyo
+sinks.py
photo_toolbar.py
+ezscrollv10.zip
+sinks.pyo
display.py
dbphoto.pyo
sources.py
@@ -10,12 +13,30 @@ xophotoactivity.py
xophotoactivity.pyo
display.pyo
setup.py
-activity/scommander.svg
+startup_images/190x152shadow_1.tiff
+startup_images/stack_background_1.tiff
+startup_images/190x152shadow.tiff
+startup_images/2946277091_0675b569ff_b.jpg
+startup_images/2612132968_fcba550e13_o.jpg
+startup_images/reuiideasmynewxo.zip
+startup_images/190x152shadow.png
+startup_images/2606362543_1598e7efc0_o.jpg
+startup_images/2947130964_3019253782_b.jpg
+startup_images/2596796843_41a240f6b8_o.jpg
+startup_images/3080618900_c90371ec9a.jpg
+startup_images/3079782689_8ca8a237da.jpg
+startup_images/stack_background.png
+startup_images/2907401406_0d6d1e0bed.jpg
+startup_images/2611672629_5f0e2c0e63_o.jpg
+startup_images/stack_background.tiff
+startup_images/2928908291_c227faca09.jpg
+startup_images/2630825026_061177dc7d.jpg
+ezscroll/inlineScroll.py
+ezscroll/examples.py
+ezscroll/ezscroll.py
activity/activity.info
activity/XoPhoto.svg
-activity/activity.save
activity/activity.info.gh
-activity/XoPhotoXPs.svg
hide/image_datastore.py
hide/dbaccess.py
hide/TestGame.py
diff --git a/activity/activity.info b/activity/activity.info
index bf33295..69279f5 100644
--- a/activity/activity.info
+++ b/activity/activity.info
@@ -1,8 +1,7 @@
[Activity]
name = XoPhoto
-service_name = org.laptop.XoPhoto
-icon = XoPhoto
-exec = sugar-activity xophotoactivity.XoPhotoActivity
-show_launcher = yes
+bundle_id = org.laptop.XoPhoto
activity_version = 2
-license = GPLv2+
+icon = XoPhoto
+class = xophotoactivity.XoPhotoActivity
+ \ No newline at end of file
diff --git a/activity/activity.info.gh b/activity/activity.info.gh
index 815e9c8..69279f5 100644
--- a/activity/activity.info.gh
+++ b/activity/activity.info.gh
@@ -1,8 +1,7 @@
[Activity]
-name = Sugar Commander
-service_name = org.laptop.sugar.SugarCommander
-icon = scommander
-exec = sugar-activity sugarcommander.SugarCommander
-show_launcher = yes
-activity_version = 3
-license = GPLv2+
+name = XoPhoto
+bundle_id = org.laptop.XoPhoto
+activity_version = 2
+icon = XoPhoto
+class = xophotoactivity.XoPhotoActivity
+ \ No newline at end of file
diff --git a/dbphoto.py b/dbphoto.py
index ab80730..247810a 100644
--- a/dbphoto.py
+++ b/dbphoto.py
@@ -77,6 +77,13 @@ class DbAccess():
mime_list.append(m[2])
return mime_list
+ def get_mime_type(self,jobject_id):
+ self.cur.execute("select * from picture where jobject_id = '%s'"%jobject_id)
+ rows = self.cur.fetchall()
+ if len(rows) > 0:
+ return rows[0]['mime_type']
+ return None
+
def get_album_list(self):
sql = 'select max duplicate from picture group by album'
album_list,cur = self.dbdo(sql)
@@ -128,6 +135,23 @@ class DbAccess():
if len(rows)>0: return True
return False
+ def get_last_album(self):
+ cursor = self.con.cursor()
+ cursor.execute("select * from config where name = 'last_album'")
+ rows = cursor.fetchmany()
+ if len(rows)>0:
+ return (rows[0]['value'],rows[0]['id'],)
+ return None,0
+
+ def set_last_album(self,album_id):
+ cursor = self.con.cursor()
+ value,id = self.get_last_album()
+ if id > 0:
+ cursor.execute("update config set value = ? where id = ?",(album_id,id))
+ else:
+ cursor.execute("insert into config (name,value) values (?,?)",('last_ablum',album_id))
+ self.con.commit()
+
def table_exists(self,table):
try:
sql = 'select * from %s'%table
diff --git a/display.py b/display.py
index 8ad84f7..9434f54 100644
--- a/display.py
+++ b/display.py
@@ -32,6 +32,7 @@ import math
import hashlib
import time
from threading import Timer
+import datetime
#application imports
from dbphoto import *
@@ -42,8 +43,10 @@ from sources import *
from xophotoactivity import *
#Display Module globals
-background_color = (255,255,255)
-selected_color = (0,0,255)
+background_color = (210,210,210)
+album_background_color = (170,170,170)
+album_selected_color = (210,210,210)
+selected_color = (0,230,0)
mouse_timer = time.time()
in_click_delay = False
in_drag = False
@@ -207,8 +210,8 @@ class DisplayMany():
self.picture_surface.fill(background_color)
self.screen_origin_x = 000
self.screen_origin_y = 000
- self.pict_per_row = 8
- self.num_rows = 6
+ self.pict_per_row = 5
+ self.num_rows = 4
self.display_start_index = index
self.origin_row = 0
self.last_selected = None
@@ -266,12 +269,24 @@ class DisplayMany():
screen.blit(self.picture_surface,(album_column_width,0))
self.select_pict(self.selected_index)
+ def clear(self):
+ #self.picture_surface = pygame.Surface((self.screen_width,self.screen_height))
+ self.pict_dict = {}
+ self.picture_surface.fill(background_color)
+
def click(self,x,y):
#first determine if the x,y pair are within the displayed thumbnails
thumb_index = int((y // self.xy_size) * self.pict_per_row + (x - album_column_width) // self.xy_size)
if thumb_index <= self.display_end_index:
self.selected_index = thumb_index
self.select_pict(self.selected_index)
+
+ def get_jobject_id_at_xy(self,x,y):
+ #first determine if the x,y pair are within the displayed thumbnails
+ thumb_index = int((y // self.xy_size) * self.pict_per_row + (x - album_column_width) // self.xy_size)
+ if thumb_index <= self.display_end_index:
+ return self.rows[thumb_index]['jobject_id']
+ return None
def toggle(self,x,y):
if not self.large_displayed:
@@ -327,7 +342,7 @@ class DisplayMany():
#self.display_start_index = self.selected_index
if self.selected_index >= (self.origin_row + self.num_rows) * self.pict_per_row:
self.origin_row += 1
- self.paint()
+ self.paint(self.rows,self.selected_index)
self.select_pict(self.selected_index)
def next_row(self):
@@ -337,7 +352,8 @@ class DisplayMany():
self.selected_index = len(self.rows)-1
if self.selected_index >= (self.origin_row + self.num_rows) * self.pict_per_row:
self.origin_row += 1
- self.paint()
+ self.paint(self.rows,self.selected_index)
+ self.last_selected = None
self.select_pict(self.selected_index)
@@ -346,7 +362,7 @@ class DisplayMany():
self.selected_index -= 1
if self.selected_index < (self.origin_row) * self.pict_per_row:
self.origin_row -= 1
- self.paint()
+ self.paint(self.rows, self.selected_index)
self.select_pict(self.selected_index)
def prev_row(self):
@@ -354,26 +370,30 @@ class DisplayMany():
self.selected_index -= self.pict_per_row
if self.selected_index // self.pict_per_row < self.origin_row:
self.origin_row -= 1
- self.paint()
+ self.paint(self.rows,self.selected_index)
self.select_pict(self.selected_index)
class DisplayAlbums():
"""Shows the photo albums on left side of main screen, responds to clicks, drag/drop events"""
- predefined_albums = [_('Journal'),_('Trash'),_('Duplicates'),_('Last Year'),_('Last Month'),]
+ predefined_albums = [('20100521T10:42',_('Journal')),('20100521T11:40',_('Trash')),] #_('Duplicates'),_('Last Year'),_('Last Month'),]
journal_name = _('Journal')
def __init__(self,db):
global album_column_width
global background_color
+ global album_background_color
+ global album_selected_color
+ self.album_rows = None
self.album_column_width = album_column_width
- self.background_color = background_color
self.db = db #pointer to the open database
+ self.accumulation_target,id = self.db.get_last_album()
self.disp_many = DisplayMany(self.db)
self.num_of_last_rolls = 5
self.text_color = (0,0,200)
- self.selected_color = (200,200,255)
- self.album_height = 35
+ self.selected_color = album_selected_color
+ self.background_color = album_background_color
+ self.album_height = 190
self.album_font_size = 30
self.up_down_jump = 5
self.selected_index = 0
@@ -393,47 +413,58 @@ class DisplayAlbums():
i = 0
if len(rows) == 0: #it is not initialized
#first put the predefined names in the list of albums
- for album in self.predefined_albums:
+ for album_tup in self.predefined_albums:
sql = """insert into groups (category,subcategory,jobject_id,seq) \
- values ('%s','%s','%s',%s)"""%('albums',album,'',i,)
+ values ('%s','%s','%s',%s)"""%('albums',album_tup[0],album_tup[1],i,)
self.db.dbtry(sql)
i += 1
self.db.commit()
-
+ """
#following block is just to debug the situation where there are more albums than fit in one column
+ #this wont be necessary if I use scroll bar
if len(rows) < 15: #it is not long enough
conn = self.db.get_connection()
cursor = conn.cursor()
for j in range(15):
album = 'Camera Roll %s'%j
- sql = """insert into groups (category,subcategory,jobject_id,seq) \
- values ('%s','%s','%s',%s)"""%('albums',album,'',i,)
+ sql = "insert into groups (category,subcategory,jobject_id,seq) values ('%s','%s','%s',%s)"%('albums',album,'',i,)
cursor.execute(sql)
self.db.commit()
-
+ """
#then put the journal picutres into the journal album
rows, cur = self.db.dbdo('select * from picture')
i = 0
+ conn = self.db.get_connection()
+ cursor = conn.cursor()
if len(rows)>0:
for row in rows:
sql = """insert into groups (category,subcategory,jobject_id,seq) \
- values ('%s','%s','%s',%s)"""% ('journal',self.journal_name,row['jobject_id'],i,)
+ values ('%s','%s','%s',%s)"""% (self.predefined_albums[0][0],self.predefined_albums[0][1],row['jobject_id'],i,)
cursor.execute(sql)
i += 1
conn.commit()
#the initial screen will show the contents of the journal
- self.display_thumbnails('journal')
+ self.display_journal()
def display_thumbnails(self,album):
"""uses the album as value for category in table groups to display thumbnails on the right side of screen"""
- sql = "select pict.*, grp.* from picture as pict, groups as grp where grp.category = '%s' and grp.jobject_id = pict.jobject_id"%album
- rows,cur = self.db.dbdo(sql)
+ sql = """select pict.*, grp.* from picture as pict, groups as grp \
+ where grp.category = ? and grp.jobject_id = pict.jobject_id order by create_date desc"""
+ cursor = self.conn.cursor()
+ cursor.execute(sql,(str(album),))
+ rows = cursor.fetchall()
_logger.debug('album to display: %s. Number of pictures found: %s'%(album,len(rows),))
+ self.disp_many.clear()
+ self.disp_many.last_selected = None
self.disp_many.paint(rows)
+
+ def display_journal(self):
+ self.display_thumbnails('20100521T10:42')
def clear_albums(self):
- self.album_surface.fill(background_color)
+ global album_background_color
+ self.album_surface.fill(album_background_color)
def can_go_up(self):
if album_display_start > 0:
@@ -447,13 +478,20 @@ class DisplayAlbums():
def one_album(self,album,selected=False):
surf = pygame.Surface((self.album_column_width,self.album_height))
+
if selected:
surf.fill(self.selected_color)
else:
surf.fill(self.background_color)
+
+ fn = os.path.join('startup_images','stack_background.png')
+ stack = pygame.image.load(fn)
+ frame = pygame.transform.scale(stack,(190,164))
+ surf.blit(frame,(0,0))
font = pygame.font.Font(None,self.album_font_size)
text = font.render(album,0,self.text_color)
- text_rect = text.get_rect(centery=self.album_height/2)
+ text_rect = text.get_rect()
+ text_rect.midbottom = surf.get_rect().midbottom
surf.blit(text,text_rect)
_logger.debug('one album %s'%album)
return surf
@@ -461,16 +499,15 @@ class DisplayAlbums():
def paint_albums(self, start=0):
global album_display_start
global album_column_width
- sql = "select * from groups where category = 'albums'"
screen_row = 0
- rows,cur = self.db.dbdo(sql)
- self.number_of_albums = len(rows)
- if len(rows) > 0:
+ if not self.album_rows:
+ self.refresh_album_rows()
+ if len(self.album_rows) > 0:
self.clear_albums()
if start > 0:
album_display_start = start
#the logic for albums is very similar to the paint many thumbnails above
- num_albums = len(rows)
+ num_albums = len(self.album_rows)
if num_albums > album_display_start + self.max_albums_displayed:
num_albums = num_albums - album_display_start
if num_albums > self.max_albums_displayed:
@@ -480,15 +517,22 @@ class DisplayAlbums():
self.album_surface.blit(self.one_album('DOWN'),(0,(self.max_albums_displayed-1)*self.album_height))
screen_row = 1
#check for upper bound on rows
- if num_albums + album_display_start > len(rows):
- num_albums = len(rows)-album_display_start
+ if num_albums + album_display_start > len(self.album_rows):
+ num_albums = len(self.album_rows)-album_display_start
_logger.debug('paint_albums in range %s,%s'%(album_display_start, num_albums + album_display_start,))
for row_index in range(album_display_start, num_albums + album_display_start):
selected = (row_index == self.selected_index)
- self.album_surface.blit(self.one_album(rows[row_index]['subcategory'],selected),(0,screen_row * self.album_height))
+ self.album_surface.blit(self.one_album(self.album_rows[row_index]['jobject_id'],selected),(0,screen_row * self.album_height))
screen_row += 1
screen.blit(self.album_surface,(0,0))
-
+
+ def refresh_album_rows(self):
+ sql = "select * from groups where category = 'albums'"
+ rows,cur = self.db.dbdo(sql)
+ self.number_of_albums = len(rows)
+ #keep a permanent reference to the list of albums
+ self.album_rows = rows
+
def click(self,x,y):
"""select the pointed to item"""
global album_display_start
@@ -504,8 +548,62 @@ class DisplayAlbums():
album_display_start += self.up_down_jump
self.paint_albums()
#now change the thumbnail side of the screen
+ try:
+ album_name = self.album_rows[self.selected_index]['subcategory']
+ except:
+ album_name = '20100521T10:42' #the journal
+ _logger.debug('now display the thumbnails with the album identifier %s'%album_name)
+ self.display_thumbnails(album_name)
-
+ def add_to_current_album(self,jobject_id,name=None):
+ """if no current album create one. if name supplied use it
+ if there is a current album,and name but no jobject_id, change name
+ """
+ if not name: name = _("Unnamed Stack")
+ conn = self.db.get_connection()
+ cursor = conn.cursor()
+ if not self.accumulation_target:
+ self.accumulation_target = str(datetime.datetime.today())
+ _logger.debug('new album is:%s'%self.accumulation_target)
+ sql = """insert into groups (category,subcategory,jobject_id,seq) \
+ values ('%s','%s','%s',%s)"""% ('albums',self.accumulation_target,name,0,)
+ cursor.execute(sql)
+
+ #save off the unique id(timestamp)as a continuing target
+ self.db.set_last_album(self.accumulation_target)
+ else: #see if this is a request to change name
+ if jobject_id == None:
+ sql = 'select * from groups where category = ? and subcategory = ?'
+ cursor.execute(sql,('albums',self.accumulation_target))
+ rows = cursor.fetchmany()
+ if len(rows)>0 : #pick up the name
+ id = rows[0]['id']
+ sql = "update groups set jobject_id = ? where id = ?"
+ cursor.execute(sql,(name,id,))
+ return
+ #we will try to add the same picture only once
+ sql = "select * from groups where category = ? and jobject_id = ?"
+ cursor.execute(sql,(self.accumulation_target,jobject_id,))
+ rows = cursor.fetchmany()
+ if len(rows)>0: return
+
+ sql = """insert into groups (category,subcategory,jobject_id,seq) \
+ values (?,?,?,?)"""
+ cursor.execute(sql,(self.accumulation_target,name,jobject_id,0,))
+ self.db.commit()
+ #self.display_thumbnails(self.accumulation_target)
+ self.refresh_album_rows()
+ self.paint_albums()
+
+ def change_name_of_current_album(self,name):
+ """create a 'current' album (if necessary) and name it"""
+ self.add_to_current_album('',name)
+
+ def add_album_at_xy(self,x,y):
+ jobject_id = self.disp_many.get_jobject_id_at_xy(x,y)
+ if jobject_id:
+ self.add_to_current_album(jobject_id)
+
def toggle(self,x,y):
"""change the number of albums displayed"""
pass
@@ -529,6 +627,28 @@ class DisplayAlbums():
class Application():
#how far does a drag need to be not to be ignored?
drag_threshold = 10
+ def __init__(self):
+ self.db = DbAccess('xophoto.sqlite')
+ if not self.db.is_open():
+ _logger.debug('failed to open "xophoto.sqlite" database')
+ exit()
+ self.ds_sql = Datastore_SQLite(self.db)
+ ds_count, added = self.ds_sql.check_for_recent_images()
+ #if the picture table is empty, populate it from the journal, and initialize
+ if ds_count < 10:
+ self.first_run_setup()
+
+ def first_run_setup(self):
+
+ #scan the datastore and add new images as required
+ #the following call takes too long during startup, just do it during import
+ number_of_pictures = self.ds_sql.scan_images()
+ if number_of_pictures < 10: #put 11 images for learning and demo
+ source = os.path.join(os.environ['SUGAR_BUNDLE_PATH'],'startup_images')
+ self.ds_sql.copy_tree_to_ds(source)
+ number_of_pictures = self.ds_sql.scan_images()
+ if number_of_pictures < 10:
+ _logger.debug('failed to initalize the datastore with at least 10 pictures')
def run(self):
global screen
@@ -536,31 +656,19 @@ class Application():
global screen_w
global screen_h
- self.db = DbAccess('xophoto.sqlite')
- if not self.db.is_open():
- _logger.debug('failed to open "xophoto.sqlite" database')
- return
- #scan the datastore and add new images as required
- #if the picture table is empty, populate it from the journal, and initialize
- self.conn = self.db.get_connection()
- sql = "select * from picture"
- rows,cur = self.db.dbdo(sql)
- if len(rows) < 20: #it is not initialized
- ds_sql = Datastore_SQLite(self.db)
- #the following call takes too long during startup, just do it during import
- ds_sql.scan_images()
if True:
-
running = True
do_display = True
-
- pygame.init()
- pygame.display.set_mode((0, 0), pygame.RESIZABLE)
screen = pygame.display.get_surface()
info = pygame.display.Info()
screen_w = info.current_w
screen_h = info.current_h
_logger.debug('startup screen sizes w:%s h:%s '%(screen_w,screen_h,))
+ if screen_h < 400:
+ screen_h = 780
+ screen_w = 1200
+ #there is a startup bug which causes this intermittentl
+ #return
# Clear Display
screen.fill((255,255,255)) #255 for white
@@ -615,6 +723,7 @@ class Application():
in_click_delay = False
else: #just a single click
self.process_mouse_click(x, y)
+ pygame.display.flip()
elif event.type == MOUSEMOTION:
self.drag(x, y)
elif event.type == MOUSEBUTTONUP:
@@ -656,7 +765,7 @@ class Application():
def process_mouse_double_click(self,x,y):
print('double click')
if x > album_column_width:
- self.albums.disp_many.toggle(x,y)
+ self.albums.add_album_at_xy(x,y)
pygame.display.flip()
def mouse_timer_running(self):
@@ -672,7 +781,12 @@ class Application():
in_click_delay = False
-if __name__ == '__main__':
+def main():
+ pygame.init()
+ pygame.display.set_mode((0, 0), pygame.RESIZABLE)
ap = Application()
ap.run()
+
+if __name__ == '__main__':
+ main()
diff --git a/dist/XoPhoto-2.xo b/dist/XoPhoto-2.xo
index 0ccb3cf..d12925e 100644
--- a/dist/XoPhoto-2.xo
+++ b/dist/XoPhoto-2.xo
Binary files differ
diff --git a/sources.py b/sources.py
index e936d70..3108389 100644
--- a/sources.py
+++ b/sources.py
@@ -55,7 +55,7 @@ class Datastore_SQLite():
returns a list of journal object ids that have mime_type equal to one
of the entries in mimetype table of xophoto database.
"""
- rtn = []
+ rtn = 0
mime_list = self.db.get_mime_list()
(results,count) = datastore.find({})
for f in results:
@@ -65,13 +65,29 @@ class Datastore_SQLite():
if dict["mime_type"] in mime_list:
#record the id, file size, file date, in_ds
self.db.create_picture_record(f.object_id, f.get_file_path())
- rtn.append(f.object_id)
+ rtn += 1
f.destroy()
self.db.commit()
- _logger.debug('%s found in journal'%count)
+ _logger.debug('%s entries found in journal. Number of pictures %s'%(count,rtn,))
return rtn
-
+ def check_for_recent_images(self):
+ find_spec = {'mime_type':['image/png','image/jpg','image/tif','image/bmp','image/gif']}
+ (results,count) = datastore.find(find_spec)
+ _logger.debug('directed image datastore found:%s'%count)
+ added = 0
+ for ds in results:
+ #at least for now assume that the newest images are tetured first
+ sql = "select * from picture where jobject_id ='%s'"%ds.object_id
+ rows,cur = self.db.dbdo(sql)
+ if len(rows) == 0:
+ self.db.create_picture_record(ds.object_id, ds.get_file_path())
+ added += 1
+ ds.destroy()
+ _logger.debug('added %s images from datastore to picture'%added)
+ return (count,added,)
+
+
def get_filename_from_jobject_id(self, id):
try:
ds_obj = datastore.get(id)
@@ -84,9 +100,9 @@ class Datastore_SQLite():
return(fn)
return None
-class filetree():
- def __init__(self,fn):
- self.db = dbaccess(fn)
+class FileTree():
+ def __init__(self,db):
+ self.db = db
self.dialog = None
def get_path(self):
@@ -126,12 +142,13 @@ class filetree():
return fname
def copy_tree_to_ds(self,path):
- added = 0
- if os.path.isdir(path):
- files = os.listdir(path)
- for f in files:
+ added = 0
+ for dirpath, dirnames, filenames in os.walk(path):
+ for filename in filenames:
+ abs_path = os.path.join(dirpath, filename)
+ #print abs_path
mtype = ''
- chunks = f.split('.')
+ chunks = abspath.split('.')
if len(chunks)>1:
ext = chunks[-1]
if ext == 'jpg' or ext == 'jpeg':
@@ -141,19 +158,18 @@ class filetree():
elif ext == 'png':
mtype = 'image/png'
if mtype == '': continue
- fullname = os.path.join(path,f)
- info = os.stat(fullname)
+ info = os.stat(abspath)
size = info.st_size
- if self.db.check_in_ds(fullname,size): continue
+ if self.db.check_in_ds(abspath,size): continue
ds = datastore.create()
- ds.metadata['filename'] = fullname
- ds.metadata['title'] = f
+ ds.metadata['filename'] = abspath
+ ds.metadata['title'] = filename
ds.metadata['mime_type'] = mtype
- dest = os.path.join(os.environ['SUGAR_ACTIVITY_ROOT'],'instance',f)
- shutil.copyfile(fullname,dest)
+ dest = os.path.join(os.environ['SUGAR_ACTIVITY_ROOT'],'instance',filename)
+ shutil.copyfile(abspath,dest)
ds.set_file_path(dest)
datastore.write(ds,transfer_ownership=True)
- self.db.update_picture(ds.object_id,fullname)
+ self.db.update_picture(ds.object_id,abspath)
ds.destroy()
added += 1
return added
@@ -174,7 +190,7 @@ if __name__ == '__main__':
exit()
for i in imagelist:
print('\n%s'%ds.get_filename_from_jobject_id(i))
- ft = filetree('xophoto.sqlite')
+ ft = FileTree('xophoto.sqlite')
#new = ft.fill_ds()
print('%s datastore records added'%new)
else:
diff --git a/xophoto.sqlite b/xophoto.sqlite
index 5867bf6..fb71ec5 100644
--- a/xophoto.sqlite
+++ b/xophoto.sqlite
Binary files differ
diff --git a/xophotoactivity.py b/xophotoactivity.py
index d88d8cc..5fce101 100644
--- a/xophotoactivity.py
+++ b/xophotoactivity.py
@@ -45,6 +45,8 @@ import shutil
import display
import photo_toolbar
+from sources import *
+from sinks import *
#Application Globals
album_column_width = 200
@@ -60,29 +62,35 @@ console_handler.setFormatter(console_formatter)
class XoPhotoActivity(activity.Activity):
def __init__(self, handle):
- if handle and handle.object_id != '':
+ if handle and handle.object_id and handle.object_id != '':
+ _logger.debug('At activity startup, handle.object_id is %s'%handle.object_id)
make_jobject = False
else:
make_jobject = True
+ _logger.debug('At activity startup, handle.object_id is None. Making a new datastore entry')
+
+ #This is a new invocation, copy the sqlite database to the data directory
+ source = os.path.join(os.getcwd(),'xophoto.sqlite.template')
+ dest = os.path.join(os.environ['SUGAR_ACTIVITY_ROOT'],'data','xophoto.sqlite')
+ if handle.object_id == None and source != dest:
+ shutil.copy('./xophoto.sqlite',dest)
+
activity.Activity.__init__(self, handle, create_jobject = make_jobject)
- """
- #for development purposes, copy the sqlite database to the data directory
- source = os.path.join(os.getcwd(),'xophoto.sqlite')
- dest = os.path.join(os.environ['SUGAR_ACTIVITY_ROOT'],'data','xophoto.sqlite')
- if handle.object_id == None and source != dest:
- shutil.copy('./xophoto.sqlite',dest)
- """
+
+ #initialize variables
+ self.file_tree = None
+
# Build the activity toolbar.
self.build_toolbar()
- # Create the game instance.
- self.game = display.Application()
-
# Build the Pygame canvas.
self._pygamecanvas = sugargame.canvas.PygameCanvas(self)
# Note that set_canvas implicitly calls read_file when resuming from the Journal.
self.set_canvas(self._pygamecanvas)
+ # Create the game instance.
+ self.game = display.Application()
+
# Start the game running.
self._pygamecanvas.run_pygame(self.game.run)
@@ -121,10 +129,33 @@ class XoPhotoActivity(activity.Activity):
self.set_toolbox(toolbox)
def edit_toolbar_doimport_cb(self, view_toolbar):
- pass
+ if not self.file_tree:
+ self.file_tree = FileTree(self.game.db)
+ path = self.file_tree.get_path()
+ pygame.display.flip()
+ if path:
+ self.file_tree.copy_tree_to_ds(path)
+ Datastore_SQLite().scan_images()
def use_toolbar_doexport_cb(self,use_toolbar):
- pass
+ if not self.file_tree:
+ self.file_tree = FileTree(self.game.db)
+ path = self.file_tree.get_path()
+ pygame.display.flip
+ if path:
+ _logger.debug("write selected album to %s"%path)
+
+
+ #figure out how to access correct object model:album_name = self.album_rows[self.selected_index]['subcategory']
+ album_object = self.game.albums
+ album_name = album_object.album_rows[album_object.selected_index]['subcategory']
+ sql = "select pict.*, grp.* from picture as pict, groups as grp where grp.category = '%s' and grp.jobject_id = pict.jobject_id"%album
+ rows,cur = album_object.db.dbdo(sql)
+ _logger.debug('album to display: %s. Number of pictures found: %s'%(album,len(rows),))
+ #def __init__(self,rows,db,sources,path):
+ exporter = ExportAlbum(rows,self.game.db,path)
+ exporter.do_export()
+
def use_toolbar_doupload_cb(self,use_toolbar):
pass
@@ -133,6 +164,10 @@ class XoPhotoActivity(activity.Activity):
pass
def read_file(self, file_path):
+ _logger.debug('read_file %s'%file_path)
+
+ dict = self.get_metadata()
+ _logger.debug('title was %s'%dict.get('title','no title given'))
sql_file = open(file_path, "rb")
local_path = os.path.join(os.environ['SUGAR_ACTIVITY_ROOT'],'data','xophoto.sqlite')
f = open(local_path, 'wb')
@@ -141,15 +176,20 @@ class XoPhotoActivity(activity.Activity):
while sql_file:
block = sql_file.read(4096)
f.write(block)
+
except IOError, e:
_logger.debug('read sqlite file to local error %s'%e)
+ return
finally:
f.close
sql_file.close()
+ self.game.db.opendb(f)
def write_file(self, file_path):
try:
+ self.game.db.closedb()
local_path = os.path.join(os.environ['SUGAR_ACTIVITY_ROOT'],'data','xophoto.sqlite')
+ #local_path = os.path.join(os.environ['SUGAR_BUNDLE_PATH'],'xophoto.sqlite')
self.metadata['filename'] = local_path
self.metadata['mime_type'] = 'application/binary'
#dest = os.path.join(os.environ['SUGAR_ACTIVITY_ROOT'],'instance',f)
@@ -159,6 +199,11 @@ class XoPhotoActivity(activity.Activity):
except Exception,e:
_logger.debug('write_file exception %s'%e)
raise e
+
+ def __stop_clicked_cb(self, button):
+ self._activity.close()
+
+
class EditToolbar(gtk.Toolbar):
__gtype_name__ = 'EditToolbar'
@@ -285,7 +330,7 @@ class UseToolbar(gtk.Toolbar):
self.stop.show()
def doexport_cb(self, button):
- self.emit('do-import')
+ self.emit('do-export')
def doupload_cb(self, button):
self.emit('do-upload')