retrieve an extensions textbox input as a list?

Discussion about writing code for Inkscape.
draftman
Posts: 39
Joined: Sun Jan 25, 2015 5:29 am

retrieve an extensions textbox input as a list?

Postby draftman » Wed Jun 01, 2016 8:23 am

Is it possible to retrieve an extensions textbox input as a list?
Tried this and got this error ,( ValueError: invalid literal for int() with base 10: '6 , 2').

inx

Code: Select all

<param name=" List " type="string"  _gui-text=" List ">0</param>



py

Code: Select all

        self.OptionParser.add_option("--List",
                        action="store", type="string",
                        dest="List ", default="0",
                        help="i need it")

                width = [self.options.List]
                W = int(width[0]) * 22.5

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: retrieve an extensions textbox input as a list?

Postby Moini » Wed Jun 01, 2016 11:42 am

Well, you could either use two (or more) float boxes in your .inx file: good and safe, only useful if the number of inputs is limited (looks like you're asking for width and height, so ...)

or you could do
your_list = your_string.split(separator)

on the string you got (but if a user enters something weird, then it won't work): only useful if the number of list items is not bounded, because it's more or less error prone, so will need some good exception handling. See also: https://docs.python.org/2/library/stdty ... #str.split
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: retrieve an extensions textbox input as a list?

Postby Moini » Wed Jun 01, 2016 11:45 am

Or you might be looking for eval() or some json format. At least eval() is a 'dangerous' option, too, and you should have good error handling in place.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

draftman
Posts: 39
Joined: Sun Jan 25, 2015 5:29 am

Re: retrieve an extensions textbox input as a list?

Postby draftman » Thu Jun 02, 2016 3:38 am

Thanks, Moini.
I did not know about split. Looks very useful.
I'll have to give it a try and see how it works.

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: retrieve an extensions textbox input as a list?

Postby Moini » Thu Jun 02, 2016 6:38 am

Good luck, draftman!
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)


Return to “Programming”