A WIMP Hello World?
Steve Fryatt (216) 2105 posts |
Use Reporter: http://www.avisoft.force9.co.uk/Reporter.htm As for Unless you’re working in the GCC Cross-Compiler, you might find it easier to borrow the code for The other option is to write your output to stderr and redirect that to Reporter’s filing system (see the manual for details). I’ve done this for NetSurf’s log output on occasions, but it doesn’t always work quite as you would expect — as such, |
Garry (87) 184 posts |
Thanks Steve, that looks great, I’ll give that a try on Monday (my Raspberry Pi is at work, not home). As for using OSLib and Toolbox, maybe I’ll see about getting that going once I’ve got my head around Toolbox itself. So far I quite like it, it seems quite simple. My project is actually really basic, and I don’t need much from my UI, all the programming logic is in Lua, and just uses C to build native interfaces on whatever platform it’s running on. I started it on Solaris/SPARC, then got it working on Windows, so now I’d like to try RISC OS. |
Colin (478) 2433 posts |
If you mean printf for debugging, fprintf(stderr,… and in !Run obey file where you run the program add ’>2 <yourprogname$dir>.log so your !run file will set yourprogname$dir <obey$dir> RMload modules…. and the run file ends with run <yourprogname$dir>.!Runimage 2> <yourprogname$dir>.log Then your stderr output will appear in the log file. To get real time output you can redirect to a pipefs file, something like 2> Pipe:$.mylog. Then in a taskobey file put: type Pipe:$.mylog and after running your program double click on the taskobey file. However this can be flakey. It’s very easy to leave pipes open when quitting your program – there are closefile utilities that are a boon here. Its a while since I used this technique but I think you need to quit your program first, then press escape in the debug window before finally closing the debug window. you can check if a pipe file is still in operation with filer_opendir pipe:$ |
Garry (87) 184 posts |
Thanks Colin, I’d like real time output, which !Reporter can provide, so I expect I’ll go with that. Cheers Garry |
Garry (87) 184 posts |
Steve, I’ve now changed my program to use both Toolbox and OSLib. OSLib has some nice bits and bobs which made it easy for me to convert from pixel positions to OS Units, among other things. OSLib and Toolbox actually feels like a fairly pleasant, modern programming environment, a nice surprise. |
David Gee (1833) 268 posts |
I’ve had a problem with the Wimp/OSLib example, the link to which was posted above. The problem is that no window is opened on the screen, and the task “WIMP” keeps running, not responding to the Task Manager or *KillTask (does RISC OS not have an equivalent of “kill -9”?) I tried changing the obvious bug in the code (it refers to y1 twice in the …extent.y1 instead of a y0) but even changing each of the y1s in turn (NOT both together!) to y0 the same behavious occurs. |
Martin Avison (27) 1494 posts |
Did you include (the mandatory) code to end the program when it received a Quit message? |
Steve Fryatt (216) 2105 posts |
If it was my code, no — as I said before, it was a direct line-for-line translation of something someone else had posted to show how OSLib made it clearer. I didn’t change anything or make it “correct”, as the intention was that it could be directly compared… The following works OK (I’ve just tested it on RISC OS 5.18), opening a window bottom-left of the screen. It should respond to Quit from the Task Manager, as it now handles message_QUIT in the poll loop. Note that the implementation still isn’t scalable: you would want to pull the message handling out of the main loop somehow.
|
Steve Fryatt (216) 2105 posts |
For completeness, here it is re-written to use SFLib’s event library (as that’s what I’m familiar with; other event libraries are available, etc). There’s still a It’s rather contrived for an “application” this size, but should scale a lot more pleasantly.
|
David Gee (1833) 268 posts |
I’ll try it on my Raspberry Pi in due course and see what happens. When I tried it yesterday, not only did it not respond to being killed but no window was displayed either—so I couldn’t end the program by closing the window. In it’s original form (without the event library) the code is pretty similar to a Windows API program—or what one might have looked like if Charles Simonyi hadn’t invented Hungarian Notation. The main difference is that the event polling routine in Win API programs is restricted to one window only—you pass its address to the window creation routine, and it’s called a “window procedure” (almost invariably it’s named WndProc). |
Rick Murray (539) 13840 posts |
Just to clarify – RISC OS isn’t Windows; closing the last window won’t quit the app unless you specifically code this behaviour )but don’t, this isn’t the RISC OS way). |
GavinWraith (26) 1563 posts |
Well, I shot my bolt some days ago. Not counting comments and blank lines I make that 99 lines for the C and 7 lines for the RiscLua example. Number of lines is a dodgy metric, of course, especially when require or #include are used, but surely it has something to say about ease of programming for the beginner. |
Steve Fryatt (216) 2105 posts |
Does the RiscLua example open a window on screen? 55 lines of the second C example are concerned entirely with that, so if not then that narrows the difference somewhat. In addition, creating windows programmatically is pretty long-winded in any language. In practice, an application using a Templates file would have a
|
Steve Fryatt (216) 2105 posts |
That’s what the example did; for small utilities that don’t install on the iconbar, it’s the correct thing to do! |
Rick Murray (539) 13840 posts |
Does that include building a window on the fly? It looks like most of that C code is for setting up the CreateWindow data block. |
David Gee (1833) 268 posts |
Well, I’ve just tried the example code you posted above—the one without the event handling library, on a Raspberry Pi/RO 5.19 RC6/Norcroft compiler, and the results are the same as before:
I tried inserting some printf statements and running the program from a TaskWindow. The results tend to vary depending on what editor is managing the teask window, but in the case of StrongEd, it is obvious that the application enters the poll loop and returns a lot of reason code 0s, as one would expect, but there’s still no window on the screen. I’ve tried changing the resolution from the Pi’s FullHD default to 640×480, but that makes no difference either. Don’t know whether the compiler has anything to do with it. I’ve installed GCC and got it (GCC) working; will look at getting the relevant version of OSLib for GCC and see if that makes a difference. But it won’t be for a while. |
Rick Murray (539) 13840 posts |
Can you post the code you used?
You can’t run a multitasking program from a task window.
You are only getting that far because you are not checking for errors. Here, I open a taskwindow and type…
In other words, your returned poll codes are meaningless because your task was never initialised – it just doesn’t work like that within taskwindows. I just wrote a short program to call Wimp_Poll in a taskwindow and it returned a lot of zeroes. Interesting, it returned 17,17,18 and then froze the system when I tried it in the F12 command line! I think maybe Wimp_Poll needs to be tweaked to throw an error if it wasn’t called by a valid task and/or in the Desktop world! Either way – you can’t run a multitasking program in a taskwindow. Sadly, nor can you easily printf(). You could use Wimp_ReportError (or whatever the library offers) to provide status messages but use them judiciously – a never-ending popup message in a poll loop isn’t a good way to start the day! [no doubt others will suggest Reporter or somesuch, this is a better long-term solution for sure] |
Rick Murray (539) 13840 posts |
I’ve entered this as a ticket – https://www.riscosopen.org/tracker/tickets/343 Nice to see Textile is so crap that the preview thingy at redcloth rendered the code part correctly when I tried a preview, but the entered ticket has <pre><code> … </code><pre> around the example code. Although it’s a show stopper (total system hang), I’ve flagged it as normal severity because if nobody’s really noticed it in a quarter century of using RISC OS, then… (^_^) |
David Gee (1833) 268 posts |
Just to refer to my earlier post—this is a compiler issue. I had more time than expected (forgot about the Bank Holiday) and obtained the GCC version of OSLib. And I find:
Looks like a bug in the Norcroft version of OSLib, or in Norcroft C itself… Yes, I’ll look at Reporter (and possibly Steve’s debug_printf) in due course. As you might be able to guess, I’m more familiar with Linux where you can always start a program from the console and printf to it—the Geany IDE for instance creates a console to run a program. Can often be very useful. Using Wimp_ReportError is equivalent to using a message box in Windows—I’ve used that in the past and it needs to be used very sparingly. Windows GUI programs do not have a console to write to, even though you can use printf the output is thrown away. BTW: how do you do the block of code as in the last-bu-one post above? |
Rick Murray (539) 13840 posts |
I have (an older version of) the Norcroft compiler. If you can zip up your project and makefile and the version of OSLib you used, I’ll give it a whirl and see what happens for me, if you like?
Ah, yes – the Alt-plus-F-key thingy that switches between the GUI and multiple command lines, all different. As you’re a Unix guy – I wondered (but never tried) – could you start the GUI in one of the other command lines and have it run independently of the GUI already started? Like Alt-F1 and Alt-F2 could switch between different window managers, each independent of the other?
Oh yes! Making a mistake like a called-a-billion-times loop with a MsgBox in it is a mistake you only tend to do once. After some time coding, you learn to drop in a few brief popup messages, and change (not add to) them as you work to narrow down the problem.
Depends on the environment – VisualBasic has Debug.Print that does runtime output while the program is running in the IDE.
Another method I have used (under RISC OS no less) is to printf to a serial port. Originally I had a DEC VT110 terminal, but more recently (as the terminal is no longer with me thanks to moving and such) I used a PocketBook II (aka Psion 3a). Only good for 9600bps, but it is actually one of the most responsive debug setups I’ve used.
Leave a blank line (this is important).
note: space inserted into example closing </code> and </pre> so Textile doesn’t think they are the real thing] |
Chris Hall (132) 3554 posts |
Ah! Of course you can’t use < instead of < to do this inside those tags! |
Steve Pampling (1551) 8170 posts |
Ever wondered why VNC has a :0 and :1 and :2 (etc) element in the command? X-windows sessions (plural) |
David Gee (1833) 268 posts |
Actually by “console” I meant a GUI terminal window (e.g. LXTerminal). But X is of course a networked protocol, so you can run it from one of the alternate consoles I would guess, provided DISPLAY is set correctly. You can even run a window on a different (physical) machine. Debug.Print disappeared from VB about 10 years ago (i.e. it’s not in VB .NET). Of course Visual Studio has a full graphical debugger but you really need two displays to make the most of this. As for the code: it’s exactly the same as in the EARLIER of Steve Fryatt’s two posts on this page (assuming this appears on page 2, anyway), there was no makefile—I just used the GUI interface to compile the single file involved (code dragged and dropped from Netsurf), and OSLib is the current version (7.00). The norcroft compiler is the one included in the NutPi suite. |
Willi Theiss (541) 17 posts |
Maybe the problem with Norcroft is caused by using the wrong libraries? |
David Gee (1833) 268 posts |
Never thought about that. I removed C:o.risc_oslib, but not wimplib. When I get time I’ll try reducing the list of libraries as you suggest and see if that makes a difference. |