### Install TickleSharp to System Library Path Source: https://context7.com/ray2501/ticklesharp/llms.txt This bash script copies the compiled TickleSharp shared library and .NET DLL to the system's local library path and updates the dynamic linker cache. ```bash #!/bin/bash # install.sh - Install TickleSharp to system library path cp bin/libtclwrapper.so /usr/local/lib64/libtclwrapper.so cp bin/TickleSharp.dll /usr/local/lib64/TickleSharp.dll ldconfig ``` -------------------------------- ### Access Callback Parameters with GetArgArray and GetParam Source: https://context7.com/ray2501/ticklesharp/llms.txt Retrieves and iterates through parameters passed from Tcl to a .NET command. Parameter 0 is reserved for the argument count, while actual arguments start at index 1. ```csharp using System; using TickleSharp; public class ParamExample { static Tcl tcl; public static void Main(string[] args) { tcl = new Tcl(); // Register command that accepts multiple parameters tcl.CreateCommand("CSharpProc", new TclTkInterface.Tcl_CmdProc(HandleParams)); // Call the command with various parameters tcl.Eval("CSharpProc {Neo} {Smith} {Matrix} {42}"); } public static int HandleParams(int ArgArrInst) { // Get argument array name for this invocation string argv = tcl.GetArgArray("CSharpProc", ArgArrInst); // Get parameter count (includes command name) int paramCount = int.Parse(tcl.GetParam(argv, 0)); Console.WriteLine($"Total arguments: {paramCount}"); // Iterate through all parameters for (int i = 1; i < paramCount; i++) { string param = tcl.GetParam(argv, i); Console.WriteLine($"Parameter {i}: {param}"); } // Output: // Total arguments: 5 // Parameter 1: Neo // Parameter 2: Smith // Parameter 3: Matrix // Parameter 4: 42 // Clean up argument array to prevent memory leaks tcl.FreeArgArray(argv); return 0; } } ``` -------------------------------- ### Manage Window Geometry and Size in C# Source: https://context7.com/ray2501/ticklesharp/llms.txt Demonstrates setting window dimensions and positions using SetWindowGeometry, SetWindowSize, and SetWindowPos. Includes command registration for dynamic resizing. ```csharp using System; using TickleSharp; public class WindowManagement { static Tk tk; public static void Main(string[] args) { tk = new Tk(); // Set complete geometry: width=800, height=600, x=100, y=50 tk.SetWindowGeometry(".", 800, 600, 100, 50); // Or set size only (window position determined by window manager) tk.SetWindowSize(".", 640, 480); // Or set position only (preserves current size) tk.SetWindowPos(".", 200, 100); // Set window title tk.SetTitleBar(".", "Window Management Demo"); // Create control buttons tk.CreateCommand("resizeSmall", new TclTkInterface.Tcl_CmdProc(ResizeSmall)); tk.CreateCommand("resizeLarge", new TclTkInterface.Tcl_CmdProc(ResizeLarge)); tk.CreateCommand("minimize", new TclTkInterface.Tcl_CmdProc(Minimize)); tk.Eval("button .small -text {Small (320x240)} -command resizeSmall"); tk.Eval("button .large -text {Large (800x600)} -command resizeLarge"); tk.Eval("button .min -text {Minimize} -command minimize"); tk.Eval("pack .small .large .min -pady 5"); tk.Run(); } public static int ResizeSmall(int inst) { tk.SetWindowSize(".", 320, 240); return 0; } public static int ResizeLarge(int inst) { tk.SetWindowSize(".", 800, 600); return 0; } public static int Minimize(int inst) { tk.MinimizeWindow("."); return 0; } } ``` -------------------------------- ### Initialize Tcl Interpreter in C# Source: https://context7.com/ray2501/ticklesharp/llms.txt Demonstrates creating a Tcl interpreter instance, evaluating commands, and managing variables. ```csharp using System; using TickleSharp; public class TclExample { static Tcl tcl; public static void Main(string[] args) { // Create a new Tcl interpreter instance tcl = new Tcl(); // Evaluate Tcl commands - outputs "Hello World!" int result = tcl.Eval("puts {Hello World!}"); Console.WriteLine($"Return code: {result}"); // 0 = TCL_OK // Set and get variables tcl.Eval("set myvar {This is a test value}"); string value = tcl.GetVar("myvar"); Console.WriteLine(value); // "This is a test value" // Modify variable from .NET tcl.SetVar("myvar", "Modified from C#"); Console.WriteLine(tcl.GetVar("myvar")); // "Modified from C#" // Get evaluation result tcl.Eval("expr {2 + 2}"); Console.WriteLine($"Result: {tcl.Result}"); // "4" } } ``` -------------------------------- ### Perform Window Lifecycle Operations in C# Source: https://context7.com/ray2501/ticklesharp/llms.txt Shows how to manage window lifecycles including creating toplevel windows, minimizing, maximizing, focusing, and destroying windows. ```csharp using System; using TickleSharp; public class WindowOps { static Tk tk; public static void Main(string[] args) { tk = new Tk(); tk.SetTitleBar(".", "Window Operations"); tk.SetWindowSize(".", 400, 300); // Create a secondary window tk.Eval("toplevel .child"); tk.SetTitleBar(".child", "Child Window"); tk.SetWindowSize(".child", 200, 150); // Control buttons tk.CreateCommand("hideChild", new TclTkInterface.Tcl_CmdProc((i) => { tk.MinimizeWindow(".child"); return 0; })); tk.CreateCommand("showChild", new TclTkInterface.Tcl_CmdProc((i) => { tk.MaximizeWindow(".child"); // Deiconify/restore return 0; })); tk.CreateCommand("focusChild", new TclTkInterface.Tcl_CmdProc((i) => { tk.SetFocus(".child"); return 0; })); tk.CreateCommand("closeChild", new TclTkInterface.Tcl_CmdProc((i) => { tk.DestroyWindow(".child"); return 0; })); tk.Eval("button .hide -text {Hide Child} -command hideChild"); tk.Eval("button .show -text {Show Child} -command showChild"); tk.Eval("button .focus -text {Focus Child} -command focusChild"); tk.Eval("button .close -text {Close Child} -command closeChild"); tk.Eval("pack .hide .show .focus .close -pady 3"); tk.Run(); } } ``` -------------------------------- ### Create Tk GUI Application in C# Source: https://context7.com/ray2501/ticklesharp/llms.txt Initializes a Tk instance to create windows and widgets, utilizing the main event loop. ```csharp using System; using TickleSharp; public class HelloWorld { static Tk tk; public static void Main(string[] args) { // Create Tk instance (includes Tcl interpreter + Tk GUI) tk = new Tk(); // Set window title tk.SetTitleBar(".", "Hello World Application"); // Set window size and position (width, height, x, y) tk.SetWindowGeometry(".", 400, 300, 100, 100); // Create GUI widgets using Tcl/Tk commands tk.Eval("button .hello -text {Click Me!} -command {puts {Hello from Tcl/Tk!}}"); tk.Eval("button .exit -text {Exit} -command exit"); tk.Eval("pack .hello -pady 10"); tk.Eval("pack .exit -pady 10"); // Start the Tk main event loop (blocks until window closes) tk.Run(); } } ``` -------------------------------- ### CreateCommand - Registering .NET Callbacks Source: https://context7.com/ray2501/ticklesharp/llms.txt Registers a .NET method as a Tcl command, allowing Tcl/Tk scripts to invoke .NET code. ```APIDOC ## CreateCommand ### Description Registers a .NET method as a Tcl command. ### Parameters - **commandName** (string) - Required - The name of the command in Tcl. - **callback** (Tcl_CmdProc) - Required - The .NET method to execute. ``` -------------------------------- ### Build Script for TickleSharp Library (Linux/Unix) Source: https://context7.com/ray2501/ticklesharp/llms.txt This bash script compiles the TickleSharp C wrapper library into a shared object (.so) and builds the .NET assembly. It outputs the necessary files to the 'bin' directory. ```bash #!/bin/bash # build.sh - Build TickleSharp library mkdir -p bin cd src # Build the C wrapper library gcc -fPIC -D__UNIX__ -shared -o ../bin/libtclwrapper.so tclwrapper.c -ltcl8.6 -ltk8.6 # Build the .NET assembly cd TickleSharp dotnet build --configuration Release cp bin/Release/netstandard2.0/TickleSharp.dll ../../bin/TickleSharp.dll ``` -------------------------------- ### Register .NET Callbacks with CreateCommand Source: https://context7.com/ray2501/ticklesharp/llms.txt Registers a .NET method as a Tcl command to allow Tcl/Tk scripts to trigger .NET logic. Always invoke FreeArgArray after processing to prevent memory leaks. ```csharp using System; using TickleSharp; public class CallbackExample { static Tk tk; public static void Main(string[] args) { tk = new Tk(); // Register a .NET method as a Tcl command tk.CreateCommand("processData", new TclTkInterface.Tcl_CmdProc(ProcessData)); // Create GUI that calls the .NET command with parameters tk.Eval("entry .name -width 20"); tk.Eval("entry .value -width 20"); tk.Eval("button .submit -text Submit -command {processData [.name get] [.value get]}"); tk.Eval("label .result -text {Result will appear here}"); tk.Eval("pack .name .value .submit .result -pady 5"); tk.SetTitleBar(".", "Callback Demo"); tk.Run(); } // Callback method signature: int MethodName(int ArgArrInst) public static int ProcessData(int ArgArrInst) { // Get the argument array for this command invocation string argv = tk.GetArgArray("processData", ArgArrInst); // Parameter 0 contains argument count int argCount = int.Parse(tk.GetParam(argv, 0)); Console.WriteLine($"Received {argCount - 1} parameters"); // Get actual parameters (1-indexed) string name = tk.GetParam(argv, 1); string value = tk.GetParam(argv, 2); // Update GUI with result tk.Eval($".result configure -text {{Processed: {name} = {value}}}"); // Always free the argument array when done tk.FreeArgArray(argv); return 0; // TCL_OK } } ``` -------------------------------- ### Scribble - Interactive Drawing Application with Tk Canvas Source: https://context7.com/ray2501/ticklesharp/llms.txt Implement an interactive drawing application using Tk canvas and mouse event bindings. Register .NET callbacks for mouse events and use Tk canvas commands to draw lines dynamically. ```csharp using System; using TickleSharp; public class Scribble { static Tk tk; public static void Main(string[] args) { tk = new Tk(); // Create a blue canvas for drawing tk.Eval("pack [canvas .c -bg blue] -fill both -expand 1"); // Register drawing callbacks tk.CreateCommand("BeginDraw", new TclTkInterface.Tcl_CmdProc(BeginDraw)); tk.CreateCommand("DrawPoint", new TclTkInterface.Tcl_CmdProc(DrawPoint)); // Bind mouse events to callbacks with coordinates tk.Eval("bind .c <1> [list BeginDraw %x %y]"); // Left click tk.Eval("bind .c {DrawPoint %x %y}"); // Drag tk.SetWindowSize(".", 600, 600); tk.SetTitleBar(".", "TickleSharp Scribble"); tk.Run(); } public static int BeginDraw(int ArgArrInst) { string argv = tk.GetArgArray("BeginDraw", ArgArrInst); // Get mouse coordinates from callback parameters string x = tk.GetParam(argv, 1); string y = tk.GetParam(argv, 2); // Create a new line starting at click position tk.Eval($ ``` ```csharp tk.Eval($"set ::points [.c create line {x} {y} {x} {y} -fill black]"); tk.FreeArgArray(argv); return 0; } public static int DrawPoint(int ArgArrInst) { string argv = tk.GetArgArray("DrawPoint", ArgArrInst); // Get current mouse position string x = tk.GetParam(argv, 1); string y = tk.GetParam(argv, 2); // Append point to current line tk.Eval($"eval .c coords $::points [concat [.c coords $::points] {x} {y}]"); tk.FreeArgArray(argv); return 0; } } ``` -------------------------------- ### GetArgArray and GetParam - Accessing Callback Parameters Source: https://context7.com/ray2501/ticklesharp/llms.txt Methods to retrieve and parse parameters passed from Tcl to a .NET callback. ```APIDOC ## GetArgArray ### Description Retrieves the name of the Tcl array containing callback parameters. ## GetParam ### Description Retrieves an individual parameter by index from the argument array. ### Parameters - **argv** (string) - Required - The argument array name. - **index** (int) - Required - The index of the parameter (0 is count, 1+ are arguments). ``` -------------------------------- ### Retrieve Tcl Variables with GetVar Source: https://context7.com/ray2501/ticklesharp/llms.txt Retrieves simple variables and array elements from the Tcl interpreter, with support for scope flags. ```csharp using System; using TickleSharp; public class VariableExample { static Tcl tcl; public static void Main(string[] args) { tcl = new Tcl(); // Set up some variables in Tcl tcl.Eval("set username {JohnDoe}"); tcl.Eval("set count 42"); tcl.Eval("array set config {host localhost port 8080}"); // Get simple variable string username = tcl.GetVar("username"); Console.WriteLine($"Username: {username}"); // "JohnDoe" // Get variable with flags (TCL_GLOBAL_ONLY = 1) string count = tcl.GetVar("count", 1); Console.WriteLine($"Count: {count}"); // "42" // Get array element (two-part variable name) string host = tcl.GetVar("config", "host"); string port = tcl.GetVar("config", "port"); Console.WriteLine($"Server: {host}:{port}"); // "Server: localhost:8080" } } ``` -------------------------------- ### Set Tcl Variables with SetVar Source: https://context7.com/ray2501/ticklesharp/llms.txt Assigns values to Tcl variables from .NET to enable bidirectional data flow. The entry widget automatically reflects updates made via the .NET callback. ```csharp using System; using TickleSharp; public class SetVarExample { static Tk tk; public static void Main(string[] args) { tk = new Tk(); // Set variable that Tk widget can use tk.SetVar("displayText", "Initial Value"); // Create entry widget bound to the variable tk.Eval("entry .e -textvariable displayText -width 30"); tk.Eval("pack .e -pady 10"); // Create button that updates the variable from .NET tk.CreateCommand("updateText", new TclTkInterface.Tcl_CmdProc(UpdateText)); tk.Eval("button .b -text {Update from .NET} -command updateText"); tk.Eval("pack .b -pady 5"); tk.SetTitleBar(".", "SetVar Demo"); tk.Run(); } public static int UpdateText(int ArgArrInst) { // Update variable - entry widget automatically reflects change tk.SetVar("displayText", $"Updated at {DateTime.Now:HH:mm:ss}"); return 0; } } ``` -------------------------------- ### SetTclResult - Return Values from .NET Callbacks to Tcl Source: https://context7.com/ray2501/ticklesharp/llms.txt Use SetTclResult to return strings, integers, doubles, or booleans from .NET callback methods to the Tcl interpreter. Ensure to free the argument array after use. ```csharp using System; using TickleSharp; public class ResultExample { static Tk tk; public static void Main(string[] args) { tk = new Tk(); // Register commands that return values tk.CreateCommand("calculateSum", new TclTkInterface.Tcl_CmdProc(CalculateSum)); tk.CreateCommand("getCurrentTime", new TclTkInterface.Tcl_CmdProc(GetCurrentTime)); // Use the results in Tcl tk.Eval("label .l1 -text {Sum of 10 + 20:}"); tk.Eval("label .r1 -text [calculateSum 10 20]"); tk.Eval("label .l2 -text {Current Time:}"); tk.Eval("label .r2 -text [getCurrentTime]"); tk.Eval("grid .l1 .r1 -pady 5 -padx 10"); tk.Eval("grid .l2 .r2 -pady 5 -padx 10"); tk.SetTitleBar(".", "Result Demo"); tk.Run(); } public static int CalculateSum(int ArgArrInst) { string argv = tk.GetArgArray("calculateSum", ArgArrInst); int a = int.Parse(tk.GetParam(argv, 1)); int b = int.Parse(tk.GetParam(argv, 2)); // Return integer result to Tcl tk.SetTclResult(a + b); tk.FreeArgArray(argv); return 0; } public static int GetCurrentTime(int ArgArrInst) { string argv = tk.GetArgArray("getCurrentTime", ArgArrInst); // Return string result to Tcl tk.SetTclResult(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); tk.FreeArgArray(argv); return 0; } } ``` -------------------------------- ### SetVar - Setting Tcl Variables Source: https://context7.com/ray2501/ticklesharp/llms.txt The SetVar method assigns values to Tcl variables from .NET code, enabling bidirectional data flow. ```APIDOC ## SetVar ### Description Assigns a value to a Tcl variable from .NET code. ### Parameters - **varName** (string) - Required - The name of the Tcl variable. - **value** (string) - Required - The value to assign to the variable. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.