Pass a string to a class

Hello,

I have an existing class from a sample python file which came with my led-matrix.
This is the code:

class RunText(SampleBase):
    def __init__(self, *args, **kwargs):
        super(RunText, self).__init__(*args, **kwargs)
        self.parser.add_argument("-t", "--text", help="The text to scroll on the RGB LED panel", default="Hello world!")

    def run(self):
        offscreen_canvas = self.matrix.CreateFrameCanvas()
        font = graphics.Font()
        font.LoadFont("../../../fonts/7x13.bdf")
        textColor = graphics.Color(255, 255, 0)
        pos = offscreen_canvas.width
        my_text = self.args.text

        while True:
            offscreen_canvas.Clear()
            len = graphics.DrawText(offscreen_canvas, font, pos, 10, textColor, my_text)
            pos -= 1
            if (pos + len < 0):
                pos = offscreen_canvas.width

            time.sleep(0.05)
            offscreen_canvas = self.matrix.SwapOnVSync(offscreen_canvas)


# Main function
if __name__ == "__main__":
    run_text = RunText()
    if (not run_text.process()):
        run_text.print_help()

I created a separate Python file which makes a custom text for me.
This text changes every minute, so the led screen has to show every minute a different text.
How can I get my variable as the default text in RunText() class?
I understand it is a coding problem and I have not enough knowledge, but I hope to learn if I know how to search for the solution.

I hope somebody is able to bring me on the right path.

Thank you.

Hello,

welcome to the forum.

From the run method script, it appears that this is where the string is determined. Specifically:

my_text = self.args.text

You will have to modify the run method as shown here by adding a parameter to the method definition and modifying the my_text variable assignment:

    def run(self, my_string):  # add parameter to method definition
        offscreen_canvas = self.matrix.CreateFrameCanvas()
        font = graphics.Font()
        font.LoadFont("../../../fonts/7x13.bdf")
        textColor = graphics.Color(255, 255, 0)
        pos = offscreen_canvas.width
        my_text = my_string  # overriding the original asignment value
       .
       .
       .  # did not include the rest of the method script for brevity

Then, in your script, you can call the run method every minute with the my_string variable as the string argument:

run_text.run(my_string)  # call the method with your argument

Note that here, the variable my_string represents your string being passed in from the file that you created per this:

Give it a try and see if that works.

Thank you Paul,

I will give it a try tomorrow as I have to start working now.
I come back to you with the result.

Yvonne

Dear Paul,

Thank you so much for your help.
I succeeded to create the text on my led-matrix.
For the moment very simple, but I’m sure I can finish the program by now.

I’m very grateful for your help.

Kind regards,
Yvonne