python_gui.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import PySimpleGUI as sg
  2. import os.path
  3. # First the window layout in 2 columns
  4. def optiwae_gui(obj):
  5. file_list_column = [
  6. [
  7. sg.Text("Type Section"),
  8. sg.In(size=(25, 1), enable_events=True, key="-FOLDER-"),
  9. sg.FolderBrowse(),
  10. ],
  11. [
  12. sg.Listbox(
  13. values=[], enable_events=True, size=(40, 20), key="-FILE LIST-"
  14. )
  15. ],
  16. ]
  17. variables_viewer_column = [
  18. [sg.Text('x')],
  19. ]
  20. # ----- Full layout -----
  21. lines_of_variables_0 = []
  22. lines_of_variables_1 = []
  23. lines_of_variables_2 = []
  24. for count,(key, value) in enumerate(obj.items()):
  25. if count<= 10:
  26. lines_of_variables_0 += [[sg.Text(str(key) + '\n')]]
  27. if count >10:
  28. lines_of_variables_1+= [[sg.Text(str(key) +'\n')]]
  29. if count >20:
  30. lines_of_variables_2+= [[sg.Text(str(key) +'\n')]]
  31. layout = [
  32. # sg.Column(file_list_column),
  33. [sg.Text('Enter Changes', size=(15, 1)), sg.InputText()],
  34. [sg.Submit(), sg.Cancel()],
  35. sg.Frame(layout= lines_of_variables_0, title=''),
  36. sg.VSeperator(),
  37. sg.Frame(layout=lines_of_variables_1, title=''),
  38. sg.VSeperator(),
  39. sg.Frame(layout=lines_of_variables_2, title=''),
  40. ]
  41. layout = [layout]
  42. window = sg.Window("Variables Viewer", layout)
  43. list_of_commands = []
  44. while True:
  45. event, values = window.read()
  46. list_of_commands += [values[0]]
  47. if event == "Exit" or event == sg.WIN_CLOSED or event=='Cancel':
  48. window.close()
  49. break
  50. return list(set(list_of_commands))
  51. # if event == "-FOLDER-":
  52. #
  53. # folder = values["-FOLDER-"]
  54. #
  55. # try:
  56. #
  57. # # Get list of files in folder
  58. #
  59. # file_list = os.listdir(folder)
  60. #
  61. # except:
  62. #
  63. # file_list = []
  64. #
  65. # fnames = [
  66. #
  67. # f
  68. #
  69. # for f in file_list
  70. #
  71. # if os.path.isfile(os.path.join(folder, f))
  72. #
  73. # and f.lower().endswith((".png", ".gif"))
  74. #
  75. # ]
  76. #
  77. # window["-FILE LIST-"].update(fnames)
  78. # elif event == "-FILE LIST-": # A file was chosen from the listbox
  79. #
  80. # try:
  81. #
  82. # filename = os.path.join(
  83. #
  84. # values["-FOLDER-"], values["-FILE LIST-"][0]
  85. #
  86. # )
  87. #
  88. # window["-TOUT-"].update(filename)
  89. #
  90. # window["-IMAGE-"].update(filename=filename)
  91. #
  92. # except:
  93. #
  94. # pass
  95. if __name__ == '__main__':
  96. k= {'x' :5, 'y':6}
  97. optiwae_gui(k)