File picker gadgets in native PureBasic?
File picker gadgets in native PureBasic?
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!
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?
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.
BarryG wrote: Tue Mar 12, 2024 5:06 am OpenFileRequester() -> https://www.purebasic.com/documentation ... ester.html
-
DarkDragon
- Addict

- Posts: 2347
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: File picker gadgets in native PureBasic?
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.
bye,
Daniel
Daniel
Re: File picker gadgets in native PureBasic?
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?
Got a screenshot? Because I have no idea which file picker you're talking about.Quin wrote: Tue Mar 12, 2024 5:27 pmI meant the super generic-looking browse for file control you super commonly see
Re: File picker gadgets in native PureBasic?
Not a screenshot, but you see multiple of them if you open PureBasic/sdk/DocMaker/DocMaker.exe.
Re: File picker gadgets in native PureBasic?
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?
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
Last edited by AZJIO on Wed Mar 13, 2024 4:12 am, edited 2 times in total.
Re: File picker gadgets in native PureBasic?
This does exactly what I want, thanks a ton!
AZJIO wrote: Wed Mar 13, 2024 3:53 am You have to do it yourselfCode: 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?
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?
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?
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?
- It was too lonely at the top.
System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
Re: File picker gadgets in native PureBasic?
This looks really cool, thanks for sharing! Unfortunately it doesn't run on my machine though...
blueb wrote: Wed Mar 13, 2024 1:47 pm If you need a little more depth....![]()
https://www.purebasic.fr/english/viewtopic.php?t=74350