, ,

Scripting the GUI with ‘howdy’

Scripting the GUI with ‘howdy’

recordsdata image

Haiku’s GUI is in thought entirely scriptable. You can trade a window’s net web yelp and measurement and manipulate somewhat mighty every widget in it.
The tool to make here is howdy. It sends BMessages to an application, thus emulating what happens if the patron clicks on a menu, checkbox, or totally different widgets.

The seminal work on this application scripting is the BeOS Utility Scripting chapter of the BeOS Bible by Chris Herborth. You would possibly want to nonetheless survey that first and, whereas you’re love me, will abet coming support to it on every occasion you suspect about solving something through howdy.

This weblog isn’t an introduction to scripting with howdy, but more love a collection of well-known howdy-traces. It’s supposed to say our GCI students as a lot as speed, who get chosen the process to make howdy-scripts to automate taking screenshots for the patron e book.
Please observation, whereas you get more guidelines!

As example application, we get a peek at the Time preferences.

The Time preferences

Transferring and resizing a window

You can procure a window’s measurement and net web yelp with:

howdy Time procure Body of Window 0
Respond BMessage(B_REPLY):
   "result" (B_RECT_TYPE) : BRect(163.0, Fifty three.0, 649.0, 420.0)

The coordinates of the BRect are within the display masks masks coordinates (left/top/upright/backside).

To home a singular measurement/net web yelp:

howdy Tracker home Body of Window 0 to "BRect(1329.0, 65.0, 1905.0, 968.0)"
Respond BMessage(B_REPLY):
   "error" (B_INT32_TYPE) : 0 (0x00000000)

Don’t be fooled, the “error” output of “0” is in total a group up of success. You can abet far from all junk output and limit it to the well-known necessities by adding the -o parameter. Makes for mighty less complicated scripting, too.

In case you get a smaller resolution, you would desire to adjust the display masks masks coordinates accordingly.

As you would stare, by forcing these absolute coordinates, the window layout isn’t in any manner restricted and can result in widgets being positioned widely spaced in that unique window physique.

Altering tabs

It’s now not as straight ahead as anticipated… To trade to the “Clock” tab:

howdy -o Time home Sequence of Survey 0 of Survey 0 of Window 0 to Three

The Clock tab

You can uncover the hierarchy of an app’s GUI by counting the views within the window, getting their “InternalName” and taking a peek at the output of the many “getsuites”:

howdy Time depend Survey of Window 0
Respond BMessage(B_REPLY):
   "result" (B_INT32_TYPE) : Three (0x00000003)


howdy Time procure InternalName of Survey 0 of Window 0
Respond BMessage(B_REPLY):
   "result" (B_STRING_TYPE) : "baseView"
   "error" (B_INT32_TYPE) : 0 (0x00000000)

howdy Time procure InternalName of Survey 0 of Survey 0 of Window 0
Respond BMessage(B_REPLY):
   "result" (B_STRING_TYPE) : "tabView"
   "error" (B_INT32_TYPE) : 0 (0x00000000)


howdy Time getsuites of Survey 0 Survey 0 of Window 0
Respond BMessage(B_REPLY):
   "suites" (B_STRING_TYPE) : "suite/vnd.Be-tab-glimpse"
   "suites" (B_STRING_TYPE) : "suite/vnd.Be-glimpse"
   "suites" (B_STRING_TYPE) : "suite/vnd.Be-handler"
   "messages" (B_PROPERTY_INFO_TYPE) : 
        property   commands                            specifiers              kinds
---------------------------------------------------------------------------------------------------
       Resolution   B_GET_PROPERTY B_SET_PROPERTY       DIRECT                  LONG 
                   Usage: 

   "messages" (B_PROPERTY_INFO_TYPE) : 
        property   commands                            specifiers              kinds
---------------------------------------------------------------------------------------------------
           Body   B_GET_PROPERTY B_SET_PROPERTY       DIRECT                  RECT 
                   Usage: The glimpse's physique rectangle.
          Hidden   B_GET_PROPERTY B_SET_PROPERTY       DIRECT                  BOOL 
                   Usage: Whether or now not the glimpse is hidden.
           Shelf                                       DIRECT                  
                   Usage: Directs the scripting message to the shelf.
            Survey   B_COUNT_PROPERTIES                  DIRECT                  LONG 
                   Usage: Returns the collection of puny one views.
            Survey                                       INDEX REV.INDEX NAME    
                   Usage: Directs the scripting message to the desired glimpse.

   "messages" (B_PROPERTY_INFO_TYPE) : 
        property   commands                            specifiers              kinds
---------------------------------------------------------------------------------------------------
          Suites   B_GET_PROPERTY                      DIRECT                  (suites CSTR)(messages SCTD)
                   Usage: 
       Messenger   B_GET_PROPERTY                      DIRECT                  MSNG 
                   Usage: 
    InternalName   B_GET_PROPERTY                      DIRECT                  CSTR 
                   Usage: 

   "error" (B_INT32_TYPE) : 0 (0x00000000)

It also generally helps to search into the app’s source code, clearly. Gain the safe web yelp where the window layout is created and stare whereas you would prepare the glimpse hierarchy.

Any seen abet watch over widget is mostly some glimpse contained in some other glimpse, which is contained in some other glimpse, which would possibly per chance very successfully be contained in some other glimpse, … which within the tip is contained within the window.
Love: A button glimpse sits in a glimpse, which sits in a container glimpse, which sits in a tab glimpse, which sits in a immoral glimpse, which sits in a window. Turtles, the entire manner down…

Alternatively!
You shouldn’t utilize this kind of Survey-of-Survey-of-concatenation in a script whereas you care about the script abet working if the app’s GUI changes.
Use the “InternalName” as a replacement. So this:

howdy -o Time home Sequence of Survey 0 of Survey 0 of Window 0 to Three

turns into:

howdy -o Time home Sequence of Survey "tabView" of Window 0 to Three

Checking a checkmark

We’re on the “Clock” tab of the Time preferences:

howdy Time procure InternalName of Survey Three of Survey 0 of Survey 0 of Survey 0 of Window 0
Respond BMessage(B_REPLY):
   "result" (B_STRING_TYPE) : "Clock"
   "error" (B_INT32_TYPE) : 0 (0x00000000)

The Clock tab

Gain the “Repeat clock in Deskbar” checkbox by checking the ‘InternalName’ of the views contained within the “Clock” glimpse. The checkbox itself is in some other glimpse “point to clock box”:

howdy Time procure InternalName of Survey 0 of Survey "Clock" of Window 0
Respond BMessage(B_REPLY):
   "result" (B_STRING_TYPE) : "point to clock box"
   "error" (B_INT32_TYPE) : 0 (0x00000000)

We are in a position to procure the impress of the checkbox because it appears to be like within the GUI (and by the utilize of “home” as a replacement of “procure” we would possibly per chance even even trade that):

howdy Time procure Mark of Survey 0 of Survey "point to clock box" of Window 0
Respond BMessage(B_REPLY):
   "result" (B_STRING_TYPE) : "Repeat clock in Deskbar"

Now, to easily accumulate the checkmark:

howdy -o Time home Price of Survey 0 of Survey "point to clock box" of Window 0 to 0

However as you stare, that finest un-attracts the checkmark – it doesn’t essentially flee the code as if the patron clicked the checkbox!
Incessantly that will most definitely be ample whereas you finest desire to buy a screenshot of the window. However in this case, essentially unselecting the checkbox need to nonetheless also disable the checkboxes beneath. And naturally disguise the clock within the Deskbar.

We get got to undoubtedly send the BMessage that will home off all that. For this, we again need to search through the code.
The BMessages for a glimpse advance at its MessageReceived() feature, in our case in ClockView.cpp. We stare the BMessage’s ‘what’ discipline’s matching constant ‘kShowHideTime’. Now we factual need to salvage the particular worth of that constant and make so in TimeMessages.h: ‘ShTm’
OpenGrok is terribly well-known for these items.
Now all the pieces turns into even mighty less complicated:

howdy -o Time 'ShTm'

That’s generally the style you’re taking care of all BControls that need to nonetheless home off some action, love clicking a button.

Filling out a text discipline

The ‘Network time’ tab has a text discipline at the pinnacle:

A text discipline

howdy -o Time home Price of Survey 0 of Survey 2 of Survey 0 of Survey 0 of Survey 0 of Window 0 to "Example text"

Or after a piece of of nosing around with “procure InternalName”:

howdy -o Time home Price of Survey 0 of Survey "Network time" of Window 0 to "Example text"

Read Extra

What do you think?

0 points
Upvote Downvote

Total votes: 0

Upvotes: 0

Upvotes percentage: 0.000000%

Downvotes: 0

Downvotes percentage: 0.000000%

Leave a Reply

Your email address will not be published. Required fields are marked *