-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
129 lines (100 loc) · 3.79 KB
/
gui.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import wx
import cv2
from DrawPicture import drawPicture
class MDIFrame(wx.MDIParentFrame):
__B = 255
__G = 0
__R = 0
__childNum = 0
def __init__(self):
color = [255,0,0]
wx.MDIParentFrame.__init__(self, None, -1, "MDI Parent - www.yiibai.com", size = (600,400))
#创建菜单
menu = wx.Menu()
menu2 = wx.Menu()
#菜单布局
menu.Append(5000, "&New Window")
menu.Append(5001, "&Exit")
menu2.Append(1000,"&color")
menubar = wx.MenuBar()
menubar.Append(menu, "&File")
menubar.Append(menu2,"&tools")
self.SetMenuBar(menubar)
self.Bind(wx.EVT_MENU, self.OnNewWindow, id = 5000)
self.Bind(wx.EVT_MENU, self.OnExit, id = 5001)
def OnExit(self, event):
self.Close(True)
def OnNewWindow(self,event):
win = wx.MDIChildFrame(self, -1,str(self.__childNum))
self.__childNum += 1
b = 0
print(b)
b += 1
picture = drawPicture(200,200,10)
#self.__pictureCount += 1
def previewButton(event):
picture.showCanvas("Back")
def changeColor(event):
print("true to setColor")
print(self.__B)
B = self.__B.GetValue()
G = self.__G.GetValue()
R = self.__R.GetValue()
print(B,G,R)
picture.setPaintBrushColor(B,G,R)
def getColor(event):
data = wx.ColourData()
data.SetChooseFull(True)
for i in range(0,16):
colour = wx.Colour(i*16, i*16, i*16)
data.SetCustomColour(i, colour)
dialog = wx.ColourDialog(self, data)
if dialog.ShowModal() == wx.ID_OK:
retData = dialog.GetColourData()
col = retData.GetColour()
brush = wx.Brush(col, wx.SOLID)
picture.setPaintBrushColor(col[2],col[1],col[0],)
#myWindow.SetBackground(brush)
#myWindow.Clear()
#myWindow.Refresh()
def saveButton(event):
with wx.FileDialog(self, "Save jpg file", wildcard="jpg files (*.jpg)|*.png",
style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) as fileDialog:
if fileDialog.ShowModal() == wx.ID_CANCEL:
return # the user changed their mind
# save the current contents in the file
pathname = fileDialog.GetPath()
try:
with open(pathname, 'w') as file:
cv2.imwrite(pathname,picture.getCanvas())
except IOError:
wx.LogError("Cannot save current data in file '%s'." % pathname)
panel = wx.Panel(win)#背景组件
vbox = wx.BoxSizer(wx.VERTICAL)
#窗口按钮布局
btnPreview= wx.Button(panel,-1,u"预览",pos=(0,0),size=(50,30))
vbox.Add(btnPreview,0,wx.ALIGN_CENTER)
btnChangeColor = wx.Button(panel,-1,u"自定义色彩",pos=(70,0),size=(50,30))
vbox.Add(btnChangeColor,0,wx.ALIGN_CENTER)
btnSave = wx.Button(panel, -1, u"保存",pos = (150,0),size = (50,30))
#vbox.Add(btnChangeColor,0,wx.ALIGN_CENTER)
btnGetColor = wx.Button(panel, -1, u"色彩选择",pos = (210,0),size = (50,30))
#vbox.Add(btnChangeColor,0,wx.ALIGN_CENTER)
btnPreview.Bind(wx.EVT_BUTTON,previewButton)
btnChangeColor.Bind(wx.EVT_BUTTON,changeColor)
btnSave.Bind(wx.EVT_BUTTON,saveButton)
btnGetColor.Bind(wx.EVT_BUTTON,getColor)
#窗口参数输入框布局
hbox1 = wx.BoxSizer(wx.HORIZONTAL)
self.__B = wx.TextCtrl(panel,style=wx.TE_RICH,pos=(3,40),size=(60,20))
self.__G = wx.TextCtrl(panel,style=wx.TE_RICH,pos=(73,40),size=(60,20))
self.__R = wx.TextCtrl(panel,style=wx.TE_RICH,pos=(143,40),size=(60,20))
hbox1.Add(self.__R,1,wx.EXPAND|wx.ALIGN_CENTER|wx.ALL,5)
hbox1.Add(self.__G,1,wx.EXPAND|wx.ALIGN_CENTER|wx.ALL,5)
hbox1.Add(self.__B,1,wx.EXPAND|wx.ALIGN_CENTER|wx.ALL,5)
#cv2.imshow("hello",cv2.imread('F:\example.jpeg'))
win.Show(True)
app = wx.App()
frame = MDIFrame()
frame.Show()
app.MainLoop()