alternative to assert
[gtkD.git] / demos / duit / TestImage.d
blobb5f49e38c36c943df976b946668899ae0f8b7e2e
1 /*
2 * This file is part of dui.
3 *
4 * dui is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
8 *
9 * dui is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with dui; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 module duit.TestImage;
21 private import gtk.VBox;
23 private import gtk.Table;
24 private import gtk.FileChooserDialog;
25 private import gtk.Button;
26 private import gtk.Widget;
27 private import gtk.ScrolledWindow;
28 private import gtk.ButtonBox;
29 private import gtk.HButtonBox;
30 private import gtk.Image;
32 private import gtk.Window;
34 private import gtk.gtktypes;
36 private import std.stdio;
38 private import glib.Str;
40 /**
41 * This tests the DUI loading and display and image file
43 class TestImage : VBox
45 Table table;
46 FileChooserDialog fs;
47 ScrolledWindow sw;
49 Window window;
51 this(Window window)
53 this.window = window;
54 debug(1)
56 printf("instantiating TestImage\n");
59 super(false,8);
61 sw = new ScrolledWindow(null,null);
63 sw.addWithViewport(initTable());
65 ButtonBox hBox = HButtonBox.createActionBox();
66 Button loadDir = new Button("Load Files", &loadImages);
67 hBox.packStart(loadDir,false,false,0);
69 packStart(sw,true,true,0);
70 packStart(hBox,false,false,0);
74 Table initTable()
77 // I don't think D can read the content of a directory yet
78 // so here it is
79 char[][] pngs;
81 pngs ~= "/home/ruimt/devel/D/DUI/images/duiIcon_t.xpm";
82 pngs ~= "/home/ruimt/devel/D/DUI/images/duiLogo.gif";
83 pngs ~= "/home/ruimt/devel/D/DUI/images/duiLogo.xpm";
84 pngs ~= "/home/ruimt/devel/D/DUI/images/duiLogo_2.xpm";
85 pngs ~= "/home/ruimt/devel/D/DUI/images/duiLogo_4.xpm";
86 pngs ~= "/home/ruimt/devel/D/DUI/images/duiLogo_8.xpm";
88 return loadTable(pngs);
91 private Table loadTable(char[][] imageFiles)
93 //Table table = new Table(1,1,false);
94 if ( table is null )
96 table = new Table(1,1,false);
98 else
100 table.removeAll();
104 int row = 0;
105 int col = 0;
107 Image image;
110 // Window progressWindow = new Window();//WindowType.POPUP);
111 // progressWindow.setBorderWidth(10);
112 // ProgressBar progressBar = new ProgressBar();
113 // progressWindow.add(progressBar);
114 // progressWindow.show();
117 for ( int i=0 ; i<imageFiles.length ;i++)
119 char[] fileName = imageFiles[i];
120 if ( fileName[0] != '/' )
122 version(linux) fileName = fileName ~ "/usr/share/pixmaps/";
123 version(Windows) fileName = fileName ~ "C:\\Projects\\D\\DynDUI\\dui\\images\\";
125 image = new Image(fileName);
126 //image.addOnEnterNotify(&onEnter);
127 //image.addOnLeaveNotify(&onLeave);
128 writefln("adding image %s to table at %s,%s", fileName, col, row);
129 table.resize(col+1, row+1);
130 table.attach(image,col,col+1,row,row+1,AttachOptions.FILL,AttachOptions.FILL,4,4);
131 ++col;
132 if ( col == 8 )
134 col = 0;
135 ++row;
139 return table;
142 private import glib.ListSG;
144 void loadImages(Button button)
146 if ( fs is null )
148 char[][] a;
149 ResponseType[] r;
150 a ~= "Lets go!";
151 a ~= "Please don't";
152 r ~= ResponseType.GTK_RESPONSE_ACCEPT;
153 r ~= ResponseType.GTK_RESPONSE_CANCEL;
154 fs = new FileChooserDialog("File Selection", window, FileChooserAction.OPEN, a, r);
156 fs.getFileChooser().setSelectMultiple(true);
157 ResponseType response = cast(ResponseType) fs.run();
158 if ( response == ResponseType.GTK_RESPONSE_ACCEPT )
160 char[][] fileNames;
161 ListSG list = fs.getFileChooser().getFilenames();
164 for ( int i = 0; i<list.length() ; i++)
166 writefln("Testmage.loadImages.File selected = %s",
167 Str.toString(cast(char*)list.nthData(i)));
168 fileNames ~= Str.toString(cast(char*)list.nthData(i)).dup;
171 loadTable(fileNames);
173 fs.hide();
176 void onEnter(Widget widget)
178 printf("TestImage.mouseEnterNotify\n");
179 return true;
181 void onLeave(Widget widget)
183 printf("TestImage.mouseLeaveNotify\n");
184 return true;