Page 1 of 2
File picker gadgets in native PureBasic?
Posted: Tue Mar 12, 2024 4:21 am
by Quin
In the DocMaker program, we see this type of control. A group with a file dialog path and a button that opens a standard Windows file dialog to select it. If you need another example, wxPython has a class called wx.FilePickerCtrl.
I know it works at least on Windows, so how do we actually use it in PureBasic?
Thanks!
Re: File picker gadgets in native PureBasic?
Posted: Tue Mar 12, 2024 5:06 am
by BarryG
Re: File picker gadgets in native PureBasic?
Posted: Tue Mar 12, 2024 5:27 pm
by Quin
That's the dialog, sure. But I meant the super generic-looking browse for file control you super commonly see, even in innosetup installers. I've seen it enough places that I assume it's a fairly ubiquitous construct.
Re: File picker gadgets in native PureBasic?
Posted: Tue Mar 12, 2024 5:56 pm
by DarkDragon
There is no official control for that, you have to compose it yourself. I also wondered a few years ago why it isn't, but it is also a very simple composition of a label, an input field and a button.
Re: File picker gadgets in native PureBasic?
Posted: Wed Mar 13, 2024 12:01 am
by Quin
I see, thank you!
DarkDragon wrote: Tue Mar 12, 2024 5:56 pm
There is no official control for that, you have to compose it yourself. I also wondered a few years ago why it isn't, but it is also a very simple composition of a label, an input field and a button.
Re: File picker gadgets in native PureBasic?
Posted: Wed Mar 13, 2024 2:40 am
by BarryG
Quin wrote: Tue Mar 12, 2024 5:27 pmI meant the super generic-looking browse for file control you super commonly see
Got a screenshot? Because I have no idea which file picker you're talking about.
Re: File picker gadgets in native PureBasic?
Posted: Wed Mar 13, 2024 2:41 am
by Quin
Not a screenshot, but you see multiple of them if you open PureBasic/sdk/DocMaker/DocMaker.exe.
BarryG wrote: Wed Mar 13, 2024 2:40 am
Quin wrote: Tue Mar 12, 2024 5:27 pmI meant the super generic-looking browse for file control you super commonly see
Got a screenshot? Because I have no idea which file picker you're talking about.
Re: File picker gadgets in native PureBasic?
Posted: Wed Mar 13, 2024 3:36 am
by BarryG
I don't see anything in DocMaker that the PureBasic commands don't provide? It just uses OpenFileRequester() and PathRequester().
Re: File picker gadgets in native PureBasic?
Posted: Wed Mar 13, 2024 3:53 am
by AZJIO
You have to do it yourself
Code: Select all
EnableExplicit
Structure Element
id_btn.i
id_str.i
EndStructure
Global NewList FPCes.Element()
Procedure OpenFile2()
Protected act, tmp$
tmp$ = OpenFileRequester("Open File", GetCurrentDirectory(), "*.txt|*.txt|*.pb|*.pb;*.pbi|Все (*.*)|*.*", 1)
If Asc(tmp$)
act = GetActiveGadget()
ForEach FPCes()
If act = FPCes()\id_btn
SetGadgetText(FPCes()\id_str, tmp$)
EndIf
Next
EndIf
ProcedureReturn
EndProcedure
Procedure FilePickerCtrl(ind, label$)
AddElement(FPCes())
TextGadget(#PB_Any, 10, 30 * ind + 5, 90, 26, label$)
FPCes()\id_str = StringGadget(#PB_Any, 100, 30 * ind + 5, 300, 26, "")
FPCes()\id_btn = ButtonGadget(#PB_Any, 400, 30 * ind + 5, 26, 26, Chr($2026))
BindGadgetEvent(FPCes()\id_btn, @OpenFile2())
ProcedureReturn FPCes()\id_str
EndProcedure
#ok = 0
Define id_str0, id_str1, id_str2
If OpenWindow(0, 0, 0, 430, 300, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
id_str0 = FilePickerCtrl(0, "Select a file:")
id_str1 = FilePickerCtrl(1, "Select a file:")
id_str2 = FilePickerCtrl(2, "Select a file:")
ButtonGadget(#ok, (430 - 60) / 2, 300 - 50, 60, 40, "OK")
;- Loop
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case #ok
Debug GetGadgetText(id_str0)
Debug GetGadgetText(id_str1)
Debug GetGadgetText(id_str2)
EndSelect
Case #PB_Event_CloseWindow
CloseWindow(0)
End
EndSelect
ForEver
EndIf
Re: File picker gadgets in native PureBasic?
Posted: Wed Mar 13, 2024 3:56 am
by Quin
This does exactly what I want, thanks a ton!
AZJIO wrote: Wed Mar 13, 2024 3:53 am
You have to do it yourself
Code: Select all
Structure Element
id_btn.i
id_str.i
EndStructure
Global NewList FPCes.Element()
Procedure OpenFile2()
Protected act, tmp$
tmp$ = OpenFileRequester("Open File", GetCurrentDirectory(), "*.txt|*.txt|*.pb|*.pb;*.pbi|Все (*.*)|*.*", 1)
act = GetActiveGadget()
ForEach FPCes()
If act = FPCes()\id_btn
SetGadgetText(FPCes()\id_str, tmp$)
EndIf
Next
ProcedureReturn
EndProcedure
Procedure FilePickerCtrl(ind, label$)
Protected id_btn, id_str
TextGadget(#PB_Any, 10, 30 * ind + 5, 90, 26, label$)
id_str = StringGadget(#PB_Any, 100, 30 * ind + 5, 300, 26, "")
id_btn = ButtonGadget(#PB_Any, 400, 30 * ind + 5, 26, 26, Chr($2026))
BindGadgetEvent(id_btn, @OpenFile2())
AddElement(FPCes())
FPCes()\id_btn = id_btn
FPCes()\id_str = id_str
ProcedureReturn id_str
EndProcedure
#ok = 0
Define id_str0, id_str1, id_str2
If OpenWindow(0, 0, 0, 430, 300, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
id_str0 = FilePickerCtrl(0, "Select a file:")
id_str1 = FilePickerCtrl(1, "Select a file:")
id_str2 = FilePickerCtrl(2, "Select a file:")
ButtonGadget(#ok, (430 - 60) / 2, 300 - 50, 60, 40, "OK")
;- Loop
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case #ok
Debug GetGadgetText(id_str0)
Debug GetGadgetText(id_str1)
Debug GetGadgetText(id_str2)
EndSelect
Case #PB_Event_CloseWindow
CloseWindow(0)
End
EndSelect
ForEver
EndIf
Re: File picker gadgets in native PureBasic?
Posted: Wed Mar 13, 2024 4:05 am
by BarryG
Can someone show me (with comparison screenshots) what I'm missing here? We're still using OpenFileRequester() as I originally said?
Re: File picker gadgets in native PureBasic?
Posted: Wed Mar 13, 2024 4:08 am
by Quin
What I was talking about creating was the UI before that dialog is displayed to the user (i.e. the area with the TextGadget(), StringGadget(), and ButtonGadget()). wxPython had a standalone construct for this, and I wondered if PB/the Windows API did too.
BarryG wrote: Wed Mar 13, 2024 4:05 am
Can someone show me (with comparison screenshots) what I'm missing here? We're still using OpenFileRequester() as I originally said?
Re: File picker gadgets in native PureBasic?
Posted: Wed Mar 13, 2024 4:10 am
by BarryG
Oh, you mean the window itself with the gadgets. Got it. I was too focussed on "file picker gadget" in your topic title

Re: File picker gadgets in native PureBasic?
Posted: Wed Mar 13, 2024 1:47 pm
by blueb
Re: File picker gadgets in native PureBasic?
Posted: Wed Mar 13, 2024 2:03 pm
by Quin
This looks really cool, thanks for sharing! Unfortunately it doesn't run on my machine though...