-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
197 lines (162 loc) · 6.83 KB
/
main.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# ------------------------------------------------------------
# mediaLocker.py
#
# Author: Mike Driscoll
# Contact: mike@pythonlibrary.org
#
# This program demonstrates how to work with a SQLite database
# using wxPython and SqlAlchemy. It is also an example of MVC
# concepts and how to put together a fully working wxPython
# application.
# ------------------------------------------------------------
import addModRecord
import commonDlgs
from controller import Controller
import wx
from ObjectListView import ObjectListView, ColumnDefn
from model import SaleOrder
########################################################################
class ButtonPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
addRecordBtn = wx.Button(self, label="Add")
addRecordBtn.Bind(wx.EVT_BUTTON, parent.onAddRecord)
btnSizer.Add(addRecordBtn, 0, wx.ALL, 5)
editRecordBtn = wx.Button(self, label="Edit")
editRecordBtn.Bind(wx.EVT_BUTTON, parent.onEditRecord)
btnSizer.Add(editRecordBtn, 0, wx.ALL, 5)
deleteRecordBtn = wx.Button(self, label="Delete")
deleteRecordBtn.Bind(wx.EVT_BUTTON, parent.onDelete)
btnSizer.Add(deleteRecordBtn, 0, wx.ALL, 5)
showAllBtn = wx.Button(self, label="Show All")
showAllBtn.Bind(wx.EVT_BUTTON, parent.onShowAllRecord)
btnSizer.Add(showAllBtn, 0, wx.ALL, 5)
self.SetSizer(btnSizer)
########################################################################
class SearchPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
# create the search related widgets
font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)
searchSizer = wx.BoxSizer(wx.HORIZONTAL)
cat = ["Author", "Title", "ISBN", "Publisher"]
searchByLbl = wx.StaticText(self, label="Search By:")
searchByLbl.SetFont(font)
searchSizer.Add(searchByLbl, 0, wx.ALL, 5)
self.categories = wx.ComboBox(self, value="Author", choices=cat)
searchSizer.Add(self.categories, 0, wx.ALL, 5)
self.search = wx.SearchCtrl(self, style=wx.TE_PROCESS_ENTER)
self.search.Bind(wx.EVT_TEXT_ENTER, parent.onSearch)
searchSizer.Add(self.search, 0, wx.ALL, 5)
self.SetSizer(searchSizer)
########################################################################
class ListViewPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
self.controller=Controller(SaleOrder,"sqlite:///odoo.db")
controller=self.controller
wx.Panel.__init__(self, parent)
try:
self.olvResults = controller.getAllRecords()
except:
self.olvResults = []
#Panels
search_panel=SearchPanel(self)
button_panel=ButtonPanel(self)
#ListView
self.olvResultsOlv = ObjectListView(self, style=wx.LC_REPORT
|wx.SUNKEN_BORDER)
self.olvResultsOlv.SetEmptyListMsg("No Records Found")
self.setRows()
#Organize the shit
mainSizer = wx.BoxSizer(wx.VERTICAL)
mainSizer.Add(search_panel)
mainSizer.Add(self.olvResultsOlv, 1, wx.ALL|wx.EXPAND, 5)
mainSizer.Add(button_panel, 0, wx.CENTER)
self.SetSizer(mainSizer)
#----------------------------------------------------------------------
def onAddRecord(self, event):
"""
Add a record to the database
"""
dlg = addModRecord.AddModRecDialog()
dlg.ShowModal()
dlg.Destroy()
self.showAllRecords()
#----------------------------------------------------------------------
def onEditRecord(self, event):
"""
Edit a record
"""
selectedRow = self.olvResultsOlv.GetSelectedObject()
if selectedRow == None:
commonDlgs.showMessageDlg("No row selected!", "Error")
return
dlg = addModRecord.AddModRecDialog(selectedRow, title="Modify",
addRecord=False)
dlg.ShowModal()
dlg.Destroy()
self.showAllRecords()
#----------------------------------------------------------------------
def onDelete(self, event):
"""
Delete a record
"""
selectedRow = self.olvResultsOlv.GetSelectedObject()
if selectedRow == None:
commonDlgs.showMessageDlg("No row selected!", "Error")
return
self.controller.deleteRecord(selectedRow.id)
self.showAllRecords()
#----------------------------------------------------------------------
def onSearch(self, event):
"""
Searches database based on the user's filter choice and keyword
"""
filterChoice = self.categories.GetValue()
keyword = self.search.GetValue()
print "%s %s" % (filterChoice, keyword)
self.olvResults = self.controller.searchRecords(filterChoice, keyword)
self.setRows()
#----------------------------------------------------------------------
def onShowAllRecord(self, event):
"""
Updates the record list to show all of them
"""
self.showAllRecords()
#----------------------------------------------------------------------
def setRows(self):
column_defs=[]
#TODO: mudar para Table_Class.formato
for column_def in self.olvResults[0].formato:
column_defs.append(ColumnDefn(column_def["label"],
column_def["align"],
column_def["size"],
column_def["field"]))
self.olvResultsOlv.SetColumns(column_defs)
self.olvResultsOlv.SetObjects(self.olvResults)
#----------------------------------------------------------------------
def showAllRecords(self):
"""
Show all records in the object list view control
"""
self.olvResults = self.controller.getAllRecords()
self.setRows()
########################################################################
class GridFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Vendas Grings",
size=(800, 600))
panel = ListViewPanel(self)
self.Show()
#----------------------------------------------------------------------
if __name__ == "__main__":
app = wx.App(False)
frame = GridFrame()
app.MainLoop()