Пример #1
0
class EditStaticText(ManagedBase, EditStylesMixin):
    "Class to handle wxStaticText objects"
    _PROPERTIES = ["Widget", "label", "style", "attribute"]
    PROPERTIES = ManagedBase.PROPERTIES + _PROPERTIES + ManagedBase.EXTRA_PROPERTIES
    ManagedBase.MOVE_PROPERTY(PROPERTIES, "attribute", "name")
    _PROPERTY_HELP ={"attribute":'Store instance as attribute of window class; e.g. self.label_1 = wx.StaticText(...)\n'
                                 'Without this, you can not access the label from your program.'}

    def __init__(self, name, parent, id, label, sizer, pos):
        ManagedBase.__init__(self, name, 'wxStaticText', parent, id, sizer, pos)
        EditStylesMixin.__init__(self)

        # initialise instance properties
        self.label     = np.TextProperty(label, multiline="grow")
        self.attribute = np.CheckBoxProperty(False, default_value=False)

    def create_widget(self):
        self.widget = wx.lib.stattext.GenStaticText(self.parent.widget, self.id, self.label)

    def properties_changed(self, modified):
        if not modified or "label" in modified:
            if self.widget:
                self.widget.SetLabel(self.label)
                self._set_widget_best_size()
            common.app_tree.refresh(self.node, refresh_label=True)

        EditStylesMixin.properties_changed(self, modified)
        ManagedBase.properties_changed(self, modified)
class EditStaticLine(ManagedBase, EditStylesMixin):
    "Class to handle wxStaticLine objects"
    _PROPERTIES = ["attribute"]
    PROPERTIES = ManagedBase.PROPERTIES + _PROPERTIES + ManagedBase.EXTRA_PROPERTIES
    PROPERTIES.remove("font")
    ManagedBase.MOVE_PROPERTY(PROPERTIES, "attribute", "name")
    _PROPERTY_LABELS = {"attribute":'Store as attribute'}
    _PROPERTY_HELP={"attribute":'Store instance as attribute of window class; e.g. self.line_1 = wx.wxStaticLine(...)\n'
                                'Without this, you can not access the line from your program.'}
    def __init__(self, name, parent, id, style, sizer, pos):
        ManagedBase.__init__(self, name, 'wxStaticLine', parent, id, sizer, pos)
        EditStylesMixin.__init__(self)

        # initialise instance properties
        self.attribute = np.CheckBoxProperty(False, default_value=False)
        if style: self.properties["style"].set(style)

    def create_widget(self):
        self.widget = wx.StaticLine(self.parent.widget, self.id, style=self.style)
        self.widget.Bind(wx.EVT_LEFT_DOWN, self.on_set_focus)

    def finish_widget_creation(self):
        ManagedBase.finish_widget_creation(self)
        self.sel_marker.Reparent(self.parent.widget)
        #del self.properties['font']

    def __getitem__(self, key):
        if key != 'font':
            return ManagedBase.__getitem__(self, key)
        return lambda: "", lambda v: None

    def properties_changed(self, modified=None):
        EditStylesMixin.properties_changed(self, modified)
        ManagedBase.properties_changed(self, modified)
Пример #3
0
class EditStaticText(ManagedBase, EditStylesMixin):
    "Class to handle wxStaticText objects"
    WX_CLASS = 'wxStaticText'
    _PROPERTIES = ["Widget", "label", "style", "attribute", "wrap"]
    PROPERTIES = ManagedBase.PROPERTIES + _PROPERTIES + ManagedBase.EXTRA_PROPERTIES
    ManagedBase.MOVE_PROPERTY(PROPERTIES, "attribute", "name")
    _PROPERTY_HELP = {
        "attribute":
        'Store instance as attribute of window class; e.g. self.label_1 = wx.StaticText(...)\n'
        'Without this, you can not access the label from your program.',
        "wrap":
        'Wrap text to at most the given width.\nThe lines will be broken at word boundaries.'
    }

    def __init__(self, name, parent, index, label):
        ManagedBase.__init__(self, name, parent, index)
        EditStylesMixin.__init__(self)

        # initialise instance properties
        self.label = np.TextProperty(label, multiline="grow")
        self.attribute = np.CheckBoxProperty(False, default_value=False)
        self.wrap = np.SpinPropertyD(100,
                                     val_range=(1, 100000),
                                     immediate=True,
                                     default_value=-1)

    def create_widget(self):
        # up to 0.8 GenStaticText was used; it seems that nowadays StaticText handles mouse events on gtk as well
        #self.widget = wx.lib.stattext.GenStaticText(self.parent_window.widget, wx.ID_ANY, self.label)
        self.widget = wx.StaticText(self.parent_window.widget,
                                    wx.ID_ANY,
                                    self.label,
                                    style=self.style)
        # self.wrap is now handled in finish_widget_creation

    def _properties_changed(self, modified, actions):
        if not modified or "label" in modified:
            if self.widget:
                p = self.properties["label"]
                if self.wrap != -1 or (p.previous_value and len(
                        p.previous_value) > len(self.label)):
                    # re-create as otherwise the size would not be reduced
                    actions.add("recreate2")
                    return
                self.widget.SetLabel(self.label)
                actions.add("layout")

        if (not modified or "wrap" in modified) and self.widget:
            actions.add(
                "recreate2"
            )  # calling .Wrap(self.wrap) would only work once and not set the size correctly
            return

        if modified and wx.Platform != "__WXMSW__":
            if "style" in modified or "font" in modified or "foreground" in modified:
                actions.add("recreate2")
                return

        EditStylesMixin._properties_changed(self, modified, actions)
        ManagedBase._properties_changed(self, modified, actions)
Пример #4
0
class EditStaticText(ManagedBase, EditStylesMixin):
    "Class to handle wxStaticText objects"
    WX_CLASS = 'wxStaticText'
    _PROPERTIES = ["Widget", "label", "style", "attribute", "wrap"]
    PROPERTIES = ManagedBase.PROPERTIES + _PROPERTIES + ManagedBase.EXTRA_PROPERTIES
    ManagedBase.MOVE_PROPERTY(PROPERTIES, "attribute", "name")
    _PROPERTY_HELP = {
        "attribute":
        'Store instance as attribute of window class; e.g. self.label_1 = wx.StaticText(...)\n'
        'Without this, you can not access the label from your program.',
        "wrap":
        'Wrap text to at most the given width.\nThe lines will be broken at word boundaries.'
    }

    def __init__(self, name, parent, label, pos):
        ManagedBase.__init__(self, name, 'wxStaticText', parent, pos)
        EditStylesMixin.__init__(self)

        # initialise instance properties
        self.label = np.TextProperty(label, multiline="grow")
        self.attribute = np.CheckBoxProperty(False, default_value=False)
        self.wrap = np.SpinPropertyD(100,
                                     val_range=(1, 100000),
                                     immediate=True,
                                     default_value=-1)

    def create_widget(self):
        # up to 0.8 GenStaticText was used; it seems that nowadays StaticText handles mouse events on gtk as well
        #self.widget = wx.lib.stattext.GenStaticText(self.parent_window.widget, self.id, self.label)
        self.widget = wx.StaticText(self.parent_window.widget, self.id,
                                    self.label)
        if self.wrap:
            self.widget.Wrap(self.wrap)

    def properties_changed(self, modified):
        if not modified or "label" in modified:
            if common.app_tree:
                common.app_tree.refresh(self, refresh_label=True)
            if self.widget:
                p = self.properties["label"]
                if self.wrap != -1 or (p.previous_value and len(
                        p.previous_value) > len(self.label)):
                    # re-create as otherwise the size would not be reduced
                    self.recreate_widget()
                    return
                self.widget.SetLabel(self.label)
                self._set_widget_best_size()

        if (not modified or "wrap" in modified) and self.widget:
            self.recreate_widget(
            )  # calling .Wrap(self.wrap) would only work once and not set the size correctly

            return

        EditStylesMixin.properties_changed(self, modified)
        ManagedBase.properties_changed(self, modified)
Пример #5
0
class EditHyperlinkCtrl(ManagedBase, EditStylesMixin):
    "Class to handle wxHyperlinkCtrl objects"
    WX_CLASS = "wxHyperlinkCtrl"
    _PROPERTIES = ["Widget", "label", "style", "url", "attribute"]
    PROPERTIES = ManagedBase.PROPERTIES + _PROPERTIES + ManagedBase.EXTRA_PROPERTIES
    ManagedBase.MOVE_PROPERTY(PROPERTIES, "attribute", "name")
    _PROPERTY_HELP = {
        'label':
        "Label of the hyperlink",
        'url':
        "URL associated with the given label",
        "attribute":
        'Store instance as attribute of window class; e.g. self.bitmap_1 = wx.wxStaticBitmap'
        '(...)\nWithout this, you can not access the bitmap from your program.'
    }

    def __init__(self, name, parent, label, pos):
        # Initialise parent classes
        ManagedBase.__init__(self, name, 'wxHyperlinkCtrl', parent, pos)
        EditStylesMixin.__init__(self)

        # initialise instance properties
        self.label = np.TextProperty(label, multiline=True)
        self.url = np.TextProperty("")
        self.attribute = np.CheckBoxProperty(False, default_value=False)

    def create_widget(self):
        self.widget = HyperlinkCtrl(self.parent_window.widget, self.id,
                                    self.label, self.url)

    def properties_changed(self, modified):
        if not modified or "label" in modified:
            if self.widget:
                self.widget.SetLabel(self.label)
                self._set_widget_best_size()
            if common.app_tree:
                common.app_tree.refresh(self,
                                        refresh_label=True,
                                        refresh_image=False)

        if not modified or "url" in modified:
            if self.widget:
                self.widget.SetURL(self.url)

        EditStylesMixin.properties_changed(self, modified)
        ManagedBase.properties_changed(self, modified)

    # handle compatibility:
    @decorators.memoize
    def wxname2attr(self, name):
        cn = self.codegen.get_class(self.codegen.cn(name))
        module = wx if compat.IS_CLASSIC else wx.adv
        return getattr(module, cn)
Пример #6
0
class EditStaticBitmap(ManagedBase, EditStylesMixin, BitmapMixin):
    "Class to handle wxStaticBitmap objects"
    update_widget_style = False
    _PROPERTIES = ["Widget", "bitmap", "attribute", "style"]
    PROPERTIES = ManagedBase.PROPERTIES + _PROPERTIES + ManagedBase.EXTRA_PROPERTIES
    ManagedBase.MOVE_PROPERTY(PROPERTIES, "attribute", "name")
    _PROPERTY_LABELS = {"attribute": 'Store as attribute'}
    _PROPERTY_HELP = {
        "attribute":
        'Store instance as attribute of window class; e.g. self.bitmap_1 = wx.wxStaticBitmap'
        '(...)\nWithout this, you can not access the bitmap from your program.',
        "bitmap":
        BitmapMixin.bitmap_tooltip_text,
    }

    def __init__(self, name, parent, id, bmp_file, sizer, pos):
        ManagedBase.__init__(self, name, 'wxStaticBitmap', parent, id, sizer,
                             pos)
        EditStylesMixin.__init__(self)

        # initialise instance properties
        filedialog_style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST  # for the following two properties
        self.bitmap = np.BitmapProperty(bmp_file, style=filedialog_style)
        self.attribute = np.CheckBoxProperty(False, default_value=False)

    def create_widget(self):
        bmp = self.get_preview_obj_bitmap()
        self.widget = wx.StaticBitmap(self.parent.widget, self.id, bmp)
        if wx.Platform == '__WXMSW__':

            def get_best_size():
                bmp = self.widget.GetBitmap()
                if bmp and bmp.IsOk():
                    return bmp.GetWidth(), bmp.GetHeight()
                return wx.StaticBitmap.GetBestSize(self.widget)

            self.widget.GetBestSize = get_best_size

    def properties_changed(self, modified=None):
        "update label (and size if label/stockitem have changed)"
        if not modified or "bitmap" in modified and self.widget:
            bmp = self.get_preview_obj_bitmap(self.bitmap)
            self.widget.SetBitmap(bmp)

            self._set_widget_best_size()

        EditStylesMixin.properties_changed(self, modified)
        ManagedBase.properties_changed(self, modified)
Пример #7
0
class EditStaticBitmap(BitmapMixin, ManagedBase, EditStylesMixin):
    "Class to handle wxStaticBitmap objects"
    recreate_on_style_change = True
    WX_CLASS = 'wxStaticBitmap'
    _PROPERTIES = ["Widget", "bitmap", "attribute", "style"]
    PROPERTIES = ManagedBase.PROPERTIES + _PROPERTIES + ManagedBase.EXTRA_PROPERTIES
    ManagedBase.MOVE_PROPERTY(PROPERTIES, "attribute", "name")
    _PROPERTY_LABELS = {"attribute": 'Store as attribute'}
    _PROPERTY_HELP = {
        "attribute":
        'Store instance as attribute of window class; e.g. self.bitmap_1 = wx.wxStaticBitmap'
        '(...)\nWithout this, you can not access the bitmap from your program.'
    }

    def __init__(self, name, parent, index, bmp_file):
        ManagedBase.__init__(self, name, parent, index)
        EditStylesMixin.__init__(self)

        # initialise instance properties
        self.bitmap = np.BitmapProperty(bmp_file)
        self.attribute = np.CheckBoxProperty(False, default_value=False)

    def create_widget(self):
        bmp = self.get_preview_obj_bitmap()
        self.widget = wx.StaticBitmap(self.parent_window.widget,
                                      wx.ID_ANY,
                                      bmp,
                                      style=self.style)
        if wx.Platform == '__WXMSW__':

            def get_best_size():
                bmp = self.widget.GetBitmap()
                if bmp and bmp.IsOk():
                    return bmp.GetWidth(), bmp.GetHeight()
                return wx.StaticBitmap.GetBestSize(self.widget)

            self.widget.GetBestSize = get_best_size

    def _properties_changed(self, modified, actions):
        "update label (and size if label/stockitem have changed)"
        if not modified or "bitmap" in modified and self.widget:
            bmp = self.get_preview_obj_bitmap(self.bitmap)
            self.widget.SetBitmap(bmp)
            if modified: actions.add("layout")

        EditStylesMixin._properties_changed(self, modified, actions)
        ManagedBase._properties_changed(self, modified, actions)