How to use the guizero.utilities.error_format function in guizero

To help you get started, we’ve selected a few guizero examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lawsie / guizero / guizero / Text.py View on Github external
self.description = "[Text] object with text \"" + str(text) + "\""

        # Save some of the config
        self.current_size = size
        self.current_color = color
        self.current_font = font

        # Create a Tkinter String variable controlling the text within the label
        self.string_var = StringVar()
        self.string_var.set( str(text) )

        # Attempt to instantiate the object and raise an error if failed
        try:
            super().__init__(master)
        except AttributeError:
            utils.error_format( self.description + "\n" +
            "The first argument was a " + str(type(master)) +". First argument must be [App] or [Box]")

        # Initial config on setup       
        self.config(textvariable=self.string_var, fg=color, font=(font, size))
        
        # Pack or grid depending on parent
        utils.auto_pack(self, master, grid, align)
github lawsie / guizero / guizero / ListBox.py View on Github external
def _command_callback(self):
        if self._command:
            args_expected = utils.no_args_expected(self._command)
            if args_expected == 0:
                self._command()
            elif args_expected == 1:
                self._command(self.value)
            else:
                utils.error_format("ListBox command function must accept either 0 or 1 arguments.\nThe current command has {} arguments.".format(args_expected))
github lawsie / guizero / guizero / ButtonGroup.py View on Github external
# update radio buttons width
        for item in self._rbuttons:
            item.width = width

        # update radio buttons height
        if len(self._rbuttons) > 0:
            # work out the height of a button
            button_height = height
            
            if isinstance(height, int):
                if height % len(self._rbuttons) != 0:
                    # if the height doesnt divide by the number of radio buttons give a warning
                    button_height = int(round(height / len(self._rbuttons)))
                    new_height = button_height * len(self._rbuttons)
                    utils.error_format("ButtonGroup height '{}' doesn't divide by the number of buttons '{}' setting height to '{}'.".format(height, len(self._rbuttons), new_height))
                else:
                    button_height = int(height / len(self._rbuttons))
            
            for item in self._rbuttons:
                item.height = button_height

        super(ButtonGroup, self).resize(width, height)
github lawsie / guizero / guizero / event.py View on Github external
def _event_callback(self, tk_event):
        # the tk event has fired, run all the callbacks associated to this event
        for ref in self._callbacks.copy():
            callback = self._callbacks[ref]
            args_expected = utils.no_args_expected(callback)

            if args_expected == 0:
                callback()
            elif args_expected == 1:
                callback(EventData(self._widget, tk_event))
            else:
                utils.error_format("An event callback function must accept either 0 or 1 arguments.\nThe current callback has {} arguments.".format(args_expected))
github lawsie / guizero / guizero / tkmixins.py View on Github external
def _update_align(self, align):
        """
        Validates a widgets align property
        """
        self._align = None
        if align is not None:
            if align in ["top", "bottom", "left", "right"]:
                self._align = align
            else:
                utils.error_format("Invalid align value ('{}') for {}\nShould be: top, bottom, left or right".format(
                    align,
                    self.description
                ))
github lawsie / guizero / guizero / Combo.py View on Github external
def value(self, value):
        value = str(value)
        if not self._set_option(value):
            utils.error_format("Tried to set " + self.description + " to option \"" + str(value) + "\", which does not exist" )
github lawsie / guizero / guizero / base.py View on Github external
def _pack_widget(self, widget):
        pack_params={}

        if widget.width == "fill" and widget.height == "fill":
            pack_params["fill"] = BOTH
            pack_params["expand"] = YES
        elif widget.width == "fill":
            pack_params["fill"] = X
        elif widget.height == "fill":
            pack_params["fill"] = Y

        if widget.align is not None:
            if widget.align in ["top", "bottom", "left", "right"]:
                pack_params["side"] = widget.align
            else:
                utils.error_format("Invalid align value ('{}') for {}\nShould be: top, bottom, left or right".format(
                    widget.align,
                    widget.description
                ))

        # this is to cater for scenario's where the frame will not expand to fill the container
        # if aligned - tk weirdness.
        if pack_params.get("side") is None and pack_params.get("fill") == Y:
            pack_params["expand"] = YES

        if pack_params.get("side") in ["top", "bottom"] and pack_params.get("fill") == Y:
            pack_params["expand"] = YES

        if pack_params.get("side") in ["left", "right"] and pack_params.get("fill") == X:
            pack_params["expand"] = YES

        widget.tk.pack(**pack_params)
github lawsie / guizero / guizero / TextBox.py View on Github external
def _key_released(self, event):
        if self._command:
            args_expected = utils.no_args_expected(self._command)
            if args_expected == 0:
                self._command()
            elif args_expected == 1:
                self._command(event.key)
            else:
                utils.error_format("TextBox command function must accept either 0 or 1 arguments.\nThe current command has {} arguments.".format(args_expected))