class QSpacer(WidgetBase): type = "qx.ui.core.Spacer" known_simple_props = { "sizeHint": { "width": SimpleProp("setWidth", il.primitive.DecimalInteger, 0), "height": SimpleProp("setHeight", il.primitive.DecimalInteger, 0), }, }
class QAbstractItemView(WidgetBase): add_function_name = 'add' known_simple_props = { "selectionMode": SimpleProp("setSelectionMode", EnumSelectionMode), } def _handle_item(self, elt): item = self.Item(elt) item.set_parent(self) self.children.append(item) def _compile_children(self, dialect, ret): for c in self.children: c.compile(dialect, ret) args = [il.primitive.FunctionCall("this.create_%s" % c.name)] add_child = il.primitive.FunctionCall( 'retval.%s' % self.add_function_name, args) self.factory_function.add_statement(add_child) def compile(self, dialect, ret): WidgetBase.compile(self, dialect, ret) self._compile_children(dialect, ret) def _init_before_parse(self): self.tag_handlers['item'] = self._handle_item
class QPushButton(WidgetBase): type = "qx.ui.form.Button" known_simple_props = { "text": SimpleProp("setLabel", il.primitive.TranslatableString, ""), "checked": SimpleProp("setValue", il.primitive.Boolean, ""), } def __init__(self, *args, **kwargs): WidgetBase.__init__(self, *args, **kwargs) self.ver_stretch_pol = 'Fixed' self.hor_stretch_pol = 'Fixed' def _handle_checkable(self, elt): if elt.find('bool').text == 'true': self.type = 'qx.ui.form.ToggleButton' known_complex_props = {"checkable": _handle_checkable}
class QGroupBox(Base): type = "qx.ui.groupbox.GroupBox" known_simple_props = { "title": SimpleProp("setLegend", il.primitive.TranslatableString), } layout_in_ctor = False def __init__(self, elt, name=None): self.layout_properties = None Base.__init__(self, elt, name)
class TabPage(Base): type = "qx.ui.tabview.Page" layout_in_ctor = False known_simple_props = { "title": SimpleProp("setLabel", il.primitive.TranslatableString), } def __init__(self, elt, name=None): self.layout_properties = None Base.__init__(self, elt, name)
class QLabel(WidgetBase): type = "qx.ui.basic.Label" known_simple_props = { "text": SimpleProp("setValue", il.primitive.TranslatableString, ""), } def __init__(self, *args, **kwargs): WidgetBase.__init__(self, *args, **kwargs) self.ver_stretch_pol = 'Fixed' self.hor_stretch_pol = 'Fixed'
class ToolBarButton(obj.Base): type = "qx.ui.toolbar.Button" known_simple_props = { "title": SimpleProp("setLabel", il.primitive.TranslatableString, ""), } def __init__(self, elt, name=None, action=None): obj.Base.__init__(self, elt, name) if action and action.checkable: self.type = 'qx.ui.toolbar.CheckBox' self.icons.base = action.icons.base
def _compile_geometry(self, dialect, ret): if not self._compile_simple_prop(SimpleProp("setMargin", il.primitive.DecimalInteger, 0), self.__margin): self._compile_simple_prop(SimpleProp("setMarginTop", il.primitive.DecimalInteger, 0), self.__margin_t) self._compile_simple_prop(SimpleProp("setMarginLeft", il.primitive.DecimalInteger, 0), self.__margin_l) self._compile_simple_prop(SimpleProp("setMarginRight", il.primitive.DecimalInteger, 0), self.__margin_r) self._compile_simple_prop(SimpleProp("setMarginBottom", il.primitive.DecimalInteger, 0), self.__margin_b) self._compile_simple_prop(SimpleProp("setMinWidth", il.primitive.DecimalInteger, 0), self.__min_width) self._compile_simple_prop(SimpleProp("setMinHeight", il.primitive.DecimalInteger, 0), self.__min_height) xml_false = etree.fromstring("<bool>false</bool>") if self.hor_stretch_pol == "Fixed": self._compile_simple_prop(SimpleProp("setAllowGrowX", il.primitive.Boolean), xml_false) if self.ver_stretch_pol == "Fixed": self._compile_simple_prop(SimpleProp("setAllowGrowY", il.primitive.Boolean), xml_false)
class QSpinBox(WidgetBase): type = "qx.ui.form.Spinner" ver_stretch_pol = "Fixed" known_simple_props = { "value": SimpleProp("setValue", il.primitive.DecimalInteger), "maximum": SimpleProp("setMaximum", il.primitive.DecimalInteger), "minimum": SimpleProp("setMinimum", il.primitive.DecimalInteger), "singleStep": SimpleProp("setSingleStep", il.primitive.DecimalInteger), } def __init__(self, *args, **kwargs): WidgetBase.__init__(self, *args, **kwargs) self.ver_stretch_pol = 'Fixed' def _compile_instantiation(self, dialect, ret): WidgetBase._compile_instantiation(self, dialect, ret) self.instantiation.right.args.append( il.primitive.ObjectReference("-Number.MAX_VALUE")) self.instantiation.right.args.append(il.primitive.ObjectReference("0")) self.instantiation.right.args.append( il.primitive.ObjectReference("Number.MAX_VALUE"))
class MenuButton(container.WithoutLayout): type = "qx.ui.menu.Button" add_function = "setMenu" known_simple_props = { "title": SimpleProp("setLabel", il.primitive.TranslatableString, ""), } def __init__(self, elt, name=None, action=None): self.menu = None container.WithoutLayout.__init__(self, elt, name) def _init_before_parse(self): container.WithoutLayout._init_before_parse(self) self.tag_handlers['addaction'] = self._handle_addaction_tag def _handle_addaction_tag(self, elt): if self.menu == None: self.menu = QMenu(None, "%s_implicit_menu" % self.name) self.menu._handle_addaction_tag(elt) def _compile_sub_menu(self, dialect, ret): set_menu = il.primitive.FunctionCall( 'retval.setMenu', [il.primitive.FunctionCall("this.create_%s" % self.menu.name)]) self.factory_function.add_statement(set_menu) def compile(self, dialect, ret): container.WithoutLayout.compile(self, dialect, ret) if self.menu != None: self.menu.compile(dialect, ret) self._compile_sub_menu(dialect, ret) def add_child(self, instance): if self.menu == None: self.menu = QMenu(None, "%s_implicit_menu" % self.name) if instance.name == "separator": raise Exception( "As there is no way to tell a non-leaf menu item " "named 'separator' from a real separator, you are not allowed " "to add a menu item named 'separator'. Sorry.") self.menu.add_child_action(instance)
class QRadioButton(WidgetBase): type = "qx.ui.form.RadioButton" known_simple_props = { "text": SimpleProp("setLabel", il.primitive.TranslatableString), "checked": SimpleProp("setValue", il.primitive.Boolean), }
class MGeometryProperties(object): hor_stretch_pol = "Expanding" ver_stretch_pol = "Expanding" hor_stretch_coef = 1 ver_stretch_coef = 1 def __init__(self): self.__margin_t = etree.fromstring("<number>1</number>") self.__margin_b = etree.fromstring("<number>1</number>") self.__margin_l = etree.fromstring("<number>1</number>") self.__margin_r = etree.fromstring("<number>1</number>") self.__margin = etree.fromstring("<number>1</number>") self.__min_width = etree.fromstring("<number>0</number>") self.__min_height = etree.fromstring("<number>0</number>") def get_geometry_top(self): if "geometry.y" in self.simple_prop_data: return int(self.simple_prop_data["geometry.y"].text) else: return 0 geometry_top = property(get_geometry_top) def get_geometry_left(self): if "geometry.x" in self.simple_prop_data: return int(self.simple_prop_data["geometry.x"].text) else: return 0 geometry_left = property(get_geometry_left) def __handle_size_policy(self, elt): if elt[0].tag == 'sizepolicy': tmp = self._decode_nested_prop(elt[0]) self.hor_stretch_pol = elt[0].attrib['hsizetype'] self.hor_stretch_coef = int(tmp['horstretch'].text) self.ver_stretch_pol = elt[0].attrib['vsizetype'] self.ver_stretch_coef = int(tmp['verstretch'].text) if not self.hor_stretch_pol in ("Fixed", "Minimum"): if self.hor_stretch_coef == 0: self.hor_stretch_coef = 1 if not self.ver_stretch_pol in ("Fixed", "Minimum"): if self.ver_stretch_coef == 0: self.ver_stretch_coef = 1 else: jsqt.debug_print("\t\t", "WARNING: property 'sizePolicy' doesn't " "have a 'sizepolicy' tag") # # hacking around qooxdoo bug 3075 # http://bugzilla.qooxdoo.org/show_bug.cgi?id=3075 # def __handle_minimum_size(self, elt): if elt[0].tag == 'size': tmp = {} for e in elt[0]: tmp[e.tag]=e self.__min_width = tmp['width'] self.__min_height = tmp['height'] self.simple_prop_data['geometry.width'] = self.__min_width self.simple_prop_data['geometry.height'] = self.__min_height else: jsqt.debug_print("\t\t", "WARNING: property 'minimumSize' doesn't " "have a 'size' tag") def _compile_geometry(self, dialect, ret): if not self._compile_simple_prop(SimpleProp("setMargin", il.primitive.DecimalInteger, 0), self.__margin): self._compile_simple_prop(SimpleProp("setMarginTop", il.primitive.DecimalInteger, 0), self.__margin_t) self._compile_simple_prop(SimpleProp("setMarginLeft", il.primitive.DecimalInteger, 0), self.__margin_l) self._compile_simple_prop(SimpleProp("setMarginRight", il.primitive.DecimalInteger, 0), self.__margin_r) self._compile_simple_prop(SimpleProp("setMarginBottom", il.primitive.DecimalInteger, 0), self.__margin_b) self._compile_simple_prop(SimpleProp("setMinWidth", il.primitive.DecimalInteger, 0), self.__min_width) self._compile_simple_prop(SimpleProp("setMinHeight", il.primitive.DecimalInteger, 0), self.__min_height) xml_false = etree.fromstring("<bool>false</bool>") if self.hor_stretch_pol == "Fixed": self._compile_simple_prop(SimpleProp("setAllowGrowX", il.primitive.Boolean), xml_false) if self.ver_stretch_pol == "Fixed": self._compile_simple_prop(SimpleProp("setAllowGrowY", il.primitive.Boolean), xml_false) known_simple_props = { "geometry": { "x": SimpleProp("", il.primitive.DecimalInteger, 0), "y": SimpleProp("", il.primitive.DecimalInteger, 0), "width": SimpleProp("setWidth", il.primitive.DecimalInteger, 0), "height": SimpleProp("setHeight", il.primitive.DecimalInteger, 0), }, "maximumSize": { "width": SimpleProp("setMaxWidth", il.primitive.DecimalInteger, 16777215), "height": SimpleProp("setMaxHeight", il.primitive.DecimalInteger, 16777215), } } known_complex_props = { "sizePolicy": __handle_size_policy, "minimumSize": __handle_minimum_size, }