# TouchComic V1.5 for Nokia S60 5th Ed, From JamieFuller.com
# Copyright (C) 2009 Jamie Fuller
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import appuifw, e32, graphics, zipfile, os, math,key_codes
def read_settings():
global startzoom, shownums, zoom, passwd
if not os.path.isdir("c:\\comics"):
os.mkdir("c:\\comics")
if not os.path.isfile("c:\\comics\\config.dat"):
shownums=1
startzoom=1
write_settings()
else:
f = open("c:\\comics\\config.dat", "r")
s=f.read()
f.close()
startzoom=int(s[0])
shownums=int(s[1])
zoom=int(s[2])
passwd=s[3:]
if passwd=="": passwd="password"
def write_settings():
global startzoom, shownums, zoom, passwd
f = open("c:\\comics\\config.dat", "w")
f.write(str(startzoom))
f.write(str(shownums))
f.write(str(zoom))
f.write(passwd)
f.close()
def write_bmark():
global drive_letter
global page,filenm
f = open(drive_letter+"\\comics\\"+filenm+".bmk", "w")
f.write(str(page))
f.close()
def quit():
global running
running=0
def toggle_screen():
global screen_state
global old_page
global screen_re, mouse_timer, xpos, ypos
if screen_state==0:
appuifw.app.screen = 'full'
screen_state=1
else:
appuifw.app.screen = 'normal'
screen_state=0
old_page=-1
screen_re=1
mouse_timer = xpos = ypos = 0
def select_drive():
global drive_letter
global cbrisloaded
drives=e32.drive_list()
drive_letter=drives[appuifw.selection_list(drives)]
cbrisloaded=0
def item1():
if cbrisloaded>0: toggle_screen()
def loadCBR():
global cbrisloaded
global nmlist
global nmcount
global z, ypos, page, screen_re, old_page
global filenm
global locked
global drive_letter
cbrisloaded=0
z=None
tf=[]
ypos = page = screen_re = 0
old_page=-1
files=map(unicode,os.listdir(drive_letter+"\\comics"))
for i in files:
if locked>0:
if i[-3:]=="zip" or i[-3:]=="cbz" or i[-3:]=="ZIP" or i[-3:]=="CBZ" or i[-3:]=="abz" or i[-3:]=="ABZ":
tf.append(i)
else:
if i[-3:]=="zip" or i[-3:]=="cbz" or i[-3:]=="ZIP" or i[-3:]=="CBZ":
tf.append(i)
tf.sort()
index=appuifw.selection_list(tf)
if index>-2:
try:
z = zipfile.ZipFile(drive_letter+"\\comics\\"+tf[index])
except zipfile.BadZipfile:
data = appuifw.query(u"Not a valid CBZ file:", "query")
else:
filenm=tf[index];
if os.path.isfile(drive_letter+"\\comics\\"+tf[index]+".bmk"):
f = open(drive_letter+"\\comics\\"+tf[index]+".bmk", "r")
s=f.read()
f.close()
page=int(s)
tnames=z.namelist() #dummyf
nmlist=[]
for i in tnames:
if i[-4:]==".jpg" or i[-4:]==".JPG" or i[-5:]==".jpeg" or i[-5:]==".JPEG" or i[-4:]==".gif" or i[-4:]==".GIF" or i[-4:]==".png" or i[-4:]==".PNG":
nmlist.append(i)
nmlist.sort()
nmcount=len(nmlist)
cbrisloaded=1
if startzoom>0:
toggle_screen()
def loadNextCBR():
global cbrisloaded
if cbrisloaded>0:
loadAnotherCBR(2)
def loadPrevCBR():
global cbrisloaded
if cbrisloaded>0:
loadAnotherCBR(0)
def loadAnotherCBR(dr): # 0 = back, 2 = forward
global cbrisloaded
global nmlist
global nmcount
global z, ypos, page, screen_re, old_page
global filenm
global locked
y=-1
#cbrisloaded=0
tf=[]
old_page=-1
files=map(unicode,os.listdir(drive_letter+"\\comics"))
for i in files:
if locked>0:
if i[-3:]=="zip" or i[-3:]=="cbz" or i[-3:]=="ZIP" or i[-3:]=="CBZ" or i[-3:]=="abz" or i[-3:]=="ABZ":
tf.append(i)
else:
if i[-3:]=="zip" or i[-3:]=="cbz" or i[-3:]=="ZIP" or i[-3:]=="CBZ":
tf.append(i)
tf.sort()
index=-1
for i in tf:
if i==filenm:
index=y+dr
else:
y+=1
if index>-1 and index0:
global page
global screen_re, nmcount
data = appuifw.query(u"Enter Page Number:", "number")
if data<1: data=1
if data>nmcount: data=nmcount
page=data-1
write_bmark()
screen_re=1
def index_page():
if cbrisloaded>0:
global nmlist
global page
global screen_re, nmcount
tmp=[]
for i in nmlist:
tmp.append(unicode(i))
data = appuifw.selection_list(tmp)
#if data<1: data=1
if data>nmcount: data=nmcount
page=data
write_bmark()
screen_re=1
def find_page():
if cbrisloaded>0:
global page
global screen_re, nmcount
global nmlist
data = appuifw.query(u"Search:", "text")
data=data.lower()
z=newpage=0
for x in nmlist:
xx=x.lower()
y=xx.find(data)
if y>-1:
newpage=z+1
break
z+=1
if newpage==0 :
appuifw.note(u"Text Not Found", "info")
else:
page=newpage-1
write_bmark()
screen_re=1
def unlock():
global locked, passwd
if locked==1:
locked=0
appuifw.note(u"Files Locked", "info")
else:
pss=appuifw.query(u"Password", "code")
if pss==passwd:
locked=1
appuifw.note(u"Files Unlocked", "info")
else:
appuifw.note(u"Incorrect Password", "info")
def change_passwd():
global passwd, locked
if locked==0:
appuifw.note(u"You Must first unlock this software to change the password", "info")
else:
pss=appuifw.query(u"New Password", "code")
pss2=appuifw.query(u"Confirm New Password", "code")
if pss==pss2:
passwd=pss
appuifw.note(u"Password Changed", "info")
write_settings()
else:
appuifw.note(u"Password did not match, Password remains unchanged", "info")
def first_page():
if cbrisloaded>0:
global page
page=0
write_bmark()
def last_page():
if cbrisloaded>0:
global page, nmcount
page=nmcount-1
write_bmark()
def next_page():
if cbrisloaded>0:
global page, nmcount, xpos,ypos
if page<(nmcount-1):
page+=1
ypos=0
xpos=0
mouse_timer=0
write_bmark()
else:
loadNextCBR()
def prev_page():
if cbrisloaded>0:
global page, nmcount, xpos,ypos
if page>0:
page-=1
ypos=0
xpos=0
mouse_timer=0
write_bmark()
else:
loadPrevCBR()
def mouse_down(pos=(0, 0)):
global mouse, c
global mouse_clk, mouse_d, mouse_timer, mouse_button
mouse = pos
if mouse_timer>0:
zz=int(abs(mouse_clk[0]-mouse[0])+abs(mouse_clk[1]-mouse[1]))/2
if(zz<32):
mouse_timer=0
mouse_button=3
#toggle_screen()
else:
mouse_timer=10000
else:
mouse_timer=10000
mouse_d=pos
mouse_clk=pos
def mouse_up(pos=(0, 0)):
global mouse
global mouse_clk, mouse_button, mouse_timer
mouse=pos
zz=int(abs(mouse_clk[0]-mouse[0])+abs(mouse_clk[1]-mouse[1]))/2
if(zz>32):
mouse_timer=0
mouse_button=1
mouse_clk= pos
def mouse_move(pos=(0, 0)):
global mouse
global mouse_button, mouse_timer
mouse=pos
mouse_button=2
appuifw.app.title = u"TouchComic V1.5"
appuifw.app.screen = 'normal'
appuifw.app.menu = [(u"Open", loadCBR),(u"Choose Drive", select_drive),(u"Full Screen", toggle_screen),
(u"Navigate", ((u"First Page", first_page),(u"Last Page", last_page),
(u"Goto Page", goto_page),(u"Find Page", find_page),
(u"Index Page", index_page),(u"Previous Comic", loadPrevCBR),(u"Next Comic", loadNextCBR),(u"Info", CBR_Info))),
(u"Settings", options),
(u"Unlock", ((u"Toggle Lock", unlock),(u"Change Password", change_passwd))),
(u"About", about),
(u"Exit", quit)]
appuifw.app.exit_key_handler = quit
appuifw.app.directional_pad = False
drive_letter="e:"
running=1
passwd=""
locked=0
old_page=-1
mouse=(0,0)
mouse_d=(0,0)
mouse_clk=(0,0)
filenm=""
# zoom 0=no zoom, 1=Fit to Width
screen_state = saved = screen_re = page = mouse_button = mouse_timer = zoom = startzoom = shownums = cbrisloaded = zoom = zz = maxx = maxy = ypos = xpos = 0
forma=None
def handle_redraw(rect):
global screen_re
screen_re=1
def handle_resize(dummy=(0, 0, 0, 0)):
global old_page
global ypos, xpos
ypos = xpos =0
old_page=-1
global screen_re
screen_re=1
c = appuifw.Canvas(resize_callback = handle_resize,redraw_callback = handle_redraw)
appuifw.app.body = c
c.bind(key_codes.EButton1Down, mouse_down, ((0,0), (640,640)))
c.bind(key_codes.EButton1Up, mouse_up, ((0,0), (640,640)))
c.bind(key_codes.EDrag, mouse_move, ((0,0), (640,640)))
c.bind(key_codes.EKeyRightArrow, next_page)
c.bind(key_codes.EKeyLeftArrow, prev_page)
c.bind(key_codes.EKeySelect, toggle_screen)
read_settings()
while running:
if cbrisloaded>0:
if mouse_button==3:
mouse_button=0
if mouse_d[0]<(c.size[0]/4):
if page>0:
page-=1
ypos=0
xpos=0
mouse_timer=0
write_bmark()
else:
loadPrevCBR()
elif mouse_d[0]>((c.size[0]/4)*3):
if page<(nmcount-1):
page+=1
ypos=0
xpos=0
mouse_timer=0
write_bmark()
else:
loadNextCBR()
else:
toggle_screen()
if mouse_button==2:
maxy=img.size[1]-c.size[1]
maxx=img.size[0]-c.size[0]
xpos+=int(mouse_d[0]-mouse[0])
ypos+=int(mouse_d[1]-mouse[1])
screen_re=1
mouse_button=0
mouse_d=mouse
if mouse_button==1:
if (xpos-maxx)>(c.size[0]/2) :
if page<(nmcount-1):
page+=1
ypos=0
xpos=0
mouse_timer=0
write_bmark()
else:
loadNextCBR()
if (xpos+(c.size[0]/2))<0 :
if page>0:
page-=1
ypos=0
xpos=0
mouse_timer=0
write_bmark()
else:
loadPrevCBR()
if(xpos>maxx): xpos=maxx
if(xpos<0): xpos=0
if(ypos>maxy): ypos=maxy
if(ypos<0): ypos=0
screen_re=1
mouse_button=0
mouse_d=mouse
if page!=old_page:
c.rectangle((0, 0, c.size[0], c.size[1]), fill=0xffffff)
c.text(((c.size[0]/2)-50,80),unicode("Loading..."),fill=0x888888)
b = open("D:\\CBR_TEMP.jpg", 'wb')
b.write(z.read(nmlist[page]))
b.close()
try:
img = graphics.Image.open("D:\\CBR_TEMP.jpg")
except:
img = graphics.Image.new(size=(360, 360))
if c.size[0]!=img.size[0] and zoom==1:
y=img.size[1]*(float(c.size[0])/img.size[0])
img=img.resize((c.size[0],int(y)))
os.remove("D:\\CBR_TEMP.jpg")
old_page=page
screen_re=1
if screen_re>0:
tx=xpos
ty=ypos
if(tx>maxx): tx=maxx
if(tx<0): tx=0
if(ty>maxy): ty=maxy
if(ty<0): ty=0
c.blit(img,(tx,ty))
if shownums>0:
c.text((1,15),unicode("%d/%d" % (page+1,nmcount)),fill=0x000000)
c.text((3,17),unicode("%d/%d" % (page+1,nmcount)),fill=0x000000)
c.text((1,17),unicode("%d/%d" % (page+1,nmcount)),fill=0x000000)
c.text((3,15),unicode("%d/%d" % (page+1,nmcount)),fill=0x000000)
c.text((2,16),unicode("%d/%d" % (page+1,nmcount)),fill=0xffffff)
#c.blit(menu_img,target=(c.size[0]-272,c.size[1]-64))
screen_re=0
else:
c.rectangle((0, 0, c.size[0], c.size[1]), fill=0x000000)
c.text((2,16),unicode("Choose Options:Open to begin"),fill=0xffffff)
e32.ao_sleep(1)
if mouse_timer>0: mouse_timer-=1
e32.ao_yield()