Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import wx
- import ectworker as EW
- import panelTwo as pTwo
- import panelThree as pThree
- import commonDlgs as cdlg
- TabLabel = 'Input Panel'
- class TabPanel(wx.Panel):
- def __init__(self, parent):
- wx.Panel.__init__(self, parent)
- self.topSizer = wx.BoxSizer(wx.VERTICAL) # <- This is the main container
- # Creating the widgets we will be using
- labelOne = wx.StaticText(self, wx.ID_ANY, ' One: ')
- self.inputTxtOne = wx.TextCtrl(self, wx.ID_ANY, 'Click Browse...')
- btnBrwsOne = wx.Button(self, wx.ID_ANY, 'Browse')
- btnClrOne = wx.Button(self, wx.ID_ANY, 'Clear')
- labelTwo = wx.StaticText(self, wx.ID_ANY, ' Two: ')
- self.inputTxtTwo = wx.TextCtrl(self, wx.ID_ANY, 'Click Browse...')
- btnBrwsTwo = wx.Button(self, wx.ID_ANY, 'Browse')
- btnClrTwo = wx.Button(self, wx.ID_ANY, 'Clear')
- labelThree = wx.StaticText(self, wx.ID_ANY, ' Three: ')
- self.inputTxtThree = wx.TextCtrl(self, wx.ID_ANY, 'Click Browse...')
- btnBrwsThree = wx.Button(self, wx.ID_ANY, 'Browse')
- btnClrThree = wx.Button(self, wx.ID_ANY, 'Clear')
- okBtn = wx.Button(self, wx.ID_ANY, 'Run')
- clearBtn = wx.Button(self, wx.ID_ANY, 'Clear All')
- # Adding the widgets to the main sizer
- self.AddToSizer(labelOne, self.inputTxtOne, wx.ALL|wx.EXPAND)
- self.AddButtons(btnBrwsOne, btnClrOne, wx.ALL|wx.EXPAND)
- self.topSizer.Add(wx.StaticLine(self), 0, wx.ALL|wx.EXPAND, 5)
- self.AddToSizer(labelTwo, self.inputTxtTwo, wx.ALL|wx.EXPAND)
- self.AddButtons(btnBrwsTwo, btnClrTwo, wx.ALL|wx.EXPAND)
- self.topSizer.Add(wx.StaticLine(self), 0, wx.ALL|wx.EXPAND, 5)
- self.AddToSizer(labelThree, self.inputTxtThree, wx.ALL|wx.EXPAND)
- self.AddButtons(btnBrwsThree, btnClrThree, wx.ALL|wx.EXPAND)
- self.topSizer.Add(wx.StaticLine(self), 0, wx.ALL|wx.EXPAND, 5)
- self.AddButtons(okBtn, clearBtn, wx.CENTER)
- self.SetSizer(self.topSizer)
- # Binding events to the buttons
- self.Bind(wx.EVT_BUTTON, self.OnBrowseOne, btnBrwsOne)
- self.Bind(wx.EVT_BUTTON, self.OnBrowseTwo, btnBrwsTwo)
- self.Bind(wx.EVT_BUTTON, self.OnBrowseThree, btnBrwsThree)
- self.Bind(wx.EVT_BUTTON, self.OnBrowseHealth, btnBrwsHealth)
- self.Bind(wx.EVT_BUTTON, self.OnClearInv, btnClrOne)
- self.Bind(wx.EVT_BUTTON, self.OnClearSales, btnClrTwo)
- self.Bind(wx.EVT_BUTTON, self.OnClearMeta, btnClrThree)
- self.Bind(wx.EVT_BUTTON, self.OnRun, okBtn)
- self.Bind(wx.EVT_BUTTON, self.OnClearAll, clearBtn)
- # Adjust the widget properties
- # Input text fields
- self.ApplyTextAttributes(self.inputTxtOne)
- self.ApplyTextAttributes(self.inputTxtTwo)
- self.ApplyTextAttributes(self.inputTxtThree)
- # One
- self.ApplyBtnAttributes(btnBrwsOne, 'Select the first file.')
- self.ApplyBtnAttributes(btnClrOne, 'Clear first file Field')
- # Two
- self.ApplyBtnAttributes(btnBrwsTwo, 'Select the second file.')
- self.ApplyBtnAttributes(btnClrTwo, 'Clear second file Field')
- # Three
- self.ApplyBtnAttributes(btnBrwsThree, 'Select the Control file.')
- self.ApplyBtnAttributes(btnClrThree, 'Clear Control file Field')
- # Ok and Clear All buttons
- self.ApplyBtnAttributes(okBtn, 'Run Application')
- self.ApplyBtnAttributes(clearBtn, 'Exit Application')
- # "Dynamic" add widget to main sizer definition.
- def AddToSizer(self, item1, item2, flags):
- hSizer = wx.BoxSizer(wx.HORIZONTAL)
- hSizer.Add(item1, 0, wx.ALL|wx.EXPAND, 5)
- if item2 != None:
- hSizer.Add(item2, 1, wx.ALL|wx.EXPAND, 5)
- self.topSizer.Add(hSizer, 0, flags, 5)
- # Adding button's to main sizer
- def AddButtons(self, item1, item2, flags):
- hSizer = wx.BoxSizer(wx.HORIZONTAL)
- hSizer.Add(item1, 0, wx.ALL|wx.EXPAND, 5)
- hSizer.Add(item2, 0, wx.ALL|wx.EXPAND, 5)
- self.topSizer.Add(hSizer, 0, flags, 5)
- # Set text field properties
- def ApplyTextAttributes(self, item1):
- item1.SetBackgroundColour((255, 255, 255))
- item1.SetCursor(wx.StockCursor(wx.CURSOR_NO_ENTRY))
- item1.SetToolTip(wx.ToolTip('Click the browse button!'))
- item1.SetEditable(False)
- # Adjust button attributes
- def ApplyBtnAttributes(self, item1, item2):
- item1.SetCursor(wx.StockCursor(wx.CURSOR_HAND))
- item1.SetToolTip(wx.ToolTip(item2))
- # Button and other Events
- def OnBrowseOne(self, event):
- """ Open a file. """
- self.dlg = wx.FileDialog(self, 'Choose a file', '', '', '*.xml', wx.OPEN)
- if self.dlg.ShowModal () == wx.ID_OK:
- self.filename = self.dlg.GetFilename()
- self.dirname = self.dlg.GetDirectory()
- self.inputTxtOne.SetValue('%s\\%s' % (self.dirname, self.filename))
- self.dlg.Destroy()
- def OnBrowseTwo(self, event):
- """ Open a file. """
- self.dlg = wx.FileDialog(self, 'Choose a file', '', '', '*.xml', wx.OPEN)
- if self.dlg.ShowModal () == wx.ID_OK:
- self.filename = self.dlg.GetFilename()
- self.dirname = self.dlg.GetDirectory()
- self.inputTxtTwo.SetValue('%s\\%s' % (self.dirname, self.filename))
- self.dlg.Destroy()
- def OnBrowseThree(self, event):
- """ Open a file. """
- self.dlg = wx.FileDialog(self, 'Choose a file', '', '', '*control*.xml', wx.OPEN)
- if self.dlg.ShowModal () == wx.ID_OK:
- self.filename = self.dlg.GetFilename()
- self.dirname = self.dlg.GetDirectory()
- self.inputTxtThree.SetValue('%s\\%s' % (self.dirname, self.filename))
- self.dlg.Destroy()
- def OnClearInv(self, event):
- """ Clear Inventory Field. """
- self.inputTxtOne.SetValue('Click Browse...')
- def OnClearSales(self, event):
- """ Clear Sales Field. """
- self.inputTxtTwo.SetValue('Click Browse...')
- def OnClearMeta(self, event):
- """ Clear Meta Data Field. """
- def OnClearAll(self, event):
- self.inputTxtOne.SetValue('Click Browse...')
- self.inputTxtTwo.SetValue('Click Browse...')
- self.inputTxtThree.SetValue('Click Browse...')
- def OnRun(self, event):
- EW.clearVariables()
- cdlg.showInfoDlg('Processing will begin when you click OK.\nPlease wait while the data is processed.', 'Information')
- if self.inputTxtOne.GetValue() != 'Click Browse...' and self.inputTxtTwo.GetValue() != 'Click Browse...' and self.inputTxtThree.GetValue() != 'Click Browse...':
- EW.parseOne(self.inputTxtOne.GetValue())
- EW.parseTwo(self.inputTxtTwo.GetValue())
- EW.parseThree(self.inputTxtThree.GetValue())
- EW.prepareOutput()
- EW.finalizeOutput()
- pTwo.invOutput = EW.dataVars.invOutput
- pThree.salesOutput = EW.dataVars.salesOutput
- else:
- cdlg.showErrorDlg('Error loading one of the files. \n Please ensure you have filled in all three file selections.', 'Error')
- #----------------------------------------------------------------------
- if __name__ == '__main__':
- print('File file is not meant to be run as a stand alone application.')
- print(' Please try again by running the main program.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement