SpinGadget() on Linux

Just starting out? Need help? Post your questions and find answers here.
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

SpinGadget() on Linux

Post by Little John »

Hi all,

the following code works as expected e.g. with PB 5.31 beta 1 x64 on Windows 7.
With that, I mean that I can change the gadget value by
  1. clicking at the up or down arrow with the mouse
  2. typing a number in the small edit field
  3. pressing the up or down arrow key
With PB 5.30 x64 on Linux Mint 17 Cinnamon, methods a) and b) are working as well, but pressing the up or down arrow key has no effect.
I encountered this on a virtual machine. However, in other programs that run on the same virtual machine (e.g. the PB IDE), the up and down arrow keys are working fine.

How can the below code be changed, in order to make the arrow keys work as expected on Linux?
Or is this a bug in PB?

Code: Select all

If OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   SpinGadget     (0, 20, 20, 100, 25, 0, 1000)
   SetGadgetState (0, 5) : SetGadgetText(0, "5")   ; set initial value
   Repeat
      Event = WaitWindowEvent()
      If Event = #PB_Event_Gadget
         If EventGadget() = 0
            Select EventType()
               Case #PB_EventType_Up, #PB_EventType_Down
                  SetGadgetText(0, Str(GetGadgetState(0)))
                  
               Case #PB_EventType_Change
                  SetGadgetState(0, Val(GetGadgetText(0)))
            EndSelect
            
         EndIf
      EndIf
   Until Event = #PB_Event_CloseWindow
EndIf
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Re: SpinGadget() on Linux

Post by uwekel »

Hi Little John,

unfortunately, the spin gadget is not a real GTK spin gadget, so the behaviour is not the same as you probably know. But here is a small work-around to get the keys working. You can also use other than the cursor up/down keys. And, what you didn't mention, the mouse scroll wheel does not work either. Some fine tuning of PB team is highly requested :-)

Code: Select all

Enumeration Gadget
  #Button
  #Spin
EndEnumeration
Enumeration 1
  #SpinUp
  #SpinDown
EndEnumeration

If OpenWindow(0, 0, 0, 140, 100, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(#Button, 10, 10, 120, 30, "Dummy")
  SpinGadget(#Spin, 10, 50, 100, 28, 0, 1000, #PB_Spin_Numeric)
  SetGadgetState(#Spin, 5)
  Repeat
    Select WaitWindowEvent(100)
    Case #PB_Event_Menu
      Select EventMenu()
      Case #SpinUp
        SetGadgetState(#Spin, GetGadgetState(#Spin) + 1)
      Case #SpinDown
        SetGadgetState(#Spin, GetGadgetState(#Spin) - 1)
      EndSelect
    Case #PB_Event_CloseWindow
      Break
    EndSelect
    ;check active gadget (unfortunately spin gadget has no focus/lostfocus eventtype)
    If GetActiveGadget() = #Spin
      If Not has_shortcut
        AddKeyboardShortcut(0, #PB_Shortcut_Up, #SpinUp)
        AddKeyboardShortcut(0, #PB_Shortcut_Down, #SpinDown)
        has_shortcut = #True
      EndIf
    ElseIf has_shortcut
      RemoveKeyboardShortcut(0, #PB_Shortcut_Up)
      RemoveKeyboardShortcut(0, #PB_Shortcut_Down)
      has_shortcut = #False
    EndIf
  ForEver
EndIf
Best regards
Uwe
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
User avatar
idle
Always Here
Always Here
Posts: 5096
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: SpinGadget() on Linux

Post by idle »

I'm still on my first coffee of the morning so no idea if theres a specific gtk signal connect to handle the up and down arrows
but you could try with bindevent.

Code: Select all


Procedure MenuEventHandlerSpin()
  Protected val.s,gad
  gad = GetActiveGadget()
  Select gad
    Case 0     
      Select EventMenu()
        Case #PB_EventType_Up
          val = Str(Val(GetGadgetText(gad))+1)
          SetGadgetText(gad,val)
        Case #PB_EventType_Down
          val = Str(Val(GetGadgetText(gad))-1)
          SetGadgetText(gad,val)
      EndSelect     
  EndSelect   
EndProcedure  

If OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   AddKeyboardShortcut(0,#PB_Shortcut_Up,#PB_EventType_Up)
   AddKeyboardShortcut(0,#PB_Shortcut_Down,#PB_EventType_Down)
   BindEvent(#PB_Event_Menu,@MenuEventHandlerSpin())
   BindEvent(#PB_Event_Menu,@MenuEventHandlerSpin())
   
   SpinGadget     (0, 20, 20, 100, 25, 0, 1000)
   SetGadgetState (0, 5) : SetGadgetText(0, "5")   ; set initial value
   Repeat
      Event = WaitWindowEvent()
      If Event = #PB_Event_Gadget
         If EventGadget() = 0
            Select EventType()
               Case #PB_EventType_Up, #PB_EventType_Down
                  SetGadgetText(0, Str(GetGadgetState(0)))
               Case #PB_EventType_Change
                  SetGadgetState(0, Val(GetGadgetText(0)))
            EndSelect
            
         EndIf
      EndIf
   Until Event = #PB_Event_CloseWindow
EndIf
Windows 11, Manjaro, Raspberry Pi OS
Image
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: SpinGadget() on Linux

Post by Little John »

Hi uwekel and idle,

thanks for your replies!

Yes, it works with self-defined keyboard shortcuts.

However, I thought that the main functions of the PB gadgets were the same on all supported platforms. In cases where this does not apply, IMHO there should be a regarding remark in the docs.
uwekel wrote:And, what you didn't mention, the mouse scroll wheel does not work either.
Yes, it's the same here. I just forgot to mention it.

In the meantime, I found out that SpinGadgets in other Linux programs work as I'd expect (i.e. like the PB SpinGadget on Windows).
For instance, I checked a SpinGadget in the program "gedit" (on Linux Mint 17 x64 Cinnamon):

Image

Here I can change the gadget value also by pressing the up or down arrow key, or with the scroll wheel of the mouse.

So it seems to me that this issue can be considered a bug or missing feature in the Linux version of the PB SpinGadget.
Thanks again!
Post Reply