Create a file-selector dialog
int PtFileSelection( PtWidget_t *parent,
PhPoint_t const *pos,
char const *title,
char const *root_dir,
char const *file_spec,
char const *btn1,
char const *btn2,
char const *format,
PtFileSelectionInfo_t *info,
int flags );
This function creates a file selector dialog that lets the user browse files and directories. The dialog allows the selection of a file and/or directory and fills a PtFileSelectionInfo_t structure with information about the selected item and the dialog.
This function has its own event-processing loop.
The arguments are as follows:
If you want to have a hotkey for this button, place an ampersand (&) in front of the appropriate character in the string. For example, to have the string Select with s as a hotkey, pass &Select as btn1.
The PtFileSelection() function creates a dialog to simplify file and directory selection:

An example of the dialog created by PtFileSelection().
The dialog is positioned according to the pos parameter: if NULL, the dialog is centered on the screen; if parent is NULL, the dialog is placed at the absolute coordinates of pos; otherwise it's placed at the relative offset of pos within parent.
You can specify the dimensions of the dialog by setting the info->dim field before calling this function.
The dialog consists of:
#include <Pt.h>
#include <photon/PtFileSel.h>
#include <sys/stat.h>
#include <string.h>
#include <stdio.h>
// global widget pointers
PtWidget_t *window, *sel_btn, *quit_btn,
*label, *sel_label;
// info structure for the dialog
PtFileSelectionInfo_t in;
// default position for the dialog
PhPoint_t pos = {100, 100};
// format string to be reused
char format[80];
int
make_fs( PtWidget_t *widget,
struct fs_dialog_modal *user,
PtCallbackInfo_t *info)
{
PtArg_t args[1];
int err;
// make the file selection dialog
err = PtFileSelection(window, &pos,
NULL, "/", NULL, "&Select",
"&Done", format, &in,
Pt_FSDIALOG_NO_FCHECK);
// save the position and format for making a future dialog
pos.x = in.pos.x;
pos.y = in.pos.y;
strcpy(format, in.format);
PtSetArg(&args[0], Pt_ARG_TEXT_STRING,
"The Selected file was:", 0);
PtSetResources(label, 1, args);
PtSetArg(&args[0], Pt_ARG_TEXT_STRING, in.path, 0);
PtSetResources(sel_label, 1, args);
return(Pt_CONTINUE);
}
void
quit( PtWidget_t *widget,
struct fs_dialog_modal *user,
PtCallbackInfo_t *info)
{
exit (EXIT_SUCCESS);
}
main()
{
PtArg_t args[10];
PhArea_t area;
PhDim_t dim = { 300, 200 };
in.dim.w = 0;
in.dim.h = 0;
// setup a default format string
strcpy(format, "nsd");
// make the main window
PtSetArg( &args[0], Pt_ARG_WINDOW_TITLE,
"PtFileSelector Demo", 0 );
PtSetArg( &args[1], Pt_ARG_DIM, &dim, 0 );
window = PtAppInit( NULL, NULL, NULL, 2, args );
// make a label
area.pos.x = 20;
area.pos.y = 30;
PtSetArg( &args[0], Pt_ARG_POS, &area.pos, 0 );
PtSetArg( &args[1], Pt_ARG_TEXT_FONT, "helv12b", 0 );
PtSetArg( &args[2], Pt_ARG_TEXT_STRING,
"There is no selected file", 0);
label = PtCreateWidget( PtLabel, window, 3, args );
// make a second label
area.pos.x = 30;
area.pos.y = 60;
PtSetArg( &args[0], Pt_ARG_POS, &area.pos, 0 );
PtSetArg( &args[1], Pt_ARG_TEXT_FONT, "helv12b", 0 );
sel_label = PtCreateWidget( PtLabel, window, 2, args );
// make a button for selecting files
area.size.w = 80;
area.size.h = 20;
area.pos.x = 120;
area.pos.y = 170;
PtSetArg( &args[0], Pt_ARG_AREA, &area, 0 );
PtSetArg( &args[1], Pt_ARG_TEXT_STRING, "Select File", 0);
sel_btn = PtCreateWidget( PtButton, window, 2, args );
PtAddCallback(sel_btn, Pt_CB_ACTIVATE, &make_fs, NULL);
// make a button for quitting
area.size.w = 80;
area.size.h = 20;
area.pos.x = 210;
area.pos.y = 170;
PtSetArg( &args[0], Pt_ARG_AREA, &area, 0 );
PtSetArg( &args[1], Pt_ARG_TEXT_STRING, "Quit", 0);
quit_btn = PtCreateWidget( PtButton, window, 2, args );
PtAddCallback(quit_btn, Pt_CB_ACTIVATE, &quit, NULL);
PtRealizeWidget( window );
PtMainLoop();
}
Photon
| Safety: | |
|---|---|
| Interrupt handler | No |
| Signal handler | No |
| Thread | No |