A custom File & Folder selector.

Under development: PCMCIA, wireless, etc.
Message
Author
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

A custom File & Folder selector.

#1 Post by sunburnt »

I made this exec. popup selector to replace xdialog and GTK+ FileDialog.

It`s simple, but is more straightforward and not nearly as ugly as xDialog.
If there`s interest I`ll add filtering for: hidden, extensions, and file types.

Being as it`s a exec., I`m also going to add help ( none yet ).
One optional argument for the path the dialog starts in, defaults to $HOME

Usage: /path/FileDlg [dialog open /path]

BaCon web site: http://www.basic-converter.org/
BaCon forum: http://basic-converter.proboards.com/

### New version:
I`ve added to it using a path.conf file so it can remember it`s /path.
To use this feature, make a blank file: /(FileDlgPath)/path.conf
And added a /path label.
Still no cli help ( sorry ), or any file filtering.
Attachments
0_FileDlg.png
(20.47 KiB) Downloaded 1280 times
FileDlg.gz
(48.85 KiB) Downloaded 386 times
Last edited by sunburnt on Sun 11 Aug 2013, 05:17, edited 3 times in total.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#2 Post by Karl Godt »

I have learned to live with the Xdialog fileselect .

Problem was mainly that authors some hundred years ago, when Puppy was intended to run on 1-inch display smartphones, made it look crippled by putting in some too weird tiny screen dimensions in them .

Your exec looks ok to me - it's slightly bit big ( stripped 162KB ) - but that does not matter to me .

What I could not find out about was the input line and the Open button .

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#3 Post by sunburnt »

Hey Karl; I guess I should have used an "OK" button.

And I`ll have to add a "selected /path(/file)" text box too for a visual.

The input line is for new file and folder names ( need a label for that...).

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#4 Post by amigo »

Xdialog simply calls the built-in GTK file-selector widget. How about posting your sources?

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#5 Post by sunburnt »

amigo; I`d love to use some of GTK`s higher level widgets.
But BaCon doesn`t have them, although it can import GTK code.
I`ve tried a few times to make that work, but I have fits with the GTK code.

Gtk-Server does a lot of widgets and properties, also by the BaCon author.
GtkDialog has many widgets and properties, but it`s Puppy only.

This file selector simply uses 2 list boxes. At least I can control all of it.
As I said, the GTK FileDialog looks and works good, but it opens to the
OS`s "recently used files" and there seems to be no controlling it.

BaCon web site: http://www.basic-converter.org/
BaCon forum: http://basic-converter.proboards.com/

I`ve added to it using a path.conf file so it can remember it`s /path.
To use this feature, make a blank file: (appPath)/path.conf
And added a /path label.
Still no cli help ( sorry ), or any file filtering.

Here`s the new "FileDlg.bac", I didn`t post it because it`s fairly long.

Code: Select all

'###	FileDlg.bac		File open, save, new file, and new folder.

'#					Terry Becker	SunBurnt	Aug. 9  2013


INCLUDE "/root/0_BaCon/BaCon/hug.bac",INIT,DISPLAY,WINDOW,LIST,STOCK,BUTTON \
		,HUGENTRY,MARK,FRAME,FONT,ATTACH,CALLBACK,TEXT,GRAB$
INIT


'###############	NEED File & Folder Filtering: Hidden, Extensions, & Type.


												' # Close button.
SUB btnClose
	END
END SUB
												' # Ok button.
SUB btnOk
	PRINT GRAB$(txtPF_)
													' write /path to path.conf
	IF FILEEXISTS(confP$) THEN
		OPEN confP$ FOR WRITING AS file_
			WRITELN path$ TO file_
		CLOSE FILE file_
	END IF
	END
END SUB
												' # Refresh ListBox.
SUB refLists
	LOCAL p$
	p$ = path$
PRINT p$
	IF p$ != "/" THEN p$ = LEFT$(p$, LEN(p$)-1)
	TEXT(txtPF_, p$)
	TEXT(lstDir_, "")
	IF path$ != "/" THEN TEXT(lstDir_, "..")
	TEXT(lstFile_, "")
	cmd$ = "find " & path$ & " -maxdepth 1 -type d |sed s'#^.*/##;1,1d' |sort"
	SPLIT CHOP$(EXEC$(cmd$)) BY NL$ TO dirs$ SIZE dirSz
	FOR i = 0 TO dirSz-1
		TEXT(lstDir_, dirs$[i])
	NEXT
	cmd$ = "find " & path$ & " -maxdepth 1 -type f |sed s'#^.*/##' |sort"
	SPLIT CHOP$(EXEC$(cmd$)) BY NL$ TO files$ SIZE fileSz
	FOR i = 0 TO fileSz-1
		TEXT(lstFile_, files$[i])
	NEXT
END SUB
												' # Dir. list click.
SUB lstDir
	LOCAL d$
	IF lstFlg = 1 THEN
		lstFlg = 0
		EXIT SUB
	END IF
	d$ = GRAB$(lstDir_)
	lstFlg = 1
	IF RIGHT$(path$, 1) != "/" THEN path$ = path$ & "/"
	IF d$ != ".." THEN
		path$ = path$ & d$ & "/"
	ELSE
		path$ = LEFT$(path$, INSTRREV(path$, "/", 2))
	END IF
	refLists
'	PRINT " Dir.:  ", d$, "   ", path$
END SUB
												' # File list click.
SUB lstFile
	LOCAL f$
	f$ = GRAB$(lstFile_)
'	PRINT " File:  ", f$
END SUB
												' # New dir. button.
SUB btnNewDir
	LOCAL d$
	d$ = GRAB$(txtNew_)
PRINT d$
	IF d$ = "" THEN
		PRINT NL$, "###  ERROR:  No new folder input.", NL$
	ELIF FILEEXISTS(path$ & d$) THEN
		PRINT NL$, "###  ERROR:  Folder already exists:  ", d$, NL$
	ELSE
		MAKEDIR path$ & d$
		TEXT(txtNew_, "")
		refLists
	END IF
END SUB
												' # New file button.
SUB btnNewFile
	LOCAL f$
	f$ = GRAB$(txtNew_)
PRINT f$
	IF f$ = "" THEN
		PRINT NL$, "###  ERROR:  No new file name input.", NL$
	ELIF FILEEXISTS(path$ & f$) THEN
		PRINT NL$, "###  ERROR:  File already exists:  ", f$, NL$
	ELSE
		OPEN path$ & f$ FOR WRITING AS file_
			WRITELN "" TO file_
		CLOSE FILE file_
		TEXT(txtNew_, "")
		refLists
	END IF
END SUB

													' cmd. args.: dialog path
SPLIT ARGUMENT$ BY " " TO arg$ SIZE argSz

appP$ = LEFT$(arg$[0], INSTRREV(arg$[0], "/"))			: ' get app`s /path
														' file path.conf exists
IF argSz = 1 THEN
	confP$ = appP$ & "path.conf"
	IF FILEEXISTS(confP$) THEN
		OPEN confP$ FOR READING AS file_
			READLN path$ FROM file_
		CLOSE FILE file_
		IF NOT(FILEEXISTS(path$)) THEN
			path$ = GETENVIRON$("HOME")
		END IF
	ELSE												: ' no conf., get $HOME
		path$ = GETENVIRON$("HOME")
	END IF												: ' command arg. /path
ELIF argSz > 1 THEN
	IF FILEEXISTS(arg$[1]) THEN
		path$ = arg$[1]
	ELSE
		path$ = GETENVIRON$("HOME")
		PRINT NL$, "###  ERROR:  Bad /path argument.", NL$
	END IF
END IF
IF RIGHT$(path$, 1) != "/" THEN path$ = path$ & "/"

winW = 500 : winH = 400

win_ = WINDOW(" Filer Dialog", winW, winH)

per = winW / 10		: panH = winH - 110

lstDir_ = LIST(per*4, panH)
	ATTACH(win_, lstDir_, 0, 0) : CALLBACK(lstDir_, lstDir)

lstFile_ = LIST(per*6, panH)
	ATTACH(win_, lstFile_, per*4, 0) : CALLBACK(lstFile_, lstFile)

frmY = winH - 100
frm_ = FRAME(winW-20, 55)
	ATTACH(win_, frm_, 10, frmY)
TEXT(frm_, "  Make New Files and Folders  ")

y = frmY + 20
txtNew_ = HUGENTRY("", winW-205, 25) : ATTACH(win_, txtNew_, 20, y)

btnNewFile_ = BUTTON("New File", 65, 25)
	ATTACH(win_, btnNewFile_, winW-175, y) : CALLBACK(btnNewFile_, btnNewFile)

btnNewDir_ = BUTTON("New Folder", 80, 25)
	ATTACH(win_, btnNewDir_, winW-100, y) : CALLBACK(btnNewDir_, btnNewDir)

y = winH - 35
'txtPF_ = ENTRY("", winW-180, 25) : ATTACH(win_, txtPF_, 10, y)
txtPF_ = MARK("", winW-180, 25) : ATTACH(win_, txtPF_, 10, y)
FONT(txtPF_, "Arial 15 bold")

btnOk_ = STOCK("gtk-ok", 60, 25)
	ATTACH(win_, btnOk_, winW-160, y) : CALLBACK(btnOk_, btnOk)

btnClose_ = STOCK("gtk-close", 80, 25)
	ATTACH(win_, btnClose_, winW-90, y) : CALLBACK(btnClose_, btnClose)

refLists
DISPLAY
### NOTE: There must be a blank line at the end of BaCon files.!
.
Last edited by sunburnt on Sun 11 Aug 2013, 16:58, edited 3 times in total.

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#6 Post by vovchik »

@ Terry,

Useful little dialog. Thanks.

@ Karl

To make the binary smaller, use the following compile line:

Code: Select all

 bacon -o -s -o -Os -o -fdata-sections -o -ffunction-sections -o -Wl,--gc-sections "$myfile"
Then use UPX to shrink the binary further. This yields a 32-bit executable of 22k. There is no run-time detriment or down side, except a nice, small size. :)

With kind regards,
vovchik

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#7 Post by sunburnt »

vovchik; Thanks for the "shrink bacon exec." pointer.
Could you post code to UPX it also?
And I noticed that my Puppy version doesn`t have UPX.

Also... Who at the BaCon site is best at understanding and importing GTK.?
Besides Peter himself that is...
I need code for the widget`s import lines and many of it`s useful properties.
We need hug type libraries of higher level widgets, and to add properties.
Gtk-Server has a lot in it, but I can`t get the GTK code to work in BaCon.
Main ones: menu, tree, table, popbuttons, ( rich text & charts, if exist...), etc.
.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#8 Post by Karl Godt »

http://upx.sourceforge.net/download/00-OLD-VERSIONS/
http://upx.sourceforge.net/
I remember It compiled fine .
Cannot remember
Source code (you will need UCL)
http://www.oberhumer.com/opensource/ucl/ anymore .

It's upx -9 binary .
Like any other packer (gzip, bzip2, ..)
Makes an exe 40-50% smaller in -9 mode . Some bins seem to run slower though ( busybox ) .

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#9 Post by mikeb »

Hmm perhaps this might be of interest
http://code.google.com/p/yad/

Highly customisable file dialogs plus other goodies such as calender, list boxes, forms, systray icon, slider, progress etc.
Some interesting ideas on site for such as a usb automounter gui and a tail/log box. All done in c and gtk so same dependencies as other simple gtk apps. I knocked up a binary of 0.9.1 as this will work on gtk 2.12+ . It came out at 74k stripped. see --help for options or the website.

yad --file-selection --file-filter=*.c --geometry=500x400+50+5
sample command line produces the screenshot
and returns the selected file on ok.

mike

edit updated download to include a bugfix found in a later version that may affect use
Attachments
Yad-v3.tar.gz
(31.9 KiB) Downloaded 393 times
yad.png
(29.65 KiB) Downloaded 1075 times
Last edited by mikeb on Tue 27 Aug 2013, 21:22, edited 1 time in total.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#10 Post by greengeek »

Does this permit "single-click" operation or is it still restricted to double-click use like previous file-choosers?

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#11 Post by mikeb »

Does this permit "single-click" operation or is it still restricted to double-click use like previous file-choosers?
Well on Slax my gtk2 filebrowser shortcuts are single click but on puppy (same gtk version) they are double click so perhaps this is a system issue. A new thread entitled 'why is puppy odd?' would be a good idea.

mike

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#12 Post by sunburnt »

Thanks mikeb, I`ve thought about yad but never looked at it.
My Puppy already has it.
Your pic shows the same "Recent", is it the default path at startup?

Karl; Thanks dude, I downloaded it, and I`ll look at it.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#13 Post by mikeb »

Well after noticing your thread i decided to nosy around the net and came across it. It looks like a useful bag of tricks and fills in some blanks left by gtkdialog and others for script writers. I will have a play with some existing guis when I get a chance though gui from command line rather than xml seems quite appealing and simple. The form widget especially so. Ease of use and low requirements are the aim while providing a myriad of options.

I tested out an older release to get earlier gtk compatability but it also means its simpler (less gtk3 etc) as it seems to me something that could be forked for puppy purposes.... lose some features and add others.
Your pic shows the same "Recent", is it the default path at startup?
opening folder (and file) is configurable as is extension filter and save file / folder only modes.... stuff I have wanted in the past with gtkdialog...though the latter can have a default folder setting as I discovered.

mike

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#14 Post by sunburnt »

mikeb; Lots of possibilities, too many to notice them all.
I`m going to look at yad, looks like a possible replacement for GtkDialog.

Initial look at yad looks so so, yad --list is only a dialog with 2 buttons, no list.
And the file dialog doesn`t seem to have any startup other than "Recent".
I`ll go to the web site and see if there`s more to it.

My main thrust here is lack of control over even simple dialogs.
Building them yourself allows you to do almost anything.
GTK+ has lots of methods and properties, but only C can access them.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#15 Post by mikeb »

Try yad --help-all .... all will unfold...the 2 button gui does make you wonder what its all about :D

sample...
tail -f /tmp/tag.txt | /tmp/usr/bin/yad --text-info --tail
makes a log box like gtklogfileviewer.
You can pipe for the purposes of a non redrawing drive gui....
check out the site for some interesting uses.
GTK+ has lots of methods and properties, but only C can access them.
which yad seems to provide just that framework...bear in mind my test sample is version 0.9.1 and its up to 0.22....
Not sure about replacing gtkdialog but it certainly would supply a good set of widgets to get as near to using c as possible for scripts and less problems with variable handling and function nestng and so on. Plus visually working with gtkdialog all would appear seamless... one to suck and see...
edit......perhaps a fresh thread is needed to give examples of usage rather than this serious hyjacking that seems to have occured...
mike

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#16 Post by Karl Godt »

I think yad became temporary popular in the later Lupu aera .

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#17 Post by mikeb »

I think yad became temporary popular in the later Lupu aera .
Perhaps like many things it became bloated, silly and incompatible with anything more than a week old... hence my suggestion to fork an older release... cut the crap as we say in guatamala....

mike

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#18 Post by sunburnt »

Highjacking`s perfectly fine, I like a good discussion... :)

A forum thread with Yad examples would be good, but perhaps belated.
I Googled it and couldn`t make heads or tails of it, seems poorly organized.

I`m thinking that a higher level wrapper around Gtk-Server would be great.
It`d take someone with GTK+ experience to write the new syntax wrapper.
.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#19 Post by mikeb »

Ok hijack it is....

the form dialog sample....

yad --form --field=Entry --field=Password:H --field=Mode:CB --field=Color:CLR --field=Amount:NU --field=Invert:CHK --field=Source:FL --field=Folder:DIR --field=Font:FN --item-separator='|' '' '' 'up|down'

Note the data added at the end for any defaults in order of widgets.

Ok produces
mike|cheese|down|#efac1cb61cb6|12.000000|TRUE|/root/hd.img|/mnt/hda3|Sans 12|

I found gtkserver promising but clumsy in the end.
The yad wiki seems ok but I mainly worked from the command line help.

mike
Attachments
form.png
(17.98 KiB) Downloaded 416 times

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#20 Post by sunburnt »

Thanks mikeb; This looks exactly like a general purpose GUI maker I wrote in BaCon.
Vertical layout of widgets only in the first version, but simpler syntax.
And the combined return line, I`ve used something like it before.

Yep, clumsy is a good description, and so the idea for a wrapper to enhance it.

Post Reply