3 # Created by Robert Wenzlaff (Det. Thorn).
7 color
=["black", "white", "darkgreen", "gray"]
11 def __init__(self
, master
):
12 frame
= Frame(master
, borderwidth
=5)
13 frame
.grid(column
=0, row
=0, pady
=5)
17 self
.laststate
=2 # 0=Black, 1=White, 2=Transp.
25 self
.screen
=Canvas( frame
, height
=320, width
=320, bg
=color
[2] )
26 self
.screen
.bind("<Button-1>", self
.scrnclick1
)
27 self
.screen
.bind("<Button-3>", self
.scrnclick2
)
28 self
.screen
.bind("<B1-Motion>", self
.scrndrag
)
31 self
.screen
.create_line((x
*20, 0, x
*20, 320), fill
=color
[3]);
32 self
.screen
.create_line((0, x
*20, 320, x
*20), fill
=color
[3]);
34 self
.screen
.grid(row
=0, column
=0, columnspan
=5)
36 frame2
=Frame(master
, borderwidth
=5)
37 frame2
.grid(column
=0, row
=1, pady
=5)
39 self
.clear
=Button(frame2
,text
="Clear",command
=self
.clearit
)
40 self
.clear
.grid(row
=0, column
=0, pady
=20)
42 self
.doit
=Button(frame2
, text
="Do It", command
=self
.doit
)
43 self
.doit
.grid(row
=0, column
=1, pady
=20)
45 #self.doitlab=Label(frame2, text="(Output to stdout)");
46 #self.doitlab.grid(row=1, column=1);
48 self
.parse
=Button(frame2
, text
="Parse it", command
=self
.parsetext
);
49 self
.parse
.grid(row
=0, column
=2, pady
=20)
53 self
.largeb
=Checkbutton(frame2
, text
="Large", var
=self
.dummy
, command
=self
.changesize
)
54 self
.largeb
.grid(row
=0, column
=3, pady
=20)
56 self
.prev
=Canvas(frame2
, height
=17, width
=17, bg
=color
[2], relief
=RIDGE
)
57 self
.prev
.grid(row
=0, column
=4, pady
=20, padx
=20)
60 self
.bmlabel
=Label(frame2
, text
="Bitmap Data (paste hex from code)")
61 self
.bmlabel
.grid(row
=2, column
=0, columnspan
=5, sticky
="W")
63 self
.bmentry
=Text(frame2
, width
=80, height
=9, font
="Times 8");
64 self
.bmentry
.bind("<Leave>", self
.bmtextpaste
);
65 self
.bmentry
.grid(row
=3, column
=0, columnspan
=5, pady
=5);
67 self
.msklabel
=Label(frame2
, text
="Mask Data (paste hex from code)")
68 self
.msklabel
.grid(row
=4, column
=0, columnspan
=5, sticky
="W")
70 self
.mskentry
=Text(frame2
, width
=80, height
=9, font
="Times 8");
71 self
.mskentry
.bind("<Leave>", self
.msktextpaste
);
72 self
.mskentry
.grid(row
=5, column
=0, columnspan
=5, pady
=5);
75 self
.large
=~self
.large
85 self
.state
.append(oldstate
[16*row
+col
])
94 if not((n
%2) or ((n
/32)%2)):
95 self
.state
.append(oldstate
[n
])
96 for n
in range(256,1024):
103 self
.prev
.config(width
=self
.size
+1, height
=self
.size
+1)
104 for n
in range(self
.states
):
106 #self.prev.grid(row=0, column=4, padx=self.gridsz, pady=self.gridsz)
108 def scrnclick1(self
, event
):
109 self
.scrnclick(event
, 1)
111 def scrnclick2(self
, event
):
112 self
.scrnclick(event
, -1)
114 def scrnclick(self
, event
, direction
):
115 if (event
.x
>319) or (event
.y
>319) or (event
.x
<0) or (event
.y
<0): return
117 n
=(event
.x
/self
.gridsz
) + self
.size
*(event
.y
/self
.gridsz
)
119 self
.state
[n
]+=direction
125 self
.screen
.create_rectangle( (self
.gridsz
*row
+1, self
.gridsz
*col
+1,\
126 self
.gridsz
*row
+self
.gridsz
-1, self
.gridsz
*col
+self
.gridsz
-1), \
127 fill
=color
[self
.state
[n
]], outline
="" )
129 self
.laststate
=self
.state
[n
]
132 def scrndrag(self
,event
):
133 if (event
.x
>319) or (event
.y
>319) or (event
.x
<0) or (event
.y
<0): return
135 n
=(event
.x
/self
.gridsz
) + self
.size
*(event
.y
/self
.gridsz
)
140 self
.screen
.create_rectangle( (self
.gridsz
*row
+1, self
.gridsz
*col
+1, \
141 self
.gridsz
*row
+self
.gridsz
-1, self
.gridsz
*col
+self
.gridsz
-1), \
142 fill
=color
[self
.laststate
], outline
="" )
143 self
.state
[n
]=self
.laststate
147 def updateprev(self
, n
):
151 if self
.large
: pad
=12
154 self
.prev
.create_line(x
+1,y
+1,x
+2,y
+1,fill
=color
[self
.state
[n
]])
155 self
.prev
.grid(row
=0, column
=4, padx
=pad
, pady
=pad
)
157 def updatescrn(self
):
158 self
.screen
.create_rectangle( 0,0,320,320, fill
=color
[2] )
159 for x
in range(self
.size
):
160 self
.screen
.create_line((x
*self
.gridsz
, 0, x
*self
.gridsz
, 320), fill
=color
[3]);
161 self
.screen
.create_line((0, x
*self
.gridsz
, 320, x
*self
.gridsz
), fill
=color
[3]);
162 for n
in range(self
.states
):
165 self
.screen
.create_rectangle( (self
.gridsz
*row
+1, self
.gridsz
*col
+1, \
166 self
.gridsz
*row
+self
.gridsz
-1, self
.gridsz
*col
+self
.gridsz
-1), \
167 fill
=color
[self
.state
[n
]], outline
="" )
169 def bmtextpaste(self
, event
):
170 string
=self
.bmentry
.get(1.0, END
)
171 self
.bmentry
.delete(1.0, END
)
172 string
=string
.replace("\t", "")
173 self
.bmentry
.insert(END
, string
)
175 def msktextpaste(self
, event
):
176 string
=self
.mskentry
.get(1.0, END
)
177 self
.mskentry
.delete(1.0, END
)
178 string
=string
.replace("\t", "")
179 self
.mskentry
.insert(END
, string
)
182 from string
import atoi
184 bmstring
=self
.bmentry
.get(1.0, END
)
185 bmstring
=bmstring
.replace(",", " ")
186 bmstring
=bmstring
.split()
188 mskstring
=self
.mskentry
.get(1.0, END
)
189 mskstring
=mskstring
.replace(",", " ")
190 mskstring
=mskstring
.split()
192 if (len(bmstring
)!=len(mskstring
)):
193 print "Mismatched data. Bitmap and mask must be same size,"
195 elif not (len(bmstring
)==32 or len(bmstring
)==128):
196 print "Size Error, input must be 32 or 128 hex bytes. "
200 for n
in range(self
.states
):
204 for entry
in bmstring
:
212 for entry
in mskstring
:
221 for n
in range(self
.states
): self
.updateprev(n
)
224 for n
in range(self
.states
):
228 self
.bmentry
.delete(0.0, END
);
229 self
.mskentry
.delete(0.0, END
);
234 numbytes
=self
.size
*self
.size
/8
235 for i
in range(numbytes
):
241 if (self
.state
[(i
*8)+(7-j
)]!=2):
243 if (self
.state
[(i
*8)+(7-j
)]==1):
245 #print (i*8)+(7-j), self.state[(i*8)+(7-j)], m
249 print "\n\nstatic char bitmap[]={" %vars(),
250 for i
in range(numbytes
):
252 if not(i
%8): print "\n\t",
253 print "0x%(b1)02x, "%vars(),
256 print "\nstatic char mask[]={" %vars(),
257 for i
in range(numbytes
):
259 if not(i
%8): print "\n\t",
260 print "0x%(b1)02x, "%vars(),
263 ################## Main App #######################
267 root
.title("Cursor Maker")