Blender V2.61 - r43446
|
00001 #!/usr/bin/python 00002 00003 # Created by Robert Wenzlaff (Det. Thorn). 00004 # Oct. 30, 2003 00005 00006 from Tkinter import * 00007 color=["black", "white", "darkgreen", "gray"] 00008 00009 class App: 00010 00011 def __init__(self, master): 00012 frame = Frame(master, borderwidth=5) 00013 frame.grid(column=0, row=0, pady=5) 00014 00015 self.state=[] 00016 self.states=256 00017 self.laststate=2 # 0=Black, 1=White, 2=Transp. 00018 00019 self.size=16 00020 self.gridsz=20 00021 00022 for x in range(1024): 00023 self.state.append(2); 00024 00025 self.screen=Canvas( frame, height=320, width=320, bg=color[2] ) 00026 self.screen.bind("<Button-1>", self.scrnclick1) 00027 self.screen.bind("<Button-3>", self.scrnclick2) 00028 self.screen.bind("<B1-Motion>", self.scrndrag) 00029 00030 for x in range(16): 00031 self.screen.create_line((x*20, 0, x*20, 320), fill=color[3]); 00032 self.screen.create_line((0, x*20, 320, x*20), fill=color[3]); 00033 00034 self.screen.grid(row=0, column=0, columnspan=5) 00035 00036 frame2=Frame(master, borderwidth=5) 00037 frame2.grid(column=0, row=1, pady=5) 00038 00039 self.clear=Button(frame2,text="Clear",command=self.clearit) 00040 self.clear.grid(row=0, column=0, pady=20) 00041 00042 self.doit=Button(frame2, text="Print", command=self.doit) 00043 self.doit.grid(row=0, column=1, pady=20) 00044 00045 #self.doitlab=Label(frame2, text="(Output to stdout)"); 00046 #self.doitlab.grid(row=1, column=1); 00047 00048 self.parse=Button(frame2, text="Parse", command=self.parsetext); 00049 self.parse.grid(row=0, column=2, pady=20) 00050 00051 self.large=0 00052 self.dummy=IntVar() 00053 self.largeb=Checkbutton(frame2, text="Large", var=self.dummy, command=self.changesize) 00054 self.largeb.grid(row=0, column=3, pady=20) 00055 00056 self.prev=Canvas(frame2, height=17, width=17, bg=color[2], relief=RIDGE) 00057 self.prev.grid(row=0, column=4, pady=20, padx=20) 00058 00059 # DataParsers 00060 self.bmlabel=Label(frame2, text="Bitmap Data (paste hex from code)") 00061 self.bmlabel.grid(row=2, column=0, columnspan=5, sticky="W") 00062 00063 self.bmentry=Text(frame2, width=80, height=9, font="Times 8"); 00064 self.bmentry.bind("<Leave>", self.bmtextpaste); 00065 self.bmentry.grid(row=3, column=0, columnspan=5, pady=5); 00066 00067 self.msklabel=Label(frame2, text="Mask Data (paste hex from code)") 00068 self.msklabel.grid(row=4, column=0, columnspan=5, sticky="W") 00069 00070 self.mskentry=Text(frame2, width=80, height=9, font="Times 8"); 00071 self.mskentry.bind("<Leave>", self.msktextpaste); 00072 self.mskentry.grid(row=5, column=0, columnspan=5, pady=5); 00073 00074 def changesize(self): 00075 self.large=~self.large 00076 if self.large: 00077 self.size=32 00078 self.gridsz=10 00079 self.states=1024 00080 oldstate=self.state 00081 self.state=[] 00082 for n in range(1024): 00083 col=(n/2)%16 00084 row=int(n/64) 00085 self.state.append(oldstate[16*row+col]) 00086 oldstate=[] 00087 else: 00088 self.size=16 00089 self.gridsz=20 00090 self.states=256 00091 oldstate=self.state 00092 self.state=[] 00093 for n in range(1024): 00094 if not((n%2) or ((n/32)%2)): 00095 self.state.append(oldstate[n]) 00096 for n in range(256,1024): 00097 self.state.append(2) 00098 oldstate=[] 00099 00100 #Insert scaling here 00101 00102 self.updatescrn() 00103 self.prev.config(width=self.size+1, height=self.size+1) 00104 for n in range(self.states): 00105 self.updateprev(n) 00106 #self.prev.grid(row=0, column=4, padx=self.gridsz, pady=self.gridsz) 00107 00108 def scrnclick1(self, event): 00109 self.scrnclick(event, 1) 00110 00111 def scrnclick2(self, event): 00112 self.scrnclick(event, -1) 00113 00114 def scrnclick(self, event, direction): 00115 if (event.x>319) or (event.y>319) or (event.x<0) or (event.y<0): return 00116 00117 n=(event.x/self.gridsz) + self.size*(event.y/self.gridsz) 00118 00119 self.state[n]+=direction 00120 self.state[n]%=3 00121 00122 row=n%self.size 00123 col=n/self.size 00124 00125 self.screen.create_rectangle( (self.gridsz*row+1, self.gridsz*col+1,\ 00126 self.gridsz*row+self.gridsz-1, self.gridsz*col+self.gridsz-1), \ 00127 fill=color[self.state[n]], outline="" ) 00128 00129 self.laststate=self.state[n] 00130 self.updateprev(n) 00131 00132 def scrndrag(self,event): 00133 if (event.x>319) or (event.y>319) or (event.x<0) or (event.y<0): return 00134 00135 n=(event.x/self.gridsz) + self.size*(event.y/self.gridsz) 00136 00137 row=n%self.size 00138 col=n/self.size 00139 00140 self.screen.create_rectangle( (self.gridsz*row+1, self.gridsz*col+1, \ 00141 self.gridsz*row+self.gridsz-1, self.gridsz*col+self.gridsz-1), \ 00142 fill=color[self.laststate], outline="" ) 00143 self.state[n]=self.laststate 00144 00145 self.updateprev(n) 00146 00147 def updateprev(self, n): 00148 x=n%self.size+1 00149 y=n/self.size+1 00150 00151 if self.large: pad=12 00152 else: pad=20 00153 00154 self.prev.create_line(x+1,y+1,x+2,y+1,fill=color[self.state[n]]) 00155 self.prev.grid(row=0, column=4, padx=pad, pady=pad) 00156 00157 def updatescrn(self): 00158 self.screen.create_rectangle( 0,0,320,320, fill=color[2] ) 00159 for x in range(self.size): 00160 self.screen.create_line((x*self.gridsz, 0, x*self.gridsz, 320), fill=color[3]); 00161 self.screen.create_line((0, x*self.gridsz, 320, x*self.gridsz), fill=color[3]); 00162 for n in range(self.states): 00163 row=n%self.size 00164 col=n/self.size 00165 self.screen.create_rectangle( (self.gridsz*row+1, self.gridsz*col+1, \ 00166 self.gridsz*row+self.gridsz-1, self.gridsz*col+self.gridsz-1), \ 00167 fill=color[self.state[n]], outline="" ) 00168 00169 def bmtextpaste(self, event): 00170 string=self.bmentry.get(1.0, END) 00171 self.bmentry.delete(1.0, END) 00172 string=string.replace("\t", "") 00173 self.bmentry.insert(END, string) 00174 00175 def msktextpaste(self, event): 00176 string=self.mskentry.get(1.0, END) 00177 self.mskentry.delete(1.0, END) 00178 string=string.replace("\t", "") 00179 self.mskentry.insert(END, string) 00180 00181 def parsetext(self): 00182 from string import atoi 00183 00184 bmstring=self.bmentry.get(1.0, END) 00185 bmstring=bmstring.replace(",", " ") 00186 bmstring=bmstring.split() 00187 00188 mskstring=self.mskentry.get(1.0, END) 00189 mskstring=mskstring.replace(",", " ") 00190 mskstring=mskstring.split() 00191 00192 if (len(bmstring)!=len(mskstring)): 00193 print "Mismatched data. Bitmap and mask must be same size," 00194 return 00195 elif not (len(bmstring)==32 or len(bmstring)==128): 00196 print "Size Error, input must be 32 or 128 hex bytes. " 00197 return 00198 00199 00200 for n in range(self.states): 00201 self.state[n]=0; 00202 00203 m=0 00204 for entry in bmstring: 00205 e=atoi(entry, 16); 00206 for bit in range(8): 00207 self.state[m]=(e&1) 00208 e=e>>1; 00209 m+=1 00210 00211 m=0 00212 for entry in mskstring: 00213 e=atoi(entry, 16); 00214 for bit in range(8): 00215 if not (e&1): 00216 self.state[m]=2; 00217 e=e>>1 00218 m+=1 00219 00220 self.updatescrn() 00221 for n in range(self.states): self.updateprev(n) 00222 00223 def clearit(self): 00224 for n in range(self.states): 00225 self.state[n]=2; 00226 self.updateprev(n) 00227 self.updatescrn() 00228 self.bmentry.delete(0.0, END); 00229 self.mskentry.delete(0.0, END); 00230 00231 def doit(self): 00232 mask=[] 00233 bitmap=[] 00234 numbytes=self.size*self.size/8 00235 for i in range(numbytes): 00236 m=0 00237 b=0 00238 for j in range(8): 00239 m<<=1 00240 b<<=1 00241 if (self.state[(i*8)+(7-j)]!=2): 00242 m|=1 00243 if (self.state[(i*8)+(7-j)]==1): 00244 b|=1 00245 #print (i*8)+(7-j), self.state[(i*8)+(7-j)], m 00246 mask.append(m) 00247 bitmap.append(b) 00248 00249 print "\n\nstatic char bitmap[]={" %vars(), 00250 for i in range(numbytes): 00251 b1=bitmap[i] 00252 if not(i%8): print "\n\t", 00253 print "0x%(b1)02x, "%vars(), 00254 print "\n};" 00255 00256 print "\nstatic char mask[]={" %vars(), 00257 for i in range(numbytes): 00258 b1=mask[i] 00259 if not(i%8): print "\n\t", 00260 print "0x%(b1)02x, "%vars(), 00261 print "\n};" 00262 00263 ################## Main App ####################### 00264 root = Tk() 00265 00266 app = App(root) 00267 root.title("Cursor Maker") 00268 00269 root.mainloop()