prompt_window.xml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <class name="PromptWindow">
  2. <relationships>
  3. <inheritance class="tk.Toplevel" priority="1"/>
  4. <inheritance class="SCCDWidget" priority="0"/>
  5. <association name="buttons" class="Button"/>
  6. <association name="parent" class="A"/>
  7. </relationships>
  8. <constructor>
  9. <parameter name="entries"/>
  10. <parameter name="options"/>
  11. <super class="tk.TopLevel"/>
  12. <super class="SCCDWidget"/>
  13. <body>
  14. print("Making prompt")
  15. print(entries)
  16. print(options)
  17. self.entries = {}
  18. self.frame = tk.Frame(self)
  19. counter = 0
  20. for k, v in entries.items():
  21. label = tk.Label(self.frame, text=k)
  22. if "\n" in v:
  23. entry = tk.Text(self.frame, **options.get(k, {}))
  24. entry.insert(tk.END, v.strip() if v is not None else "")
  25. else:
  26. entry = tk.Entry(self.frame, **options.get(k, {}))
  27. entry.insert(0, v if v is not None else "")
  28. label.grid(row=counter, column=0)
  29. entry.grid(row=counter, column=1)
  30. counter += 1
  31. self.entries[k] = entry
  32. self.frame.pack()
  33. </body>
  34. </constructor>
  35. <destructor>
  36. <body>
  37. self.destroy()
  38. </body>
  39. </destructor>
  40. <scxml initial="init">
  41. <state id="init" initial="init_button_OK">
  42. <state id="init_button_OK">
  43. <onentry>
  44. <raise event="create_instance" scope="cd">
  45. <parameter expr="'buttons'"/>
  46. <parameter expr="'Button'"/>
  47. <parameter expr="{'parent': self, 'visual': TextVisual('OK'), 'tooltip_text': 'Accept values', 'event_parameters': 'OK'}"/>
  48. </raise>
  49. </onentry>
  50. <transition event="instance_created" target="../wait_for_packing">
  51. <parameter name="association_name"/>
  52. <raise event="start_instance" scope="cd">
  53. <parameter expr="association_name"/>
  54. </raise>
  55. <script>
  56. self.button = association_name
  57. </script>
  58. </transition>
  59. </state>
  60. <state id="wait_for_packing">
  61. <transition event="tk_widget" target="../../root">
  62. <parameter name="tk_elem"/>
  63. <script>
  64. tk_elem.pack(fill=tk.X)
  65. </script>
  66. </transition>
  67. </state>
  68. </state>
  69. <state id="root">
  70. <transition event="button_pressed" cond="event_name == 'OK'" target="../closing">
  71. <parameter name="event_name"/>
  72. <script>
  73. results = {}
  74. for k, v in self.entries.items():
  75. try:
  76. results[k] = v.get()
  77. except:
  78. results[k] = v.get("1.0", tk.END)
  79. </script>
  80. <raise event="prompt_results" scope="narrow" target="'parent'">
  81. <parameter expr="results"/>
  82. </raise>
  83. </transition>
  84. <transition event="window-close" cond="ID == id(self)" target="../closing">
  85. <parameter name="ID"/>
  86. </transition>
  87. </state>
  88. <state id="closing">
  89. <onentry>
  90. <raise event="delete_instance" scope="cd">
  91. <parameter expr="self.button"/>
  92. </raise>
  93. </onentry>
  94. <transition event="instance_deleted" target="../close"/>
  95. </state>
  96. <state id="close">
  97. <onentry>
  98. <raise event="close_window" scope="narrow" target="'parent'"/>
  99. </onentry>
  100. </state>
  101. </scxml>
  102. </class>