Charles.Forsyth20060303a828770d19 years agoHistory
2508 lines · 66.4 KB · Brainfuck
RawDownload
# Sort out timing with taking photo & getting jpg/thumbnail - make sure it gets the right one when 2photos have been taken & sort out 'cannot communicate with camera' error implement tkinterface; include "tk.m";	tk: Tk;include "tkclient.m";	tkclient: Tkclient;include "sys.m";	sys : Sys;include "daytime.m";	daytime: Daytime;include "readdir.m";	readdir: Readdir;include "bufio.m";	bufio: Bufio;	Iobuf: import bufio;include "selectfile.m";	selectfile: Selectfile; include "string.m";	str : String;include "draw.m";	draw: Draw;	Context, Display, Point, Rect, Image, Screen, Font: import draw;include "grid/readjpg.m";	readjpg: Readjpg; display : ref draw->Display;context : ref draw->Context;camerapath := "";savepath := "";tmppath := "/tmp/";usecache := 1;working := 0;processing := 0;coords: draw->Rect;DONE : con 1;KILLED : con 2;font: ref Draw->Font;tkfont := "";tkfontb := "";tkfontf := "";ssize := 3;maxsize : Point;nilrect := Draw->Rect((0,0),(0,0));runwithoutcam := 0;toplevels : list of (ref Tk->Toplevel, string, list of int, int) = nil;procimg : ref Draw->Image;loadimg: ref Draw->Image; tkinterface : module {	init : fn (ctxt : ref Draw->Context, argv : list of string);}; init(ctxt : ref Draw->Context, argv : list of string){	display = ctxt.display;	context = ctxt; 	sys = load Sys Sys->PATH;#	sys->pctl(Sys->NEWPGRP, nil);#	sys->pctl(Sys->FORKNS, nil); 	str = load String String->PATH;	readdir = load Readdir Readdir->PATH;	daytime = load Daytime Daytime->PATH;	bufio = load Bufio Bufio->PATH;		str = load String String->PATH;	draw = load Draw Draw->PATH; 	tk = load Tk Tk->PATH;	tkclient = load Tkclient Tkclient->PATH;	tkclient->init();	selectfile = load Selectfile Selectfile->PATH;	selectfile->init();	readjpg = load Readjpg Readjpg->PATH;	readjpg->init(display);	font = draw->Font.open(display, "/fonts/charon/plain.small.font");	runfrom := hd argv;	p := isat2(runfrom,"/");	savepath = runfrom[:p+1];	argv = tl argv;	while (argv != nil) {		if (camerapath == "" && (hd argv)[0] == '/') camerapath = hd argv;		if (hd argv == "nocache") usecache = 0;		argv = tl argv;	}	if (camerapath == "")		camerapath = "./";	if (camerapath != "" && camerapath[len camerapath - 1] != '/')		camerapath[len camerapath] = '/'; 	r := display.image.r;#	if (r.dx() < 800 || r.dy() < 600) ssize = 2;	if (r.dx() < 400 || r.dy() < 300) ssize = 1;	maxsize = (r.dx(), r.dy()); 	if (ssize == 1) {		tkfont = "/fonts/charon/plain.tiny.font";		tkfontb = "/fonts/charon/bold.tiny.font";		tkfontf = "/fonts/pelm/unicode.8.font";	}	else if (ssize == 2) {		tkfont = "/fonts/charon/plain.small.font";		tkfontb = "/fonts/charon/bold.small.font";		tkfontf = "/fonts/pelm/unicode.8.font";	}	else {		tkfont = "/fonts/charon/plain.normal.font";		tkfontb = "/fonts/charon/bold.normal.font";		tkfontf = "/fonts/pelm/unicode.8.font";	}	if ((sys->stat(tkfont)).t0 == -1)		tkfont = "";	else tkfont = " -font " + tkfont;	if ((sys->stat(tkfontb)).t0 == -1)		tkfontb = "";	else tkfontb = " -font " + tkfontb;	if ((sys->stat(tkfontf)).t0 == -1)		tkfontf = "";	else tkfontf = " -font " + tkfontf; 	procimg = display.open("camproc.bit");	loadimg = display.open("camload.bit"); 	spawn tkstuff();} # Tk stuff thumbscr := array[] of {	"frame .f",	"frame .fthumb -bg white",	"frame .f.finfo",	"frame .f.fsnap",	"menubutton .f.fsnap.fsettings.mb2 -text {Selected\n(0 files)} -menu .m2 @",	"menu .m2 @",	".m2 add command -text {Select All} -command {send butchan selectall 1}",	".m2 add command -text {Select None} -command {send butchan selectall 0}",	".m2 add command -text {Invert Selection} -command {send butchan invert}",	".m2 add command -text {Refresh Files} -command {send butchan refresh}",	"menu .m @", 	"frame .f.fsnap.fsettings -borderwidth 1 -relief raised",	"menubutton .f.fsnap.fsettings.mb -text {Settings} -menu .m &",	"button .f.fsnap.fsettings.b -text {Information} -command {send butchan info} &",	"grid .f.fsnap.fsettings.b -row 0 -column 0 -sticky ew",	"grid .f.fsnap.fsettings.mb -row 1 -column 0 -sticky ew",	"grid .f.fsnap.fsettings.mb2 -row 2 -column 0 -sticky ew", 	"frame .f.fsnap.fstore -borderwidth 1 -relief raised",	"label .f.fsnap.fstore.l1 -text {  Photos taken: } @",	"label .f.fsnap.fstore.l2 -text {  Remaining: } @",	"label .f.fsnap.fstore.l3 -text {  } @",	"label .f.fsnap.fstore.l4 -text {  } @",	"grid .f.fsnap.fstore.l1 -row 0 -column 0 -sticky w",	"grid .f.fsnap.fstore.l2 -row 1 -column 0 -sticky w",	"grid .f.fsnap.fstore.l3 -row 0 -column 1 -sticky w",	"grid .f.fsnap.fstore.l4 -row 1 -column 1 -sticky w", 	"frame .f.fsnap.ftime -borderwidth 1 -relief raised",	"label .f.fsnap.ftime.l1 -text {Local: } @",	"label .f.fsnap.ftime.l2 -text {Camera: } @",	"label .f.fsnap.ftime.l3",	"label .f.fsnap.ftime.l4",	"checkbutton .f.fsnap.ftime.cb -text {Set camera to local time} -variable time &",	"button .f.fsnap.ftime.b -text {refresh} -command {send butchan gettime} &",	"grid .f.fsnap.ftime.l1 -row 0 -column 0 -sticky w",	"grid .f.fsnap.ftime.l2 -row 1 -column 0 -sticky w",	"grid .f.fsnap.ftime.l3 -row 0 -column 1 -sticky w",	"grid .f.fsnap.ftime.l4 -row 1 -column 1 -sticky w",	"grid .f.fsnap.ftime.cb -row 2 -column 0 -columnspan 2",	"grid .f.fsnap.ftime.b -row 3 -column 0 -columnspan 2", 	"button .f.fsnap.b -text {Take Photo} -command {send butchan snap} &",	"grid columnconfigure .f.fsnap 2 -minsize 150",	"frame .f.fcom",	"frame .f.f1 -background #0d0d0d1a",	"canvas .f.f1.c1 -yscrollcommand {.f.f1.sb1 set} -height 255 -width 542 -bg white",	".f.f1.c1 create window 0 0 -window .fthumb -anchor nw",	"scrollbar .f.f1.sb1 -command {.f.f1.c1 yview}", #	"frame .f.f2",#	"canvas .f.f2.c1 -width 556 -height 304",#	".f.f2.c1 create window 0 0 -window .f.fsnap -anchor nw", 	"grid .f.fsnap -column 0 -row 0",	"grid .f.f1 -column 0 -row 1",	"grid .f.f1.c1 -column 0 -row 0",	"grid .f.f1.sb1 -column 1 -row 0 -sticky ns",#	"grid .f.f2 -column 0 -row 0",#	"grid .f.f2.c1 -column 0 -row 0 -sticky ew",	"bind .Wm_t <ButtonPress-1> +{focus .}",	"bind .Wm_t.title <ButtonPress-1> +{focus .}",}; lastpath := ""; Aitem: adt {	pname,desc: string;	dtype,factory: int;	read, location: string;	data: list of (string, int);};LIST: con 0;MINMAX: con 1;OTHER: con 2; noabilities := 0;	abilities : array of Aitem; getdesc(l : list of string): list of string{	s := "";	while(hd l != "min" && hd l != "items" && tl l != nil) {		s += hd l + " ";		l = tl l;	}	while (s[len s - 1] == ' ' || s[len s - 1] == '\n')		s = s[:len s -1];	l = s :: l;	return l;} inflist : list of (string, string);ablmenu : array of string; getabilities(){	inflist = nil;	abilities = array[200] of Aitem;		fd := bufio->open(camerapath+"abilities", bufio->OREAD);	if (runwithoutcam)		fd = bufio->open("/usr/danny/camera/abls", bufio->OREAD);	i := 0;	for (;;) {		take := 0;		s := fd.gets('\n');		if (s == "") break;		(n, lst) := sys->tokenize(s," ,:\t\n");		abilities[i].data = nil;		abilities[i].read = "";		if (lst != nil && len hd lst == 4) {			abilities[i].pname = hd lst;			lst = getdesc(tl lst);			abilities[i].desc = hd lst;			if (hd tl lst == "items") {				abilities[i].dtype = LIST;				abilities[i].factory = int hd tl tl tl tl lst;				noitems := int hd tl tl lst;				for (k := 0; k < noitems; k++) {					s = fd.gets('\n');					(n2, lst2) := sys->tokenize(s,",:\t\n");					name := hd lst2;					val := int hd tl lst2;					if (k == 0) {						if (abilities[i].pname == "ssiz")							abilities[i].factory = val;						else if (abilities[i].pname == "scpn")							abilities[i].factory = val;					}						if (val == abilities[i].factory && noitems > 1) name += " *";					abilities[i].data = (name, val) :: abilities[i].data;				}				if (noitems < 2) {					inflist = (abilities[i].desc, (hd abilities[i].data).t0) :: inflist;					take = 1;				}			}			else if (hd tl lst == "min") {				abilities[i].dtype = MINMAX;				abilities[i].factory = int hd tl tl tl tl tl tl lst;				min := int hd tl tl lst;				max := int hd tl tl tl tl lst;				mul := 1;				while (max > 200000) {					min /= 10;					max /= 10;					mul *= 10;				}				abilities[i].data = ("min", min) :: abilities[i].data;				abilities[i].data = ("max", max) :: abilities[i].data;				abilities[i].data = ("mul", mul) :: abilities[i].data;			}			else {				inflist = (abilities[i].desc,list2string(tl lst)) :: inflist;				take = 1;			}			if (take || 				abilities[i].desc == "Time Format" ||				abilities[i].desc == "Date Format" ||				abilities[i].desc == "File Type" ||				contains(abilities[i].desc,"Video") ||				contains(abilities[i].desc,"Media") ||				contains(abilities[i].desc,"Sound") ||				contains(abilities[i].desc,"Volume") ||				contains(abilities[i].desc,"Slide") ||				contains(abilities[i].desc,"Timelapse") ||				contains(abilities[i].desc,"Burst") ||				contains(abilities[i].desc,"Power") ||				contains(abilities[i].desc,"Sleep"))					i--;			i++;		}		}	noabilities = i;} isat(s: string, test: string): int{	num := -1;	if (len test > len s) return -1;	for (i := 0; i < (1 + (len s) - (len test)); i++) {		if (num == -1 && test == s[i:i+len test]) num = i;	}	return num;} isat2(s: string, test: string): int{	num := -1;	if (len test > len s) return -1;	for (i := len s - len test; i >= 0; i--) {		if (num == -1 && test == s[i:i+len test]) num = i;	}	return num;}  nomatches(s: string): int{	n := 0;	for (i := 0; i < noabilities; i++) {		test := abilities[i].desc;		if (len s <= len test && test[:len s] == s) n++;	}	return n;} matches(s1,s2: string): int{	if (len s1 < len s2) return 0;	if (s1[:len s2] == s2) return 1;	return 0;} biggestmatch(nm: int, s: string, l: int): string{	bigmatch := s;	match := s[:l];	for (;;) {		if (bigmatch == match) break;		if (nomatches(bigmatch) == nm) return bigmatch;		p := isat2(bigmatch," ");		if (p < len match) break;		bigmatch = bigmatch[:p];	}	return match;} getabllist(): array of string{	los : list of string;	los = nil;	for (i := 0; i < noabilities; i++) {		p := 0;		p2 := 0;		nm : int;		for (;;) {			nm = -1;			tmpl := los;			while (tmpl != nil) {				if (matches(abilities[i].desc, hd tmpl)) nm = 0;				tmpl = tl tmpl;			}			if (nm == 0) break;			p += p2;			tmp := abilities[i].desc[p:];			p2 = isat(tmp, " ");			if (p2 == -1) p2 = len tmp;			else p2++;			nm = nomatches(abilities[i].desc[:p+p2]);			if (nm <= 5) break;		}		if (nm > 0) {			listitem := biggestmatch(nm, abilities[i].desc,p+p2);			los = listitem :: los;		}	}	ar := array[len los] of string;	for (i = len ar - 1; i >= 0; i--) {		ar[i] = hd los;		los = tl los;	}	return ar;} buildabilitiesframes(top: ref Tk->Toplevel){	ablmenu = getabllist();	tkcmd(top, ".m add command -text {Refresh Main Screen} -command {send butchan refreshstate}");	tkcmd(top, ".m add command -text {Reset Camera} -command {send butchan reset}");	for (k := 0; k < len ablmenu; k++) {		if (len ablmenu[k] > 4 && (ablmenu[k][:4] == "Zoom" || ablmenu[k][:5] == "Still"))  			buildabilitiesframe(top,k,"butchan");		else			tkcmd(top, ".m add command -text {"+ablmenu[k]+				"} -command {send butchan abls "+string k+"}");	}	tkcmd(top, "menu .mthumb "+tkfont);	tkcmd(top, ".mthumb add command -label {Selection (88 files)}");	tkcmd(top, ".mthumb add separator");	for (k = nothumbs; k < len menu; k++)		 tkcmd(top, ".mthumb add command -text {"+menu[k].text+"} " +				"-command {send butchan}"); } buildabilitiesframe(top: ref Tk->Toplevel,k: int, chanout: string){	nm := string nomatches(ablmenu[k]);	count2 := 0;	for (i := 0; i < noabilities; i++) {		if (matches(abilities[i].desc,ablmenu[k])) { 			frame : string;			case abilities[i].pname {				"scpn" or "ssiz" or "zpos" =>					frame = ".f.fsnap.f"+abilities[i].pname;					tkcmd(top, "frame "+frame+" -borderwidth 1 -relief raised");				* =>					frame = ".f";					if (count2 == 0)  { 						tkcmd(top, "frame "+frame);						tkcmd(top, "label "+frame+".l -text {"+ablmenu[k]+"}"+tkfontb);						tkcmd(top, "grid "+frame+".l -row 0 -column 0 -columnspan "+nm);					}					frame = frame + ".f"+string count2;					tkcmd(top, "frame "+frame+" -borderwidth 1 -relief raised");					tkcmd(top, "grid "+frame+" -row 1 -column "+string count2+ " -sticky nsew");					mul := getval(abilities[i].data,"mul");					s := abilities[i].desc[len ablmenu[k]:];					if (mul != 1 && abilities[i].dtype == MINMAX)						s += " (x"+string mul+")";					tkcmd(top, "label "+frame+".l -text {"+s+"}"+tkfont);					tkcmd(top, "grid "+frame+".l -row 0 -column 0 -sticky nw");			}							if (abilities[i].dtype == MINMAX) {				abilities[i].location = frame+".sc";				min := getval(abilities[i].data,"min");				max := getval(abilities[i].data,"max");				tkcmd(top, sys->sprint("scale %s.sc -to %d -from %d %s", frame,min,max,tkfont));				tkcmd(top, "bind "+frame+".sc <ButtonPress-3> {send " +					chanout + " scaleval " + string i + " %X %Y}");				tkcmd(top, "grid "+frame+".sc -row 1 -column 0");					}			else if (abilities[i].dtype == LIST) {				tkcmd(top, "frame "+frame+".frb");				tkcmd(top, "grid "+frame+".frb -row 1 -column 0");				tmp := abilities[i].data;				row := 0;				while (tmp != nil) {					(name, val) := hd tmp;					s := sys->sprint("radiobutton %s.frb.rb%d -text {%s} -value %d -variable %s  -height %d %s",frame,row,name,val,abilities[i].pname,24 - (3*(3-ssize)), tkfont);					tkcmd(top,s);					tkcmd(top, sys->sprint("grid %s.frb.rb%d -row %d -column 0 -sticky w",						frame,row,row));					tmp = tl tmp;					row++;				}			}			tkcmd(top, "button "+frame+".bs -text {Set} -command "+				"{send "+chanout+" set "+string i+"}"+butheight+tkfont);			tkcmd(top, "grid "+frame+".bs -row 2 -column 0 -sticky ew");			if (abilities[i].dtype == MINMAX) {				tkcmd(top, "button "+frame+".bf -text {Default} -command "+					"{send "+chanout+" setdef "+string i+"}"+butheight+tkfont);				tkcmd(top, "grid "+frame+".bf -row 3 -column 0 -sticky ew");			}			count2++;		}	}} getvaluescr := array[] of {	"frame .f -height 84 -width 114 -borderwidth 2 -relief raised",	"label .f.l1 -text {Enter Value:} @",	"entry .f.e1 -width 100 -bg white @",	"button .f.b1 -text { ok } -command {send chanin ok} &",	"button .f.b2 -text cancel -command {send chanin cancel} &",	"grid .f.l1 -column 1 -row 0 -columnspan 2 -padx 0 -sticky w",	"grid .f.e1 -column 1 -row 1 -columnspan 2 -padx 0 -pady 5",	"grid .f.b1 -column 1 -row 2 -padx 0",	"grid .f.b2 -column 2 -row 2 -padx 0",	"grid columnconfigure .f 1 -minsize 20",	"grid columnconfigure .f 2 -minsize 20",	"grid columnconfigure .f 3 -minsize 5",

Lines 1–500 of 2508.