--****************************************************************************** --* * --* File: TkLua_01.lua Revision: 1.0 * --* * --* Contents: a simple system color display * --* * --* Creation: 06.03.2002 Last Modification: 06.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_01"; local Subtitle = "a simple system color display"; Status = "click on a color to see its RGB definition"; ColorList = { "SystemActiveBorder", "SystemActiveCaption", "SystemAppWorkspace", "SystemBackground", "SystemButtonFace", "SystemButtonHighlight", "SystemButtonShadow", "SystemButtonText", "SystemCaptionText", "SystemDisabledText", "SystemHighlight", "SystemHighlightText", "SystemInactiveBorder", "SystemInactiveCaption", "SystemInactiveCaptionText", "SystemMenu", "SystemMenuText", "SystemScrollbar", "SystemWindow", "SystemWindowFrame", "SystemWindowText" }; --****************************************************************************** --* * --* ColorSpec retrieves RGB (background) color definition of a given widget * --* * --****************************************************************************** function ColorSpec (Widget) local Definition = tkeval("winfo rgb",Widget.tkname,Widget.background); return floor(Definition[1]/256)..","..floor(Definition[2]/256)..","..floor(Definition[3]/256); end; --****************************************************************************** --* * --* main program * --* * --****************************************************************************** --**** 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 ViewList = {}; -- receives a list of color views local Index, Column = 1,0; for Index = 1,getn(ColorList) do Column = Column + 1; tinsert(ViewList, tkframe{ tklabel{ColorList[Index]}, {side="left", anchor="e", fill="x", expand=1}, tkframe{relief="sunken", borderwidth=1, width=16, height=16, background=ColorList[Index], ColorName=ColorList[Index]}, {side="left", anchor="w", padx=1}; }); ViewList[ViewList.n][3]:bind( -- bind some events to the color square "", "StatusBar.text=self.ColorName" ); ViewList[ViewList.n][3]:bind( "", "StatusBar.text=Status" ); ViewList[ViewList.n][3]:bind( "", "StatusBar.text=self.ColorName..' ('..ColorSpec(self)..')'" ); -- tinsert(ViewList, {sticky="e"}); -- doesn't seem to work! if (Column == 3) then tinsert(ViewList, "/"); -- start a new row Column = 0; end; end; local ColorView = tkframe{objects=ViewList, borderwidth=0, geoman="grid"}; local LowerSeparator = tkframe{relief="sunken", borderwidth=2, height=2}; 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"}, ColorView, {side="top", fill="both", expand=1, pady=2}, 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 = 1,getn(ViewList) do local tkname = ViewList[i].tkname; if (tkname ~= nil) then -- take care of layout descriptors tkeval('grid configure '..ViewList[i].tkname..' -sticky "e"'); end; end; --**** provide an explicit method to terminate this program! **** MainWindow:protocol("WM_DELETE_WINDOW", "print('done...'); tkexit()");