/startconfig.py

https://github.com/schoeke/navigationtask · Python · 153 lines · 103 code · 37 blank · 13 comment · 16 complexity · 0c16fbb16b02af89ccff29043e5055ab MD5 · raw file

  1. #!/usr/bin/python
  2. # File: project.py
  3. # Author: Nathan Tarr
  4. import wx
  5. from xml.dom import minidom
  6. exitstatus = 0
  7. class ExperimentConfig(wx.Frame):
  8. """
  9. """
  10. def __init__(self, parent, id, title):
  11. """
  12. """
  13. wx.Frame.__init__(self, parent, id, title, size=(300, 250))
  14. pnl = wx.Panel(self, -1)
  15. vbox = wx.BoxSizer(wx.VERTICAL)
  16. hbox1 = wx.BoxSizer(wx.HORIZONTAL)
  17. label = wx.StaticText(pnl, -1, 'Name:')
  18. self.text = wx.TextCtrl(pnl, -1)
  19. hbox1.Add(label, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 10)
  20. hbox1.Add(self.text, 1)
  21. vbox.Add(hbox1, 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 10)
  22. vbox.Add((-1, 10))
  23. hbox2 = wx.BoxSizer(wx.HORIZONTAL)
  24. label2 = wx.StaticText(pnl, -1, 'Supervisor:')
  25. self.text2 = wx.TextCtrl(pnl, -1)
  26. hbox2.Add(label2, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 10)
  27. hbox2.Add(self.text2, 1)
  28. vbox.Add(hbox2, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
  29. vbox.Add((-1, 10))
  30. self.resolutions = [('640', '480'), ('800', '600'), ('1024', '768')]
  31. options = ['640x480', '800x600', '1024x768']
  32. hboxResL = wx.BoxSizer(wx.HORIZONTAL)
  33. label2 = wx.StaticText(pnl, -1, 'Resolution:')
  34. self.cmbBox = wx.ComboBox(pnl, -1, choices=options, style=wx.CB_READONLY)
  35. self.cmbBox.SetSelection(0)
  36. hboxResL.Add(label2, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 10)
  37. hboxResL.Add(self.cmbBox, 1)
  38. vbox.Add(hboxResL, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
  39. vbox.Add((-1, 10))
  40. hboxFullScr = wx.BoxSizer(wx.HORIZONTAL)
  41. self.chkFullScr = wx.CheckBox(pnl, -1, 'Fullscreen?')
  42. self.chkFullScr.SetValue(True)
  43. hboxFullScr.Add(self.chkFullScr, 0)
  44. vbox.Add(hboxFullScr, 0, wx.ALIGN_LEFT | wx.LEFT | wx.RIGHT, 10)
  45. vbox.Add((-1, 10))
  46. hboxOrder = wx.BoxSizer(wx.HORIZONTAL)
  47. self.chkOrder = wx.CheckBox(pnl, -1, 'Swap visible landmark group?')
  48. self.chkOrder.SetValue(False)
  49. hboxOrder.Add(self.chkOrder, 0)
  50. vbox.Add(hboxOrder, 0, wx.ALIGN_LEFT | wx.LEFT | wx.RIGHT, 10)
  51. vbox.Add((-1, 30))
  52. hboxBttn = wx.BoxSizer(wx.HORIZONTAL)
  53. btn1 = wx.Button(pnl, -1, 'Ok')
  54. btn1.Bind(wx.EVT_BUTTON, self.OnClickOkay)
  55. btn2 = wx.Button(pnl, -1, 'Cancel')
  56. btn2.Bind(wx.EVT_BUTTON, self.OnClickCancel)
  57. hboxBttn.Add(btn1, 0, 0)
  58. hboxBttn.Add(btn2, 0, 0)
  59. vbox.Add(hboxBttn, 0, wx.ALIGN_RIGHT, 10)
  60. pnl.SetSizer(vbox)
  61. self.Centre()
  62. self.Show(True)
  63. def OnClickOkay(self, event):
  64. """
  65. """
  66. global exitstatus
  67. if not self.text.IsEmpty() and not self.text2.IsEmpty():
  68. name = self.text.GetValue()
  69. supervisor = self.text2.GetValue()
  70. fullscreen = 'False'
  71. if self.chkFullScr.GetValue():
  72. fullscreen = 'True'
  73. resIdx = self.cmbBox.GetCurrentSelection()
  74. res = self.resolutions[resIdx]
  75. swaporder = 'False'
  76. if self.chkOrder.GetValue():
  77. swaporder = 'True'
  78. xmldoc = minidom.parse("startconfig.xml")
  79. subjectTags = xmldoc.getElementsByTagName("name")
  80. if len(subjectTags) > 0 and subjectTags[0].hasChildNodes() == True:
  81. subjectTags[0].firstChild.replaceWholeText(name)
  82. subjectTags = xmldoc.getElementsByTagName("supervisor")
  83. if len(subjectTags) > 0 and subjectTags[0].hasChildNodes() == True:
  84. subjectTags[0].firstChild.replaceWholeText(supervisor)
  85. subjectTags = xmldoc.getElementsByTagName("fullscreen")
  86. if len(subjectTags) > 0 and subjectTags[0].hasChildNodes() == True:
  87. subjectTags[0].firstChild.replaceWholeText(fullscreen)
  88. subjectTags = xmldoc.getElementsByTagName("resolutionwidth")
  89. if len(subjectTags) > 0 and subjectTags[0].hasChildNodes() == True:
  90. subjectTags[0].firstChild.replaceWholeText(res[0])
  91. subjectTags = xmldoc.getElementsByTagName("resolutionheight")
  92. if len(subjectTags) > 0 and subjectTags[0].hasChildNodes() == True:
  93. subjectTags[0].firstChild.replaceWholeText(res[1])
  94. subjectTags = xmldoc.getElementsByTagName("orderswapped")
  95. if len(subjectTags) > 0 and subjectTags[0].hasChildNodes() == True:
  96. subjectTags[0].firstChild.replaceWholeText(swaporder)
  97. fHandle = open("startconfig.xml", 'w')
  98. fHandle.truncate(0)
  99. fHandle.write( xmldoc.toprettyxml(indent='', newl='') )
  100. fHandle.close()
  101. exitstatus = 0
  102. self.Destroy()
  103. def OnClickCancel(self, event):
  104. """
  105. """
  106. global exitstatus
  107. exitstatus = 1
  108. self.Destroy()
  109. def GetExitStatus():
  110. """
  111. """
  112. return self.exitstatus
  113. app = wx.App()
  114. win = ExperimentConfig(None, -1, 'Experiment Configuration')
  115. app.MainLoop()
  116. exit(exitstatus)