mailto: blog -at- heyrick -dot- eu

Navi: Previous entry Display calendar Next entry
Switch to desktop version

FYI! Last read at 18:36 on 2024/11/21.

Some coding

I'm having a "pont" today. This means that since the previous two days were a weekend, and tomorrow is a public holiday, we're not working this single day in the middle.
That's good, because, honestly, I felt like crap this morning. Got up at half six, fed furry and had tea, then went back to bed.
Next thing I know, it's just going ten.
I don't like Mondays.

Anyway, I'm working on something. I'm not going to say what at the moment, but it runs in a single-tasking mode (no, it's not a game), and in order to be able to accept input from the user in a nicer method than OS_ReadLine (that's basically INPUT), I decided to create a "dialogue manager".

Based upon the way OPL used to work on the Psion organiser, there are six primary stages of creating a dialogue:

  1. Initialise the dialogue.
    This is a simple call to dialogue_init() passing a dialogue title. This sets up the memory for an empty dialogue.
  2. Add things to the dialogue.
    There are various types of object that can be added. Text messages, check boxes, radio options, string input, selection choices, buttons...
    If you will need to read information from the dialogue in the future, you will need to remember the object handle.
  3. Show the dialogue on the screen.
    This will iterate through the added objects and will work out how big the dialogue needs to be to fit everything into it, and to place it centred on the screen.
    At this point, dialogue content cannot be changed except as provided by the user interface. You can't add/remove objects.
  4. Let the dialogue manager handle the user interface.
    This is a simple call to dialogue_do() that will handle the entire UI behaviour, and will return TRUE if the user clicked the Primary (OK) button or pressed Enter; or FALSE if the Cancel button or pressed Escape.
  5. Read information from the dialogue, as necessary.
  6. Finally, dismiss the dialogue (with dialogue_dismiss(). This will free the memory used, and restore things.

It is acceptable to call dialogue_do() multiple times, so you can check values on exit from the UI and pop up a message if something is wrong, then go back to dialogue_do() so the user can do something about it.

Multiple dialogues are possible. Only the most recently used is the current. This is a dialogue manager, not a window manager. ☺ But it does mean you can use a dialogue on top of a dialogue to notify the user of problems.
In this case, dialogue_dismiss() will, if there's a previous dialogue, restore the previous dialogue context.

Here is some example code.

// At the top
   dialogue_handle diaref = NULL;
   object_handle   behaviour = NULL;
   object_handle   runaround = NULL;
   object_handle   throwstuff = NULL;
   object_handle   newname = NULL;
   int             optval = 0;

   [...]

   // Create the dialogue
   diaref     = dialogue_init("How to handle the world");
   dialogue_addtext("The world is screwed. How do you intend to cope with it?");
   behaviour  = dialogue_addradio("Behaviour", "Scream", "Panic quietly", "Meh",
                                  "Laugh", "Get drunk", "", "", "", 2);
   runaround  = dialogue_addcheck("Options", "Run around with arms in the air", TRUE);
   throwstuff = dialogue_addcheck("", "Throw random items of furniture", FALSE);
   dialogue_addtext("If you wish to be known by another name, enter it below.");
   newname    = dialogue_addstring("Name", "Tiamat", STRING_MAX);
   dialogue_addbuttons("Accept reality", "Deny everything");

   // Show it on-screen
   dialogue_show(DIA_NORMAL);

   // Handle the dialogue UI
   if ( dialogue_do() )
   {
      // TRUE response, user clicked OK button
      OS_CLI("ScreenSave $.dialogue");

      // You would read options like this
      optval = dialogue_readcheck(runaround);
      // is TRUE if option checked, else FALSE
   }
   // else FALSE if user clicked Cancel button

   // We're done, so dismiss this dialogue
   dialogue_dismiss();

This would make the following dialogue.

An example dialogue
An example dialogue.

You can see most of the different sorts of objects there.

If we edit the code around dialogue_do() as follows...

   // Handle the dialogue UI
   if ( dialogue_do() )
   {
      // TRUE response, user clicked OK button

      // One can overlay a dialogue on another
      // We aren't remembering any handles as we only want to show this,
      // so the handles aren't required.
      dialogue_init("Critical error!");
      dialogue_addtext("Unfortunately reality is broken and your chosen");
      dialogue_addtext("options cannot be applied.");
      dialogue_addtext("Please die, and then try again.");
      dialogue_addbuttons("Terminate", "");
      dialogue_show(DIA_ERROR);
      dialogue_do();
      dialogue_dismiss(); // will restore the previous dialogue context
   }

It will demonstrate overlaid dialogues as shown just below. Also worth noting is that since we aren't interested in reading anything back from this dialogue, there's no need to bother with any of the handles. Just create it, show it, wait for the user to do something, then discard it.

No, that isn't right!
No, that isn't right, something went wrong!

193 lines of header file, and 1857 lines of code. Not bad for a weekend. Well, I say weekend. I wrote most of the code yesterday.
It's simple, but it does what I wanted and it looks better than simply asking the user to enter input.

 

Headphone repair

Amazon dispatched my battery yesterday evening. Colis Privé got it to me in the morning before, even, the post person had been around.

The replacement battery
The replacement battery.

I cut off the Molex plug and soldered the terminals to the associated pads within the headphones. As I didn't have sticky to hold the battery in place, I Blue Petered something using a piece of plastic cut from the bottom of a cheese pack.

The headphones, fixed
The headphones, fixed.

As you can see, from the green indicator (rather than blue), the active noise cancelling is working again. As the old battery was on the way out, that only worked sometimes.

The ear pads are a bit naff, but they're the headphones I wear at work and while out shopping, so it's nice to get them operating again - and with the noise cancelling too. Nice!

 

Cheese origins

Speaking of cheddar packs, I bought myself another pack of the Super U's own brand sliced cheddar. In the shop I turned the pack over, read the back, and would have burst into laughter if I had anything that resembled a functional emotional response. I did, sort of, manage a smirk.

Oh, look, Stranraer.
Oh, look, Stranraer.

So, asides from some outliers like Cathedral City, it seems as if most of the cheddar in France (from my sample of two supermarkets!) comes from this one factory in Scotland.

Now, this isn't as crazy as it might seem, as the factory is owned and run by Lactalis, which being a multinational will have some experience in all of the Brexit-inflicted bullshit that have caused problems with imports into Europe.
To put this into context, British tourists are not allowed to take any meat or dairy products with them. Which means, yes, cheese and pickle sandwiches and bacon butties may be confiscated by customs.
It's pathetic, but since the UK is no longer part of the EU customs area... it's "what the people voted for", apparently. I think, having been a part of the EEC then the EU for as long as I've been alive, people didn't really appreciate exactly how much freedom the customs arrangements actually gave everybody. I mean, my brain nearly exploded when the Brexiteers tried to say that leaving the EU would be less red tape (how's that one working out?).

So, having a big French company running this Scottish cheese factory is perhaps the best way to get imports into the EU sorted. Granted, it might reduce choice (my Cathedral City that is sometimes available from the Leclerc in Big Town is aged nine months...), but on the other hand a reduced choice is better than erratic or no choice.
Besides, I've been eating the Seriously Strong since before I even came to France!

 

Buddleia

As part of my tidying up outside, I have cut away all of the dead bits of the buddleia. Remember, this was a mess of brambles as tall as me.

What's left of the buddleia.
What's left of the buddleia.

 

Hair

Look mummy! I've changed my gender! 😂

But, yeah... got fed up with my hair so an old pair of scissors and five minutes of inept snipping at random bits and... it probably looks crap but I might manage a shrug if I try really hard.

I'm more unset about the lack of colour.
I'm more upset about the lack of colour.

 

Car service

Today was the day that I had predicted to take my little car for it's service. Well, since I haven't gone to Big Town, or vide greniers, or anywhere actually... I still have 914km before the counter hits zero.
That's about six and a half weeks at current use.

 

 

Your comments:

No comments yet...

Add a comment (v0.11) [help?]
Your name:

 
Your email (optional):

 
Validation:
Please type 65372 backwards.

 
Your comment:

 

Navi: Previous entry Display calendar Next entry
Switch to desktop version

Search:

See the rest of HeyRick :-)