main.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import sys, string, os
  2. from Tkinter import *
  3. import steps
  4. Plugins = sys.argv[1]
  5. print Plugins
  6. pluginList = Plugins.split(':')
  7. maxStep = 2
  8. curStep = 1
  9. stepList = []
  10. # functions
  11. # show step on the num index
  12. def showStep(num):
  13. global stepList
  14. stepNum = len(stepList)
  15. if num >= stepNum or num <= 0 :
  16. pass
  17. i = 0
  18. while i < stepNum:
  19. if i == num:
  20. stepList[i].stepFrame.pack(fill=BOTH, anchor='nw')
  21. else:
  22. stepList[i].stepFrame.pack_forget()
  23. i += 1
  24. # update the pre & next buttons status
  25. def updateBtnState():
  26. global curStep
  27. global btnNextStep
  28. global btnPreStep
  29. if curStep == 1:
  30. btnPreStep['state'] = DISABLED
  31. btnNextStep['state'] = NORMAL
  32. btnNextStep['text'] = 'Next'
  33. elif curStep == maxStep:
  34. btnPreStep['state'] = NORMAL
  35. btnNextStep['state'] = NORMAL
  36. btnNextStep['text'] = 'Finish'
  37. else:
  38. btnPreStep['state'] = NORMAL
  39. btnNextStep['state'] = NORMAL
  40. btnNextStep['text'] = 'Next'
  41. # next button clicked
  42. def nextStep():
  43. if btnNextStep['text'] == 'close':
  44. root.quit()
  45. return
  46. global curStep
  47. nowStepObj = stepList[curStep - 1]
  48. bRet = nowStepObj.checkStep()
  49. if bRet != None:
  50. stepError['text'] = bRet
  51. return
  52. else:
  53. stepError['text'] = ''
  54. if curStep < maxStep:
  55. curStep += 1
  56. showStep(curStep - 1)
  57. updateBtnState()
  58. elif curStep == maxStep:
  59. # disable buttons when process
  60. btnPreStep['state'] = DISABLED
  61. btnNextStep['state'] = DISABLED
  62. # get user input arguments
  63. projPath = stepList[0].getPath()
  64. plugins = stepList[1].getSelectedPlugins()
  65. strPlugins = ''
  66. i = 0
  67. while i < len(plugins):
  68. strPlugins += "plugins/"
  69. strPlugins += plugins[i]
  70. if i != (len(plugins) - 1):
  71. strPlugins += ':'
  72. i += 1
  73. # process shell script to modify the game project
  74. ret = os.system('bash ./toolsForGame/addPluginForGame.sh ' + projPath + ' ' + strPlugins)
  75. if ret != 0:
  76. # enable buttons after process
  77. btnPreStep['state'] = NORMAL
  78. btnNextStep['state'] = NORMAL
  79. stepError['text'] = 'Error during process'
  80. else:
  81. # enable next button & change text to close
  82. btnNextStep['state'] = NORMAL
  83. btnNextStep['text'] = 'close'
  84. stepError['text'] = 'Process Successful!'
  85. # pre button clicked
  86. def preStep():
  87. global curStep
  88. global stepError
  89. stepError['text'] = ''
  90. if curStep > 1:
  91. curStep -= 1
  92. showStep(curStep - 1)
  93. updateBtnState()
  94. # init root view
  95. root = Tk()
  96. root.title('Plugin-x Integration Guide')
  97. root.geometry("600x400")
  98. rootFrame = Frame(root)
  99. rootFrame.pack(fill=BOTH)
  100. # steps view
  101. MyStep1 = steps.step1()
  102. MyStep1.initStep(rootFrame)
  103. MyStep2 = steps.step2()
  104. MyStep2.initStep(rootFrame, pluginList)
  105. stepList.append(MyStep1)
  106. stepList.append(MyStep2)
  107. MyStep1.stepFrame.pack(fill=BOTH, anchor='nw')
  108. # add step error message
  109. controlFrame = Frame(root)
  110. controlFrame.pack(side=BOTTOM, fill=X, anchor='s')
  111. stepError = Label(controlFrame)
  112. stepError.pack(side=LEFT, padx=30)
  113. # add step button
  114. btnNextStep = Button(controlFrame, text='Next', command=nextStep)
  115. btnPreStep = Button(controlFrame, text='Back', command=preStep, state=DISABLED)
  116. btnNextStep.pack(side=RIGHT, padx=30)
  117. btnPreStep.pack(side=RIGHT)
  118. root.mainloop()