Python3 documentation and advanced SWI stuff
Lauren Etc. (8147) 52 posts |
Hi, I’m playing around this week with porting some stuff I did in Python over to RISC, but I wanted to slap a Toolbox interface on it and yet I’m getting hung up on the platform-specific features which I’m having trouble finding much in the way of documentation for. The only guide for swi.swi() I could find is a one-line example in the release notes inside the app bundle using OS_Write0 or something, but I’m wondering how I would do a call like, say, this where I’m having to pass it an entire memory block (which would be defined with some kind of struct in C): DIM id_block% 32, msg_block% 4 My inclination was to use bytearrays for the blocks I’m trying to pass but it doesn’t like that at all and I just get a TypeError. I then tried some more baroque stuff like defining a class with ctypes fields in it but no good. I feel a bit stupid, but has anyone used swi.swi() in the Python3 port? Or is there more documentation I’m missing somewhere? By the way, I know there is a Toolbox module as well but a.) the demo code for that was having issues and I haven’t looked into it yet and b.) I’ll still likely need to do something like this regardless so I’m wondering how it works. Thanks! |
Andrew Conroy (370) 725 posts |
Did you find the StrongHelp manual included with Python3 Alpha 4? That goes into more detail about swi.swi and how to pass it a pointer to a block. Not sure why this isn’t included with the release version too. |
Lauren Etc. (8147) 52 posts |
> Did you find the StrongHelp manual included with Python3 Alpha 4? Thanks for the lead, I haven’t. I’ve actually been searching for a while now and can’t locate it, I found the 3.8a4 release on Github but didn’t see it there either. Does anyone have a link? I’ll keep searching in the meantime but so far I’m empty handed. |
John Rickman (71) 645 posts |
You might find this useful, but it comes with a warning. It is old,I don’t know how accurately it reflects the current toolbox swi and I can’t remember where it came from. |
Sprow (202) 1150 posts |
While this isn’t addressing your python question, I should say that that doesn’t look right for BBC BASIC. In particular the directory name in R4 is missing, more like
It’s also worth a mention that wimp_mask% and tbox_mask% are pointers to lists of words of Wimp or Toolbox reason codes rather than bitmasks (just guessing from the variable names here!). |
Andrew Conroy (370) 725 posts |
I can’t find it now either, so I’ve temporarily put a copy up here: http://www.owlart.co.uk/temp/Python38a4.zip Let me know once you’ve got it and I’ll take it down again. |
Lauren Etc. (8147) 52 posts |
I’ll take it with a grain of salt then, but this does look helpful.
I should have specified, for purposes of my question imagine my code example is correct ;)
Got it, thanks! On a cursory glance it looks like it has the info I need, hopefully. But the heatwave here has taken a few IQ points off me and might fry my Pi too, so I’ll examine it more later. Thanks again! But you should be good to take it down for now, I’ve got a copy saved. |
Mark Beerling (8582) 4 posts |
This looks like the right forum topic for me I’ve also been trying to convert some RISC OS C/C++ programs over to Python I’m having problems passing a string over to swi.swi when the string contains characters with the top bit set. for example ‘öüä’ & the Euro sign. These come out garbled in the corresponding wimp gadget. This seems to be a problem with the swi library, the simplest example of the problem is below.
There is a workaround in that I pass the string as a block (‘b’ instead of ‘s’). This works for some gadgets but not for others (eg ‘StringSet’). I’ve had a look at using Gerph’s “rocodecs/py” but even the enclosed check & test programs don’t work for me (see below). BTW. I’m using “*Country Germany” and “Alphabet Latin9”. Perhaps someone can help me.
|
Mark Beerling (8582) 4 posts |
Please ignore the strike though above. I don’t know what happend there! |
Steve Fryatt (216) 2095 posts |
You need to prefix your code with a |
Chris Johns (8262) 242 posts |
Late to the thread here. There is a new toolbox library out now (1.0.1) which has had a major overhaul. Those who attended the WROCC presentation will have an idea about them. SWI blocks. There is the swi.block, which can be passed to swi.swi by specifing a ‘b’ in the registers string. You create a block by gizing it the number of WORDS you want, eg. b = swi.block(64) # 64 words (256 bytes) you can then pass it to the swi with swu.swi(“Foo_Bar”, “b”, b) to get things in/out of the block, you can use b.signed(byte-offset, value) and b.tosigned(byte-offset) there are similar methods for unsigned, and there is padstring(string, pad-char, start, end) to fill in a string, nullstring(offset) / ctrlstring(offset) to get a null or ctrl terminated string from the block. The other option is to use ctypes, and pass in the address of the ctypes struct as an unsigned integer. The new toolbox libraby does this in sevral places. |
Mark Beerling (8582) 4 posts |
Thanks for the response Chris. I looked at the examples in the toolbox library & used package ctypes.
I use latin9 so that the Euro symbol is in the same location as in Linux & Windows. |
David Gee (1833) 268 posts |
I think Python strings are Unicode (UTF-8); this might be a possible cause of the corruption. Linux is generally now UTF-8. |
Rick Murray (539) 13747 posts |
Fixed that for you. |
Chris Johns (8262) 242 posts |
Internally the strings are utf-8 but given (almost) none of the RISC OS APIs can handle UTF8 there are bits of python on RISC OS that assume latin-1 and ecode to that, which is my bad. (BECUZ EVERYONE SPEEKS EEENGLISH! :)) It’s something I need to address, although it might need to wait unitl 3.12, if I can convince that to build and run. |
Clive Semmens (2335) 3274 posts |
In my experience, in India most geeks know how English writing works better than they know how the writing of their own language works. |
Rick Murray (539) 13747 posts |
Yeah, but aren’t there like two dozen languages in India (each with different scripts)? |
GavinWraith (26) 1559 posts |
Rather more than that! https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers_in_India |