From: Hidetoshi NAGAI Date: 2005-01-11T00:49:31+09:00 Subject: Re: how do I add a C widget to Ruby/Tk? Hi, From: Bill Paxton Subject: how do I add a C widget to Ruby/Tk? Date: Mon, 10 Jan 2005 02:33:05 +0900 Message-ID: > I have an existing Tcl/Tk widget written in C that I�d like to port to > Ruby/Tk. Please use your widget as it is. Ruby/Tk (tcltklib) uses standard Tcl/Tk libraries. If your wish (which uses same Tcl/Tk libraries) can load your widget library, Ruby/Tk can load the widget library. For exapmle, Tk.load_cmd_on_ip(tk_cmd) --> auto_load tk_cmd Tk.load_tclscript(file, enc=nil) --> source ?-encoding enc? file Tk.load_tcllibrary(file, pkg=None, --> load file ?pkg? ?interp? interp=None) Tk.tk_call(cmd, arg, ... ) --> cmd arg ... Tk.ip_eval(script) --> (eval "script" on Tcl/Tk ip) Probably, you'll be able to load your widget library by Tk.load_tcllibrary('your widget library'). After that, you can create and control your widgets by Tk.tk_call(). If you want create a class for your widget, it is better the class is a sub-class of TkWindow class. When the create command of your widget is "xxx path ??-opt val? ...?", minimum definition for your widget class is the following. ---------------------------------------------------------- class YOUR_WIDGET < TkWindow TkCommandNames = ['xxx'.freeze].freeze WidgetClassName = 'Xxx' # if needed WidgetClassNames[WidgetClassName] = self # if needed # define instance methods for your widget class end ---------------------------------------------------------- Then, you'll be able to create your widget by ---------------------------------------------------------- YOUR_WIDGET.new(parent, optkeys){ ... } ---------------------------------------------------------- like as other standard widgets. -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)