-
Notifications
You must be signed in to change notification settings - Fork 0
/
automat.py
168 lines (135 loc) · 6.13 KB
/
automat.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env python
import wx
import resource
import config
import configDialog
class Automatization(wx.Frame):
""" Main application Frame.
This is the main frame to be displayed by the application. It creates all
sort of widget and resources required to make the application work.
"""
def __init__(self, parent, ID):
""" Automatization initialization.
Initializes the main frame. Create all sizer and widgets.
"""
wx.Frame.__init__(self, parent, ID, 'Automatization YAML Configuration', size=(800, 480))
self.resourceHdlr = resource.ResourceHandler()
mainPanel = wx.Panel(self)
mainPanel.SetBackgroundColour('White')
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
mainSizer = wx.BoxSizer(wx.VERTICAL)
mainSizer.Add(self.createResourceButtons(mainPanel), 1, wx.EXPAND | wx.ALL, border=1)
mainSizer.Add(self.createConfigurationPanel(mainPanel), 2, wx.EXPAND | wx.ALL, border=1)
mainSizer.Add(self.createOutputPanel(mainPanel), 3, wx.EXPAND | wx.ALL, border=1)
mainPanel.SetSizer(mainSizer)
mainPanel.Fit()
def _sendToOutput(self):
""" Parse all resources and send information to the outputTextCtrl.
For every resource, information is parsed in the final YAML format and
it is displayed in the outputTextCtrl widget.
"""
self.outputTextCtrl.Clear()
for resId in [config.getResourceId(resource) for resource in config.RESOURCES]:
self.outputTextCtrl.AppendText(self.resourceHdlr.parseToYamlForAll(resId))
self.outputTextCtrl.SetInsertionPoint(0)
def _createResource(self, dialog):
""" Creates a resource entry.
It creates a resource entry which keep information about the format
and the data for every entry added.
"""
result = dialog.ShowModal()
if result == wx.ID_OK:
instance = dialog.GetSelection()
self.resourceHdlr.addResource(instance)
self._sendToOutput()
dialog.Destroy()
def createResourceButtons(self, panel):
""" Create all resource buttons.
It creates all resource buttons and bind them to the OnClickEvent
handler.
"""
sizer = wx.BoxSizer(wx.HORIZONTAL)
for resId in [config.getResourceId(resource) for resource in config.RESOURCES]:
button = wx.Button(panel, -1, resId)
sizer.Add(button, 1, wx.HORIZONTAL)
self.Bind(wx.EVT_BUTTON, self.OnClickConfig, button)
#eventBtn = wx.Button(panel, -1, 'Event')
#sizer.Add(eventBtn, 1, wx.HORIZONTAL)
#self.Bind(wx.EVT_BUTTON, self.OnClickEvent, eventBtn)
return sizer
def createConfigurationPanel(self, panel):
""" Create configuration panel.
It creates the configuration panel which holds widget that display all
resources entered. Resources can be edited and deleted using this panel.
"""
mainSizer = wx.BoxSizer(wx.HORIZONTAL)
configListBox = wx.ListBox(panel, -1, style=wx.LB_SINGLE)
mainSizer.Add(configListBox, 1, wx.EXPAND | wx.ALL, border=10)
self.resourceHdlr.widget = configListBox
editBtn = wx.Button(panel, -1, 'EDIT')
removeBtn = wx.Button(panel, -1, 'REMOVE')
self.Bind(wx.EVT_BUTTON, self.OnClickEdit, editBtn)
self.Bind(wx.EVT_BUTTON, self.OnClickRemove, removeBtn)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.AddSpacer(50)
sizer.Add(editBtn, 0, wx.HORIZONTAL)
sizer.AddSpacer(5)
sizer.Add(removeBtn, 0, wx.HORIZONTAL)
mainSizer.AddSpacer(10)
mainSizer.Add(sizer, 0, wx.EXPAND)
mainSizer.AddSpacer(10)
return mainSizer
def createOutputPanel(self, panel):
""" Create output panel.
It created the output panel which holds widget that display all
resources entered in YAML format.
"""
sizer = wx.BoxSizer(wx.VERTICAL)
self.outputTextCtrl = wx.TextCtrl(panel, -1, "", style=wx.TE_MULTILINE | wx.TE_RICH2)
outputStyle = wx.TextAttr()
outputStyle.SetTabs([40, 80, 120, 160, 200, 240, 280])
self.outputTextCtrl.SetDefaultStyle(outputStyle)
sizer.Add(self.outputTextCtrl, 1, wx.EXPAND | wx.ALL, border=10)
return sizer
def OnCloseWindow(self, ev):
""" Close window event handler.
"""
self.Destroy()
def OnClickConfig(self, ev):
""" OnClick any resource button event handler.
It handles events when a resource button is clicked. Dialog for the
given resource will be launched.
"""
resId = ev.GetEventObject().Label
resource = config.getResourceFromId(resId)
dialog = configDialog.ConfigDialog(self, -1, resource)
self._createResource(dialog)
def OnClickEdit(self, ev):
""" OnClick edit resource event.
It handles when the EDIT resource button is clicked. Selected resource
will be launched with resource data.
"""
selection = self.resourceHdlr.widget.GetSelection()
if selection != -1:
instance = self.resourceHdlr.resources[selection]
dialog = instance.createDialog(self, -1)
result = dialog.ShowModal()
if result == wx.ID_OK:
instance = dialog.GetSelection()
self.resourceHdlr.replaceResource(instance, selection)
self._sendToOutput()
dialog.Destroy()
def OnClickRemove(self, ev):
""" OnClick delete resource event.
It handles when the REMOVE resource button is ckicled. Selected
resource will be removed.
"""
selection = self.resourceHdlr.widget.GetSelection()
if selection != -1:
self.resourceHdlr.deleteResource(selection)
self._sendToOutput()
if __name__ == '__main__':
app = wx.PySimpleApp(False)
frame = Automatization(parent=None, ID=-1)
frame.Show()
app.MainLoop()