| 1 |
nino.borges |
693 |
"""
|
| 2 |
|
|
|
| 3 |
|
|
IncomingProdAnalyzer_UI
|
| 4 |
|
|
|
| 5 |
|
|
Created by
|
| 6 |
|
|
Emanuel Borges
|
| 7 |
|
|
2020.05.12
|
| 8 |
|
|
|
| 9 |
|
|
UI for the incoming prod analyzer program.
|
| 10 |
|
|
|
| 11 |
|
|
"""
|
| 12 |
|
|
|
| 13 |
|
|
|
| 14 |
|
|
|
| 15 |
|
|
|
| 16 |
|
|
import wx, os
|
| 17 |
|
|
import wx.lib.agw.pybusyinfo as PBI
|
| 18 |
nino.borges |
697 |
import IncomingProdAnalyzer, DatReportDialog
|
| 19 |
nino.borges |
693 |
|
| 20 |
|
|
|
| 21 |
nino.borges |
710 |
class MyDataConstants(object):
|
| 22 |
|
|
def __init__(self, totalRecordCount, fullFieldList, populatedFieldsList, emptyFieldsList, parsingErrorCount, contents, quoteChar, delim):
|
| 23 |
|
|
self.totalRecordCount = totalRecordCount
|
| 24 |
|
|
self.fullFieldList = fullFieldList
|
| 25 |
|
|
self.populatedFieldsList = populatedFieldsList
|
| 26 |
|
|
self.emptyFieldsList = emptyFieldsList
|
| 27 |
|
|
self.parsingErrorCount = parsingErrorCount
|
| 28 |
|
|
self.contents = contents
|
| 29 |
|
|
self.quoteChar = quoteChar
|
| 30 |
|
|
self.delim = delim
|
| 31 |
|
|
self.BegBatesFieldNumber = ""
|
| 32 |
|
|
self.EndBatesFieldNumber = ""
|
| 33 |
|
|
|
| 34 |
nino.borges |
693 |
|
| 35 |
|
|
class MyFrame(wx.Frame):
|
| 36 |
|
|
def __init__(self, parent, ID, title, pos=wx.DefaultPosition):
|
| 37 |
nino.borges |
710 |
print dataConst.totalRecordCount
|
| 38 |
|
|
wx.Frame.__init__(self, parent, ID, title, pos, size = (1000,700))
|
| 39 |
|
|
|
| 40 |
nino.borges |
693 |
self.panel = wx.Panel(self,-1)
|
| 41 |
nino.borges |
710 |
#self.currentCaseStaticText = wx.StaticText(self.panel, -1, "Simple program for performing analysis on incoming productions before loading.",wx.DefaultPosition)
|
| 42 |
|
|
self.CreateStatusBar()
|
| 43 |
|
|
self.SetStatusText("Ready.")
|
| 44 |
|
|
self.CreateMenuBar()
|
| 45 |
|
|
|
| 46 |
nino.borges |
693 |
|
| 47 |
nino.borges |
710 |
recordCountLabel = wx.StaticText(self.panel, -1, "Number of records in DAT: %s "% dataConst.totalRecordCount)
|
| 48 |
|
|
parsingErrorCountLabel = wx.StaticText(self.panel, -1, "There are %s parsing errors in this DAT"% dataConst.parsingErrorCount)
|
| 49 |
nino.borges |
693 |
|
| 50 |
nino.borges |
710 |
fullFieldListLabel = wx.StaticText(self.panel, -1, "Fields In DAT:")
|
| 51 |
|
|
fullFieldListText = ''
|
| 52 |
|
|
for i in dataConst.fullFieldList:
|
| 53 |
|
|
fullFieldListText = fullFieldListText + "%s\n"% i
|
| 54 |
nino.borges |
693 |
|
| 55 |
nino.borges |
710 |
fullFieldListTextBox = wx.TextCtrl(self.panel, -1, fullFieldListText, wx.DefaultPosition, (300,460), style=wx.TE_MULTILINE)
|
| 56 |
nino.borges |
693 |
|
| 57 |
|
|
|
| 58 |
nino.borges |
710 |
populatedFieldsListLabel = wx.StaticText(self.panel, -1, "Populated Fields:")
|
| 59 |
|
|
populatedFieldsListText = ''
|
| 60 |
|
|
for i in dataConst.populatedFieldsList:
|
| 61 |
|
|
populatedFieldsListText = populatedFieldsListText + "%s\n"% i
|
| 62 |
|
|
|
| 63 |
|
|
populatedFieldsListTextBox = wx.TextCtrl(self.panel, -1, populatedFieldsListText, wx.DefaultPosition, (300,460), style=wx.TE_MULTILINE)
|
| 64 |
|
|
|
| 65 |
|
|
|
| 66 |
|
|
emptyFieldsListLabel = wx.StaticText(self.panel, -1, "Empty Fields:")
|
| 67 |
|
|
emptyFieldsListText = ''
|
| 68 |
|
|
for i in dataConst.emptyFieldsList:
|
| 69 |
|
|
emptyFieldsListText = emptyFieldsListText + "%s\n"% i
|
| 70 |
|
|
|
| 71 |
|
|
emptyFieldsListTextBox = wx.TextCtrl(self.panel, -1, emptyFieldsListText, wx.DefaultPosition, (300,460), style=wx.TE_MULTILINE)
|
| 72 |
|
|
|
| 73 |
|
|
|
| 74 |
|
|
topSectionSizer = wx.BoxSizer(wx.HORIZONTAL)
|
| 75 |
|
|
topSectionSizer.Add(recordCountLabel, 0)
|
| 76 |
|
|
topSectionSizer.Add(parsingErrorCountLabel, 0, wx.LEFT, 400)
|
| 77 |
|
|
|
| 78 |
|
|
fullFieldListSizer = wx.BoxSizer(wx.VERTICAL)
|
| 79 |
|
|
fullFieldListSizer.Add(fullFieldListLabel, 0, wx.ALIGN_LEFT)
|
| 80 |
|
|
fullFieldListSizer.Add(fullFieldListTextBox, 0)
|
| 81 |
|
|
|
| 82 |
|
|
populatedFieldsListSizer = wx.BoxSizer(wx.VERTICAL)
|
| 83 |
|
|
populatedFieldsListSizer.Add(populatedFieldsListLabel, 0, wx.ALIGN_LEFT)
|
| 84 |
|
|
populatedFieldsListSizer.Add(populatedFieldsListTextBox, 0)
|
| 85 |
|
|
|
| 86 |
|
|
emptyFieldsListSizer = wx.BoxSizer(wx.VERTICAL)
|
| 87 |
|
|
emptyFieldsListSizer.Add(emptyFieldsListLabel, 0, wx.ALIGN_LEFT)
|
| 88 |
|
|
emptyFieldsListSizer.Add(emptyFieldsListTextBox, 0)
|
| 89 |
|
|
|
| 90 |
|
|
midSectionSizer = wx.BoxSizer(wx.HORIZONTAL)
|
| 91 |
|
|
midSectionSizer.Add(fullFieldListSizer, 0, wx.ALL, 10)
|
| 92 |
|
|
midSectionSizer.Add(populatedFieldsListSizer, 0, wx.ALL, 10)
|
| 93 |
|
|
midSectionSizer.Add(emptyFieldsListSizer, 0, wx.ALL, 10)
|
| 94 |
|
|
|
| 95 |
|
|
|
| 96 |
|
|
|
| 97 |
nino.borges |
693 |
mainSizer = wx.BoxSizer(wx.VERTICAL)
|
| 98 |
nino.borges |
710 |
mainSizer.Add(topSectionSizer,0, wx.ALL, 40)
|
| 99 |
|
|
mainSizer.Add(midSectionSizer, 0, wx.ALL, 20)
|
| 100 |
|
|
|
| 101 |
nino.borges |
693 |
|
| 102 |
nino.borges |
710 |
#oKButton = wx.Button(self.panel, wx.ID_OK)
|
| 103 |
|
|
#oKButton.SetDefault()
|
| 104 |
|
|
|
| 105 |
|
|
#mainSizer.Add(oKButton,0, wx.ALL|wx.ALIGN_CENTER, 10)
|
| 106 |
nino.borges |
693 |
|
| 107 |
nino.borges |
710 |
self.SetSizer(mainSizer)
|
| 108 |
nino.borges |
693 |
|
| 109 |
|
|
|
| 110 |
nino.borges |
710 |
def MenuData(self):
|
| 111 |
|
|
return(("&Tools",
|
| 112 |
|
|
("List Bates Ranges", "Displays a list of the bates ranges in this DAT.", self.OnListBatesRanges),
|
| 113 |
|
|
("test 2", "Bla2 Bla2", self.NothingYet)),
|
| 114 |
|
|
("&Reports",
|
| 115 |
|
|
("&Field Report","Generates a spreadsheet report detailing fields with and without information.", self.OnGenerateFieldReport)),
|
| 116 |
|
|
("&Help",
|
| 117 |
|
|
("@About", "Displays the About Window", self.NothingYet)))
|
| 118 |
nino.borges |
693 |
|
| 119 |
nino.borges |
710 |
def NothingYet(self, event):
|
| 120 |
|
|
diag = wx.MessageDialog(self, "Nothing here yet!", "Disabled...", wx.OK | wx.ICON_INFORMATION)
|
| 121 |
|
|
diag.ShowModal()
|
| 122 |
|
|
diag.Destroy()
|
| 123 |
nino.borges |
693 |
|
| 124 |
nino.borges |
710 |
|
| 125 |
|
|
def CreateMenuBar(self):
|
| 126 |
|
|
menuBar = wx.MenuBar()
|
| 127 |
|
|
for eachMenuData in self.MenuData():
|
| 128 |
|
|
menuLabel = eachMenuData[0]
|
| 129 |
|
|
menuItems = eachMenuData[1:]
|
| 130 |
|
|
menuBar.Append(self.CreateMenu(menuItems), menuLabel)
|
| 131 |
|
|
self.SetMenuBar(menuBar)
|
| 132 |
|
|
|
| 133 |
|
|
def CreateMenu(self, menuData):
|
| 134 |
|
|
menu = wx.Menu()
|
| 135 |
|
|
for eachLabel, eachStatus, eachHandler in menuData:
|
| 136 |
|
|
if not eachLabel:
|
| 137 |
|
|
menu.AppendSeparator()
|
| 138 |
|
|
continue
|
| 139 |
|
|
menuItem = menu.Append(-1, eachLabel, eachStatus)
|
| 140 |
|
|
self.Bind(wx.EVT_MENU, eachHandler, menuItem)
|
| 141 |
|
|
return menu
|
| 142 |
|
|
|
| 143 |
|
|
def OnListBatesRanges(self,event):
|
| 144 |
|
|
dlg = wx.MultiChoiceDialog(self,
|
| 145 |
|
|
"Select both the BegBates and EndBates fields",
|
| 146 |
|
|
"List Bates Ranges", dataConst.populatedFieldsList)
|
| 147 |
|
|
if (dlg.ShowModal() == wx.ID_OK):
|
| 148 |
|
|
message = "Calulating from your DAT file..."
|
| 149 |
|
|
busy = PBI.PyBusyInfo(message, parent=None, title="System Busy: Hold Yer Horses!")
|
| 150 |
|
|
selections = dlg.GetSelections()
|
| 151 |
|
|
strings = [dataConst.populatedFieldsList[x] for x in selections]
|
| 152 |
|
|
#print strings
|
| 153 |
|
|
colsNumbsToIngest = []
|
| 154 |
|
|
for s in strings:
|
| 155 |
|
|
colsNumbsToIngest.append(dataConst.fullFieldList.index(s))
|
| 156 |
|
|
test = IncomingProdAnalyzer.CreateBatesRangeList(colsNumbsToIngest, dataConst.contents, dataConst.quoteChar, dataConst.delim)
|
| 157 |
|
|
test2 = ""
|
| 158 |
|
|
print test
|
| 159 |
|
|
for r in test:
|
| 160 |
|
|
test2 = test2 + str(r)+"\n"
|
| 161 |
|
|
del busy
|
| 162 |
|
|
dlg = wx.TextEntryDialog(
|
| 163 |
|
|
self, '',
|
| 164 |
|
|
'Ranges in this Dat', '', style = wx.TE_MULTILINE)
|
| 165 |
|
|
dlg.SetValue(test2)
|
| 166 |
|
|
dlg.ShowModal()
|
| 167 |
|
|
dlg.Destroy()
|
| 168 |
|
|
|
| 169 |
|
|
def OnGenerateFieldReport(self,event):
|
| 170 |
nino.borges |
693 |
dlg = wx.FileDialog(
|
| 171 |
nino.borges |
710 |
self, message="Save report as ...", defaultDir=os.path.expanduser("~\\Documents"),
|
| 172 |
|
|
defaultFile="", wildcard="Excel files (*.xlsx)|*.xlsx", style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT
|
| 173 |
|
|
)
|
| 174 |
|
|
if dlg.ShowModal() == wx.ID_OK:
|
| 175 |
|
|
spreadSheetPath = dlg.GetPath()
|
| 176 |
|
|
IncomingProdAnalyzer.CreateExcelDatReport(spreadSheetPath, dataConst.fullFieldList, dataConst.emptyFieldsList, dataConst.totalRecordCount)
|
| 177 |
|
|
doneDiag = wx.MessageDialog(self, "Report saved to\n%s"%spreadSheetPath,"All Done!",wx.OK | wx.ICON_INFORMATION)
|
| 178 |
|
|
doneDiag.ShowModal()
|
| 179 |
|
|
doneDiag.Destroy()
|
| 180 |
|
|
|
| 181 |
|
|
def CloseWindow(self,event):
|
| 182 |
|
|
self.Close(True)
|
| 183 |
|
|
|
| 184 |
|
|
class MyApp(wx.App):
|
| 185 |
|
|
def OnInit(self):
|
| 186 |
|
|
dlg = wx.FileDialog(
|
| 187 |
|
|
None, message="Choose a DAT file to begin",
|
| 188 |
nino.borges |
693 |
defaultDir=os.path.expanduser("~\\Documents"),
|
| 189 |
|
|
defaultFile="",
|
| 190 |
|
|
wildcard="DAT files (*.Dat)|*.Dat",
|
| 191 |
|
|
style=wx.FD_OPEN |
|
| 192 |
|
|
wx.FD_CHANGE_DIR | wx.FD_FILE_MUST_EXIST |
|
| 193 |
|
|
wx.FD_PREVIEW
|
| 194 |
|
|
)
|
| 195 |
|
|
if dlg.ShowModal() == wx.ID_OK:
|
| 196 |
nino.borges |
710 |
rawReportPath = dlg.GetPath()
|
| 197 |
|
|
message = "Analyzing your DAT file..."
|
| 198 |
|
|
busy = PBI.PyBusyInfo(message, parent=None, title="System Busy: Hold Yer Horses!")
|
| 199 |
|
|
totalRecordCount, fullFieldList, populatedFieldsList, emptyFieldsList, parsingErrorCount, contents, quoteChar, delim = IncomingProdAnalyzer.AnalyzeDAT(rawReportPath)
|
| 200 |
|
|
del busy
|
| 201 |
|
|
global dataConst
|
| 202 |
|
|
dataConst = MyDataConstants(totalRecordCount, fullFieldList, populatedFieldsList, emptyFieldsList, parsingErrorCount, contents, quoteChar, delim)
|
| 203 |
|
|
#dlg2.ShowModal()
|
| 204 |
|
|
#dlg2.Destroy()
|
| 205 |
|
|
self.frame = MyFrame(None, -1, "Incoming Production Analyzer v 2.0")
|
| 206 |
|
|
self.frame.Show(True)
|
| 207 |
|
|
self.SetTopWindow(self.frame)
|
| 208 |
|
|
return True
|
| 209 |
|
|
else:
|
| 210 |
|
|
return False
|
| 211 |
nino.borges |
693 |
|
| 212 |
|
|
|
| 213 |
|
|
if __name__ == '__main__':
|
| 214 |
|
|
app = MyApp(0)
|
| 215 |
|
|
app.MainLoop() |