-
Notifications
You must be signed in to change notification settings - Fork 0
/
py.py
64 lines (56 loc) · 2.75 KB
/
py.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#wxpython2.8 python2.6
import wx
import random
from Main import opj
import randomColor as rcolor
#----------------------------------------------------------------------
class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.tempImage = None;
self.log = log
wx.Panel.__init__(self, parent, -1)
b = wx.Button(self, -1, "Change the color", (200,50))
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
saveButton = wx.Button(self, -1, "savebtn", (400,50))
self.Bind(wx.EVT_BUTTON, self.onSaveButton, saveButton)
def onSaveButton( self, evt ):
self.saveFile( self.tempImage )
def OnButton(self, evt):
png = wx.Image(opj('testimage.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap()
pos = 10
wx.StaticBitmap(self, -1, png, (10, pos), (png.GetWidth(), png.GetHeight()))
dstImage = wx.ImageFromBitmap( png )
emptyImage = wx.EmptyImage(png.GetWidth(), png.GetHeight())
defaultRed = 138;
defaultGreen = 102;
defaultBlue = 110;
defaultRed1 = 183;
defaultGreen2 = 171;
defaultBlue3 = 173;
rcr = rcolor.randomColor()
randomRed,randomGreen,randomBlue = rcr.getRandomColor()
randomRed1,randomGreen1,randomBlue1 = rcr.getRandomColor()
indexColor = 0;
for x in xrange(png.GetWidth()):
for y in xrange(png.GetHeight()):
if defaultRed == dstImage.GetRed(x,y) and defaultGreen == dstImage.GetGreen(x,y) and defaultBlue == dstImage.GetBlue(x,y):
emptyImage.SetRGB(x, y, randomRed, randomGreen, randomBlue)
elif defaultRed1 == dstImage.GetRed(x,y) and defaultGreen2 == dstImage.GetGreen(x,y) and defaultBlue3 == dstImage.GetBlue(x,y):
emptyImage.SetRGB(x, y, randomRed1, randomGreen1, randomBlue1)
else:
emptyImage.SetRGB(x, y, dstImage.GetRed(x,y), dstImage.GetGreen(x,y), dstImage.GetBlue(x,y))
indexColor = indexColor + 1
pos = pos + png.GetHeight() + 10
self.tempImage = emptyImage.ConvertToBitmap()
wx.StaticBitmap(self, -1, self.tempImage, (10, pos), (self.tempImage.GetWidth(), self.tempImage.GetHeight()))
def saveFile( self, saveImage ):
if saveImage != None:
saveImage.SaveFile('bitmaps/save.png', wx.BITMAP_TYPE_PNG)
def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win
#----------------------------------------------------------------------
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])