Python toolbox library updated
Chris Johns (8262) 242 posts |
Those of you who attended the WROCC talk will be aware that the toolbox library for python has undergone a bit of an overhaul. The reults of this are now available, and can be installed with pip in the usual way. You might need to tell pip you want to upgrade riscos-toolbox if you’ve been using 0.2.0. A word of warning, things build for 0.2 will need a bit of fettling to use 1.0.1. The Hyper example is on github (https://github.com/c-jo/riscos-toolbox) which should give you a good idea how to do stuff, given the lack of docs and howtos. Which are on the list of things to do! |
John Rickman (71) 646 posts |
Hi Chris Meanwhile I used PIP to upgrade itself but am a bit puzzled by the warning.
|
David Pitt (9872) 363 posts |
Replicating the above I decided to verify the upgrade had happened. *python3 -m pip --version Traceback (most recent call last): .... File "ADFS::Titan4.$.Progm.Progm2.Python.!Python3.python38.lib.importlib.resources", line 61, in _normalize_path raise ValueError('{!r} must be only a file name'.format(path)) ValueError: 'cacert.pem' must be only a file name I remembered this. A bit of digging found instances of A speculative search and replace of all 7 **python3 -m pip --version pip 23.1.2 from ... !PythonSite.Python38.Site-Packages.pip (python 3.8) * Perhaps PackMan versions are better for RISC OS?? A bit later Reverted to pip 20.0.2 from PackMan. |
Lauren Etc. (8147) 52 posts |
Excellent timing, just grabbed it for the project I’m working on, can’t wait to give it a shot. |
David J. Ruck (33) 1635 posts |
All occurrences of ‘.’ used as an extension separator should be replaced with os.path.extsepthen the code will work on all platforms. The change then needs to be push back upstream. |
Chris Johns (8262) 242 posts |
I’m not sure if upstream would accept the patch, but it’s worth at least trying! As to pip. It was a bit of an effort to get the version on PackMan working, so I suspect any installed from the net versions won’t work on risc os. As mentioned at the talk, I am going to try to port 3.12, which will, no doubt, be a challenge. I did get 3.10 to work, but I don’t think I ever tried 3.11. |
John Rickman (71) 646 posts |
The reults of this are now available, and can be installed with pip in the usual way. You might need to tell pip you want to upgrade if you’ve been using 0.2.0. Just in case anyone else makes my mistake! As did David above I reverted to pip 20.0.2 from PackMan and used it to install the toolbox. |
Chris Johns (8262) 242 posts |
Sorry, that wasn’t very clear was it. I’ve upated the post to make it clearer! |
Matthew Phillips (473) 721 posts |
I am struggling creating a suitable block which I can pass to Wimp_SendMessage in order to send a user message to another application. I created a class like this: class HelpReplyMessage(UserMessage) event_id = 0x503 _fields_ = [ ("help_message", ctypes.c_char*236) ] Then I can create the message, ready to send, like this: message = HelpReplyMessage() message.your_ref = 0 message.code = 0x503 swi.swi("Wimp_SendMessage", "iII", Wimp.UserMessage, ctypes.addressof(message), task) But I cannot for the life of me work out how to actually set that help_message string. I’ve searched the internet for ctypes examples, but almost all those involving strings have c_char_p, and the string is, of course, embedded in the message block. |
Chris Johns (8262) 242 posts |
Thanks to the efforts of Laren, there are a load of extra gadgets supported. Version 1.0.2 available from pip. |
Lauren Etc. (8147) 52 posts |
Excellent, thank you Chris! I’ve been a bit busy the past couple days but I’m already in the process of porting something over to give the new stuff a real world test. Thanks again for your work! |
Lauren Etc. (8147) 52 posts |
Is this going to be merged back into main? |
Michael Stubbs (8242) 70 posts |
Chris: Thanks for all the work you’re doing on Python for RISC OS. I’m currently learning Python on Mac OS and Windows for work so really looking forward to trying on RISC OS when I have a bit more knowledge. Lauren: I don’t know what gadgets are yet but they sound significant so thank you, as well! |
Matthew Phillips (473) 721 posts |
Bumping this up to the top again in the hope that someone has a solution to this I have searched for c_char in the Toolbox library code in the hope of finding an example of setting the contents of a c_char * NNN block with the contents of a string, but I think all the examples in the library are of reading strings! |
Lauren Etc. (8147) 52 posts |
Matthew: After the chat the other day I didn’t want to just leave this unanswered, so… First, I think you’re overwriting the parent class’s fields definition there, so you may want to append it something along these lines:
That said, I tried for hours and I couldn’t get anywhere either :( No matter what I tried I always got “Message block is too big / not a multiple of 4” and weirdly I noticed when I put a character array field in it always showed as being 20 bytes more than it was expected to be. But even if I adjusted for that it was the same thing… I ran out of time, but hopefully either Chris can come back and answer this or if I ever figure it out in the course of things I’ll let you know… I’ll probably have to revisit it later. |
Matthew Phillips (473) 721 posts |
It looks like it, doesn’t it! I have no idea how is works, but that bit functions fine: I copied it from examples elsewhere in the Toolbox library, such as here, for example As for the problem, it looks like I was over-thinking it. I cannot remember precisely what I tried last time, but just setting message.help_message = b"Press this button to cause untold catastrophe" seems to work. I should have had another go before bumping the thread, as I hit on it straight away. I’m sorry you struggled at it like me first time round! My next problem is how to read two strings which are passed in the same buffer, one immediately after the other separated by a single null byte. I have only myself to blame for the message format, as it’s one I devised for Nominatim to maximise the capacity of a limited buffer. Dead easy to read in C or BASIC, but I’ve yet to work it out for Python! |
David J. Ruck (33) 1635 posts |
I first thought of struct.unpack but that only does fixed length objects, but you could use it to extract the part of the buffer with the two null terminated strings and call struct.unpack(spec, buffer).spit(b"\x00")[0:1]which should separate the two strings and ignore any following padding. This works as Python strings are stored as length and buffer contents, and aren’t terminated by any character sequence. |
John Rickman (71) 646 posts |
There are a couple of problems with the python toolbox test program !Hyper. 1. The Keyboard short cuts in the menu do not work. My guess is they were not implemented. 2. The “Previous” button in the status line does not work for some cards. Eg: If you delete the three buttons on the DDT card the “previous” or “back_handler” button works.
It looks as if the history stack is being corrupted by processing the buttons defined on the card. |
Charles Ferguson (8243) 427 posts |
Remember, you can raise issues on the Python toolbox library in the usual way by posting them on the project itself – https://github.com/c-jo/riscos-toolbox/issues. |
Jean-Michel BRUCK (3009) 359 posts |
After the nice demonstration of using the ToolBox with Phyton, thanks to Chris, I undertook to make a version in C++ only with the DDE. It was a challenge with Paolo :-) This program had always interested me and I wanted to understand how it worked, it’s very informative. Buttons and shortcuts seem to work! The toolbox is very good tool, for anyone who wants to create applications and it is available in many languages!!! |
Lauren Etc. (8147) 52 posts |
Nice, Jean-Michel, I’d like to see the source when ready. I’m honestly a big proponent of the Toolbox, having a proper toolkit sure beats doing things the old-fashioned way, which is why I was eager to try it out with Python. Now that said, I’m very foolish so rather than clean up the source or make it anything near ready, I’m going to post what I’ve been making with it and the more recent version of the Python toolbox library; it’s mostly there to exist as another example or demonstration, so nobody take it as best practice. Also, it’s fully functional but completely useless to everyone except perhaps myself: https://github.com/laurenrad/RLook I’ll be working on it more soon, but consider this an extremely soft launch. It’ll keep getting updated alongside the library as well. |
John Rickman (71) 646 posts |
Thanks for reminder – Issue now raised on github. |
Jean-Michel BRUCK (3009) 359 posts |
@ Lauren https://jeanmichelb.riscos.fr/Download/Hyper2Sce.zip
Me too, as all the libraries, I see that Pyhton is not lacking… Would have a example sampler file to see RLook in action |
Lauren Etc. (8147) 52 posts |
@ Jean-Michel Oh, there is an example file included within the RLook app bundle, by the way. I meant to pull it out of the app folder, but forgot. |
Jean-Michel BRUCK (3009) 359 posts |
Thanks Lauren, |