Exemple #1
0
    def set_kwargs(self, code):
        """Sets widget from kwargs string

        Parameters
        ----------
        code: String
        \tCode representation of kwargs value

        """

        kwargs = {}

        kwarglist = list(parse_dict_strings(code[1:-1]))

        for kwarg, val in zip(kwarglist[::2], kwarglist[1::2]):
            kwargs[unquote_string(kwarg)] = val

        for key in kwargs:
            if key == "color":
                color = code2color(kwargs[key])
                self.colorselect.SetValue(color)
                self.colorselect.SetOwnForegroundColour(color)

            elif key == "fontname":
                self.font_face = unquote_string(kwargs[key])

                if self.chosen_font is None:
                    self.chosen_font = get_default_font()
                self.chosen_font.SetFaceName(self.font_face)

            elif key == "fontsize":
                if kwargs[key]:
                    self.font_size = int(kwargs[key])
                else:
                    self.font_size = get_default_font().GetPointSize()

                if self.chosen_font is None:
                    self.chosen_font = get_default_font()

                self.chosen_font.SetPointSize(self.font_size)

            elif key == "fontstyle":
                self.font_style = \
                    self.style_mpl2wx[unquote_string(kwargs[key])]

                if self.chosen_font is None:
                    self.chosen_font = get_default_font()

                self.chosen_font.SetStyle(self.font_style)

            elif key == "fontweight":
                self.font_weight = \
                    self.weight_mpl2wx[unquote_string(kwargs[key])]

                if self.chosen_font is None:
                    self.chosen_font = get_default_font()

                self.chosen_font.SetWeight(self.font_weight)
Exemple #2
0
    def set_kwargs(self, code):
        """Sets widget from kwargs string

        Parameters
        ----------
        code: String
        \tCode representation of kwargs value

        """

        kwargs = {}

        kwarglist = list(parse_dict_strings(code[1:-1]))

        for kwarg, val in zip(kwarglist[::2], kwarglist[1::2]):
            kwargs[unquote_string(kwarg)] = val

        for key in kwargs:
            if key == "direction":
                self.attrs[key] = unquote_string(kwargs[key])
                label = self.choice_param2label[self.attrs[key]]
                label_list = self.direction_choicectrl.Items
                self.direction_choicectrl.SetSelection(label_list.index(label))

            elif key == "pad":
                self.attrs[key] = int(kwargs[key])
                self.pad_intctrl.SetValue(self.attrs[key])

            elif key in ["top", "right"]:
                self.attrs[key] = (not kwargs[key] == "False")
                if self.attrs[key]:
                    self.sec_checkboxctrl.Set3StateValue(wx.CHK_CHECKED)
                else:
                    self.sec_checkboxctrl.Set3StateValue(wx.CHK_UNCHECKED)

            elif key == "labelsize":
                self.attrs[key] = int(kwargs[key])
                self.labelsize_intctrl.SetValue(self.attrs[key])
Exemple #3
0
def test_unquote_string(code, res):
    """Unit test for unquote_string"""

    assert unquote_string(code) == res