Advertisement
Hakugin

Panel 1 - panelOne.py

Aug 20th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.28 KB | None | 0 0
  1. import wx
  2. import ectworker as EW
  3. import panelTwo as pTwo
  4. import panelThree as pThree
  5. import commonDlgs as cdlg
  6.  
  7. TabLabel = 'Input Panel'
  8.  
  9. class TabPanel(wx.Panel):
  10.     def __init__(self, parent):
  11.         wx.Panel.__init__(self, parent)
  12.         self.topSizer = wx.BoxSizer(wx.VERTICAL) # <- This is the main container
  13.  
  14. # Creating the widgets we will be using
  15.         labelOne = wx.StaticText(self, wx.ID_ANY, ' One: ')
  16.         self.inputTxtOne = wx.TextCtrl(self, wx.ID_ANY, 'Click Browse...')
  17.         btnBrwsOne = wx.Button(self, wx.ID_ANY, 'Browse')
  18.         btnClrOne = wx.Button(self, wx.ID_ANY, 'Clear')
  19.  
  20.         labelTwo = wx.StaticText(self, wx.ID_ANY, ' Two:         ')
  21.         self.inputTxtTwo = wx.TextCtrl(self, wx.ID_ANY, 'Click Browse...')
  22.         btnBrwsTwo = wx.Button(self, wx.ID_ANY, 'Browse')
  23.         btnClrTwo = wx.Button(self, wx.ID_ANY, 'Clear')
  24.  
  25.         labelThree = wx.StaticText(self, wx.ID_ANY, ' Three: ')
  26.         self.inputTxtThree = wx.TextCtrl(self, wx.ID_ANY, 'Click Browse...')
  27.         btnBrwsThree = wx.Button(self, wx.ID_ANY, 'Browse')
  28.         btnClrThree = wx.Button(self, wx.ID_ANY, 'Clear')
  29.  
  30.         okBtn = wx.Button(self, wx.ID_ANY, 'Run')
  31.         clearBtn = wx.Button(self, wx.ID_ANY, 'Clear All')
  32.  
  33. # Adding the widgets to the main sizer
  34.         self.AddToSizer(labelOne, self.inputTxtOne, wx.ALL|wx.EXPAND)
  35.         self.AddButtons(btnBrwsOne, btnClrOne, wx.ALL|wx.EXPAND)
  36.         self.topSizer.Add(wx.StaticLine(self), 0, wx.ALL|wx.EXPAND, 5)
  37.         self.AddToSizer(labelTwo, self.inputTxtTwo, wx.ALL|wx.EXPAND)
  38.         self.AddButtons(btnBrwsTwo, btnClrTwo, wx.ALL|wx.EXPAND)
  39.         self.topSizer.Add(wx.StaticLine(self), 0, wx.ALL|wx.EXPAND, 5)
  40.         self.AddToSizer(labelThree, self.inputTxtThree, wx.ALL|wx.EXPAND)
  41.         self.AddButtons(btnBrwsThree, btnClrThree, wx.ALL|wx.EXPAND)
  42.         self.topSizer.Add(wx.StaticLine(self), 0, wx.ALL|wx.EXPAND, 5)
  43.         self.AddButtons(okBtn, clearBtn, wx.CENTER)
  44.         self.SetSizer(self.topSizer)
  45.  
  46. # Binding events to the buttons
  47.         self.Bind(wx.EVT_BUTTON, self.OnBrowseOne, btnBrwsOne)
  48.         self.Bind(wx.EVT_BUTTON, self.OnBrowseTwo, btnBrwsTwo)
  49.         self.Bind(wx.EVT_BUTTON, self.OnBrowseThree, btnBrwsThree)
  50.         self.Bind(wx.EVT_BUTTON, self.OnBrowseHealth, btnBrwsHealth)
  51.         self.Bind(wx.EVT_BUTTON, self.OnClearInv, btnClrOne)
  52.         self.Bind(wx.EVT_BUTTON, self.OnClearSales, btnClrTwo)
  53.         self.Bind(wx.EVT_BUTTON, self.OnClearMeta, btnClrThree)
  54.         self.Bind(wx.EVT_BUTTON, self.OnRun, okBtn)
  55.         self.Bind(wx.EVT_BUTTON, self.OnClearAll, clearBtn)
  56.  
  57. # Adjust the widget properties
  58.     # Input text fields
  59.         self.ApplyTextAttributes(self.inputTxtOne)
  60.         self.ApplyTextAttributes(self.inputTxtTwo)
  61.         self.ApplyTextAttributes(self.inputTxtThree)
  62.     # One
  63.         self.ApplyBtnAttributes(btnBrwsOne, 'Select the first file.')
  64.         self.ApplyBtnAttributes(btnClrOne, 'Clear first file Field')
  65.     # Two
  66.         self.ApplyBtnAttributes(btnBrwsTwo, 'Select the second file.')
  67.         self.ApplyBtnAttributes(btnClrTwo, 'Clear second file Field')
  68.     # Three
  69.         self.ApplyBtnAttributes(btnBrwsThree, 'Select the Control file.')
  70.         self.ApplyBtnAttributes(btnClrThree, 'Clear Control file Field')
  71.     # Ok and Clear All buttons
  72.         self.ApplyBtnAttributes(okBtn, 'Run Application')
  73.         self.ApplyBtnAttributes(clearBtn, 'Exit Application')
  74.  
  75. # "Dynamic" add widget to main sizer definition.
  76.     def AddToSizer(self, item1, item2, flags):
  77.         hSizer = wx.BoxSizer(wx.HORIZONTAL)
  78.         hSizer.Add(item1, 0, wx.ALL|wx.EXPAND, 5)
  79.         if item2 != None:
  80.             hSizer.Add(item2, 1, wx.ALL|wx.EXPAND, 5)
  81.         self.topSizer.Add(hSizer, 0, flags, 5)
  82.  
  83. # Adding button's to main sizer
  84.     def AddButtons(self, item1, item2, flags):
  85.         hSizer = wx.BoxSizer(wx.HORIZONTAL)
  86.         hSizer.Add(item1, 0, wx.ALL|wx.EXPAND, 5)
  87.         hSizer.Add(item2, 0, wx.ALL|wx.EXPAND, 5)
  88.         self.topSizer.Add(hSizer, 0, flags, 5)
  89.  
  90. # Set text field properties
  91.     def ApplyTextAttributes(self, item1):
  92.         item1.SetBackgroundColour((255, 255, 255))
  93.         item1.SetCursor(wx.StockCursor(wx.CURSOR_NO_ENTRY))
  94.         item1.SetToolTip(wx.ToolTip('Click the browse button!'))
  95.         item1.SetEditable(False)
  96.  
  97. # Adjust button attributes
  98.     def ApplyBtnAttributes(self, item1, item2):
  99.         item1.SetCursor(wx.StockCursor(wx.CURSOR_HAND))
  100.         item1.SetToolTip(wx.ToolTip(item2))
  101.  
  102. # Button and other Events
  103.     def OnBrowseOne(self, event):
  104.         """ Open a file. """
  105.         self.dlg = wx.FileDialog(self, 'Choose a file', '', '', '*.xml', wx.OPEN)
  106.         if self.dlg.ShowModal () == wx.ID_OK:
  107.             self.filename = self.dlg.GetFilename()
  108.             self.dirname = self.dlg.GetDirectory()
  109.             self.inputTxtOne.SetValue('%s\\%s' % (self.dirname, self.filename))
  110.         self.dlg.Destroy()
  111.  
  112.     def OnBrowseTwo(self, event):
  113.         """ Open a file. """
  114.         self.dlg = wx.FileDialog(self, 'Choose a file', '', '', '*.xml', wx.OPEN)
  115.         if self.dlg.ShowModal () == wx.ID_OK:
  116.             self.filename = self.dlg.GetFilename()
  117.             self.dirname = self.dlg.GetDirectory()
  118.             self.inputTxtTwo.SetValue('%s\\%s' % (self.dirname, self.filename))
  119.         self.dlg.Destroy()
  120.  
  121.     def OnBrowseThree(self, event):
  122.         """ Open a file. """
  123.         self.dlg = wx.FileDialog(self, 'Choose a file', '', '', '*control*.xml', wx.OPEN)
  124.         if self.dlg.ShowModal () == wx.ID_OK:
  125.             self.filename = self.dlg.GetFilename()
  126.             self.dirname = self.dlg.GetDirectory()
  127.             self.inputTxtThree.SetValue('%s\\%s' % (self.dirname, self.filename))
  128.         self.dlg.Destroy()
  129.  
  130.     def OnClearInv(self, event):
  131.         """ Clear Inventory Field. """
  132.         self.inputTxtOne.SetValue('Click Browse...')
  133.  
  134.     def OnClearSales(self, event):
  135.         """ Clear Sales Field. """
  136.         self.inputTxtTwo.SetValue('Click Browse...')
  137.  
  138.     def OnClearMeta(self, event):
  139.         """ Clear Meta Data Field. """
  140.  
  141.     def OnClearAll(self, event):
  142.         self.inputTxtOne.SetValue('Click Browse...')
  143.         self.inputTxtTwo.SetValue('Click Browse...')
  144.         self.inputTxtThree.SetValue('Click Browse...')
  145.  
  146.     def OnRun(self, event):
  147.         EW.clearVariables()
  148.         cdlg.showInfoDlg('Processing will begin when you click OK.\nPlease wait while the data is processed.', 'Information')
  149.         if self.inputTxtOne.GetValue() != 'Click Browse...' and self.inputTxtTwo.GetValue() != 'Click Browse...' and self.inputTxtThree.GetValue() != 'Click Browse...':
  150.             EW.parseOne(self.inputTxtOne.GetValue())
  151.             EW.parseTwo(self.inputTxtTwo.GetValue())
  152.             EW.parseThree(self.inputTxtThree.GetValue())
  153.             EW.prepareOutput()
  154.             EW.finalizeOutput()
  155.             pTwo.invOutput = EW.dataVars.invOutput
  156.             pThree.salesOutput = EW.dataVars.salesOutput
  157.        
  158.         else:
  159.             cdlg.showErrorDlg('Error loading one of the files. \n Please ensure you have filled in all three file selections.', 'Error')
  160.  
  161. #----------------------------------------------------------------------
  162. if __name__ == '__main__':
  163.     print('File file is not meant to be run as a stand alone application.')
  164.     print('  Please try again by running the main program.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement