File picker gadgets in native PureBasic?

Just starting out? Need help? Post your questions and find answers here.
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

File picker gadgets in native PureBasic?

Post 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!
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: File picker gadgets in native PureBasic?

Post by BarryG »

Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: File picker gadgets in native PureBasic?

Post 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.
BarryG wrote: Tue Mar 12, 2024 5:06 am OpenFileRequester() -> https://www.purebasic.com/documentation ... ester.html
DarkDragon
Addict
Addict
Posts: 2347
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: File picker gadgets in native PureBasic?

Post 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.
bye,
Daniel
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: File picker gadgets in native PureBasic?

Post 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.
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: File picker gadgets in native PureBasic?

Post 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.
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: File picker gadgets in native PureBasic?

Post 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.
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: File picker gadgets in native PureBasic?

Post by BarryG »

I don't see anything in DocMaker that the PureBasic commands don't provide? It just uses OpenFileRequester() and PathRequester().
AZJIO
Addict
Addict
Posts: 2226
Joined: Sun May 14, 2017 1:48 am

Re: File picker gadgets in native PureBasic?

Post 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
Last edited by AZJIO on Wed Mar 13, 2024 4:12 am, edited 2 times in total.
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: File picker gadgets in native PureBasic?

Post 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
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: File picker gadgets in native PureBasic?

Post by BarryG »

Can someone show me (with comparison screenshots) what I'm missing here? We're still using OpenFileRequester() as I originally said?
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: File picker gadgets in native PureBasic?

Post 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?
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: File picker gadgets in native PureBasic?

Post 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 :lol:
User avatar
blueb
Addict
Addict
Posts: 1118
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: File picker gadgets in native PureBasic?

Post by blueb »

If you need a little more depth.... :mrgreen:

https://www.purebasic.fr/english/viewtopic.php?t=74350
- 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
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: File picker gadgets in native PureBasic?

Post by Quin »

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.... :mrgreen:

https://www.purebasic.fr/english/viewtopic.php?t=74350
Post Reply