--****************************************************************************** --* * --* File: TkLua_05.lua Revision: 1.0 * --* * --* Purpose: shows some window and window system details * --* * --* Creation: 12.03.2002 Last Modification: 12.03.2002 * --* * --* Platform: IBM-compatible PC running Windows 98SE * --* * --* Environment: Lua 4.0, TkLua 4.0 * --* * --* Author: Andreas Rozek Phone: ++49 (711) 6770682 * --* Kirschblütenweg 15 Fax: - * --* D-70569 Stuttgart EMail: Andreas.Rozek@T-Online.De * --* Germany * --* * --* URL: http://www.Andreas-Rozek.de/ * --* * --* Copyright: the software is published under the "GNU Lesser General Pub- * --* lic License" (see "http://www.fsf.org/copyleft/lesser.html" * --* for additional information) * --* * --* Comments: (none) * --* * --****************************************************************************** dofile("Lua_02_Lib.lua"); -- provides an extended 'tostring' function etc. dofile("TkLua_00_Lib.lua"); -- provides a simple console for TkLua programs local Icon = "./Lua.gif";-- specifying the file name is already sufficient local Title = "TkLua_05"; local Subtitle = "Screen and Window Information Display"; local Status = "(no special action required)"; local LabelFont = "-*-helvetica-bold-r-*--12"; --**** define window components **** local IconLabel = tklabel{image=Icon, anchor="center", width=32, height=32}; local TitleLabel = tklabel{Title; anchor="e", font="-*-helvetica-bold-o-*--16"}; local SubtitleLabel = tklabel{Subtitle; anchor="e", font="-*-helvetica-bold-r-*--12"}; local UpperSeparator = tkframe{relief="sunken", borderwidth=2, height=2}; local ScreenHeader = tklabel{"Screen Info:"; anchor="w", font="-*-helvetica-bold-r-*--12"}; local ScreenInfo = tkframe{ tklabel{"Display Name:"; anchor="e", font=LabelFont}, tklabel{""; anchor="w"}, "/", tklabel{"Pixel Resolution:"; anchor="e", font=LabelFont}, tklabel{""; anchor="w"}, "/", tklabel{"Screen Dimension:"; anchor="e", font=LabelFont}, tklabel{""; anchor="w"}, "/", tklabel{"Color Depth:"; anchor="e", font=LabelFont}, tklabel{""; anchor="w"}, "/", tklabel{"Palette Entries:"; anchor="e", font=LabelFont}, tklabel{""; anchor="w"}, "/", tklabel{"\"Visual\" Type:"; anchor="e", font=LabelFont}, tklabel{""; anchor="w"}; geoman="grid" }; local WindowHeader = tklabel{"Window Info:"; anchor="w", font="-*-helvetica-bold-r-*--12"}; local WindowInfo = tkframe{ tklabel{"Position:"; anchor="e", font=LabelFont}, tklabel{""; anchor="w"}, "/", tklabel{"Size:"; anchor="e", font=LabelFont}, tklabel{""; anchor="w"}, "/", tklabel{"Geometry:"; anchor="e", font=LabelFont}, tklabel{""; anchor="w"}, "/", tklabel{"Color Depth:"; anchor="e", font=LabelFont}, tklabel{""; anchor="w"}, "/", tklabel{"Palette Entries:"; anchor="e", font=LabelFont}, tklabel{""; anchor="w"}, "/", tklabel{"\"Visual\" Type:"; anchor="e", font=LabelFont}, tklabel{""; anchor="w"}; geoman="grid" }; local LowerSeparator = tkframe{relief="sunken", borderwidth=2, height=2}; local StatusBar = tklabel{Status; anchor="w", font="-*-helvetica-medium-r-*--11"}; --**** construct application window **** local MainWindow = tkmain{ tkframe{ IconLabel, {side="left"}, TitleLabel, {side="top", fill="x"}, SubtitleLabel, {side="top", fill="x"} }, {side="top", fill="x"}, UpperSeparator, {side="top", fill="x"}, ScreenHeader, {side="top", fill="x"}, ScreenInfo, {side="top", fill="x", expand=1, padx=4}, WindowHeader, {side="top", fill="x"}, WindowInfo, {side="top", fill="x", expand=1, padx=4}, LowerSeparator, {side="top", fill="x"}, StatusBar, {side="top", fill="x"} }; --**** display application window **** MainWindow:title(Title.." - "..Subtitle); MainWindow:show(); -- also triggers a window layout --MainWindow:resizable(0,0); -- disables window size changes --MainWindow:raise(); -- brings the window into the foreground --**** it's now time to fine-tune the display **** for i = 0,5 do tkeval("grid configure "..ScreenInfo.objects[i*3+1].tkname..' -sticky "e"'); tkeval("grid configure "..ScreenInfo.objects[i*3+2].tkname..' -sticky "ew"'); end; tkeval('grid columnconfigure '..ScreenInfo.tkname..' 1 -weight 1'); for i = 0,5 do tkeval("grid configure "..WindowInfo.objects[i*3+1].tkname..' -sticky "e"'); tkeval("grid configure "..WindowInfo.objects[i*3+2].tkname..' -sticky "ew"'); end; tkeval('grid columnconfigure '..WindowInfo.tkname..' 1 -weight 1'); --**** oops - we still have to fill the display with values! **** --tkeval("update idletasks"); -- guarantee actual window display tkeval("update"); -- "update idletasks" doesn't seem to be enough ScreenInfo.objects[2].text = tkeval("winfo screen "..MainWindow.tkname)[1]; ScreenInfo.objects[5].text = tkeval("winfo screenwidth "..MainWindow.tkname)[1].."x"..tkeval("winfo screenheight "..MainWindow.tkname)[1].." Pixels"; ScreenInfo.objects[8].text = tkeval("winfo screenmmwidth "..MainWindow.tkname)[1].."x"..tkeval("winfo screenmmheight "..MainWindow.tkname)[1].." mm^2"; ScreenInfo.objects[11].text = tkeval("winfo screendepth "..MainWindow.tkname)[1]; ScreenInfo.objects[14].text = tkeval("winfo screencells "..MainWindow.tkname)[1]; ScreenInfo.objects[17].text = tkeval("winfo screenvisual "..MainWindow.tkname)[1]; WindowInfo.objects[2].text = tkeval("winfo rootx "..MainWindow.tkname)[1]..","..tkeval("winfo rooty "..MainWindow.tkname)[1]; WindowInfo.objects[5].text = tkeval("winfo width "..MainWindow.tkname)[1].."x"..tkeval("winfo height "..MainWindow.tkname)[1].." Pixels"; WindowInfo.objects[8].text = tkeval("winfo geometry "..MainWindow.tkname)[1]; WindowInfo.objects[11].text = tkeval("winfo depth "..MainWindow.tkname)[1]; WindowInfo.objects[14].text = tkeval("winfo cells "..MainWindow.tkname)[1]; WindowInfo.objects[17].text = tkeval("winfo visual "..MainWindow.tkname)[1]; --**** provide an explicit method to terminate this program! **** MainWindow:protocol("WM_DELETE_WINDOW", "print('done...'); tkexit()");