__init__.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. from gi.repository import Gtk
  2. class Method:
  3. def run(self, files, output, full_width, full_height):
  4. raise NotImplementedError()
  5. def stack(self, files):
  6. raise NotImplementedError()
  7. def __init__(self):
  8. self.id = ""
  9. self.name = ""
  10. self.properties = []
  11. # Let the tool set values
  12. self.on_init()
  13. self.props = {}
  14. for property in self.properties:
  15. self.props[property.id] = property
  16. # Create widget for tool
  17. self.widget = Gtk.Grid()
  18. self.widget.set_column_spacing(8)
  19. self.widget.set_row_spacing(6)
  20. self.widget.set_halign(Gtk.Align.FILL)
  21. self.widget.set_hexpand(True)
  22. vpos = 0
  23. for property in self.properties:
  24. # Create Header
  25. if(property.type == "Header"):
  26. header = Gtk.HBox()
  27. header.set_margin_top(6)
  28. if(vpos != 0):
  29. # Add a Separator
  30. separator = Gtk.Separator()
  31. separator.set_margin_top(6)
  32. separator.show()
  33. self.widget.attach(separator, 0, vpos, 3, 1)
  34. vpos += 1
  35. title = Gtk.Label()
  36. title.set_halign(Gtk.Align.START)
  37. if(property.is_subheading):
  38. title.set_markup("<i>%s</i>" % property.name)
  39. else:
  40. title.set_markup("<b>%s</b>" % property.name)
  41. header.add(title)
  42. self.widget.attach(header, 0, vpos, 3, 1)
  43. # Create Combo
  44. elif(property.type == "Combo"):
  45. label = Gtk.Label()
  46. label.set_halign(Gtk.Align.END)
  47. label.set_justify(Gtk.Justification.RIGHT)
  48. label.set_text(property.name)
  49. self.widget.attach(label, 0, vpos, 1, 1)
  50. combo = Gtk.ComboBoxText()
  51. combo.set_hexpand(True)
  52. self.widget.attach(combo, 1, vpos, 1, 1)
  53. for option in property.options:
  54. combo.append_text(option)
  55. property.set_widget(combo)
  56. # Create Spin
  57. elif (property.type == "Spin"):
  58. label = Gtk.Label()
  59. label.set_halign(Gtk.Align.END)
  60. label.set_justify(Gtk.Justification.RIGHT)
  61. label.set_text(property.name)
  62. self.widget.attach(label, 0, vpos, 1, 1)
  63. adjustment = Gtk.Adjustment()
  64. adjustment.set_lower(property.min)
  65. adjustment.set_upper(property.max)
  66. adjustment.set_step_increment((property.max - property.min) / 100)
  67. property.set_widget(adjustment)
  68. spin = Gtk.SpinButton()
  69. spin.set_adjustment(adjustment)
  70. spin.set_hexpand(True)
  71. spin.set_digits(3)
  72. property.ui_widget = spin
  73. self.widget.attach(spin, 1, vpos, 1, 1)
  74. # Create Toggle
  75. elif(property.type == "Toggle"):
  76. label = Gtk.Label()
  77. label.set_halign(Gtk.Align.END)
  78. label.set_justify(Gtk.Justification.RIGHT)
  79. label.set_text(property.name)
  80. self.widget.attach(label, 0, vpos, 1, 1)
  81. toggle = Gtk.ToggleButton()
  82. toggle.set_label("Enable")
  83. toggle.set_hexpand(True)
  84. self.widget.attach(toggle, 1, vpos, 1, 1)
  85. property.set_widget(toggle)
  86. # Create Slider
  87. elif (property.type == "Slider"):
  88. label = Gtk.Label()
  89. label.set_halign(Gtk.Align.END)
  90. label.set_justify(Gtk.Justification.RIGHT)
  91. label.set_text(property.name)
  92. self.widget.attach(label, 0, vpos, 1, 1)
  93. adjustment = Gtk.Adjustment()
  94. adjustment.set_lower(property.min)
  95. adjustment.set_upper(property.max)
  96. adjustment.set_step_increment((property.max - property.min)/100)
  97. property.set_widget(adjustment)
  98. slider = Gtk.Scale()
  99. slider.set_adjustment(adjustment)
  100. slider.set_digits(2)
  101. slider.set_hexpand(True)
  102. slider.set_value_pos(Gtk.PositionType.RIGHT)
  103. property.ui_widget = slider
  104. self.widget.attach(slider, 1, vpos, 1, 1)
  105. if(property.type != "Header"):
  106. # Create reset button
  107. icon = Gtk.Image()
  108. icon.set_from_icon_name("edit-clear-symbolic", Gtk.IconSize.BUTTON)
  109. reset_button = Gtk.Button()
  110. reset_button.set_image(icon)
  111. reset_button.connect("clicked", property.reset_value)
  112. property.reset_button = reset_button
  113. self.widget.attach(reset_button, 2, vpos, 1, 1)
  114. vpos += 1
  115. separator = Gtk.Separator()
  116. separator.set_margin_top(6)
  117. separator.show()
  118. self.widget.attach(separator, 0, vpos, 3, 1)
  119. self.widget.show_all()
  120. def on_init(self):
  121. raise NotImplementedError()