Re: ChatGPT & Euphoria
- Posted by irv 5 days ago
- 231 views
And here is the complete code to implement a gtk4 picture widget. Each widget takes similar code to implement, except for the listviews. The main "wrapper" for gtk4 is only about 750 lines so far. Big improvement over the more than 10,000 in the previous EuGTK. Comments and formatting by ChatGPT:
-------------------------------------- namespace Picture -------------------------------------- /* 💡 What This Module Does: This code binds the GTK4 GtkPicture widget to Euphoria by defining the function names and their signatures in the widget[Picture] structure. It lists all the common GTK methods you can call on a GtkPicture widget getters, setters, and constructors. The new function is a convenience function that creates a new GtkPicture widget from a given filename string. ⏺ It dynamically looks up the GTK C function gtk_picture_new_for_filename. ⏺ It converts the Euphoria string to a C-compatible string using allocate_string. ⏺ Calls the GTK function and gets back a widget handle. ⏺ Calls init to initialize internal widget state. ⏺ Registers the widget in the Euphoria GTK registry, returning a usable handle. This enables you to easily create and manipulate image widgets in your GTK application with Euphoria by just calling Picture:new("image.png"). */ -- Include GTK base definitions and types include gtk4.e -- Define the Picture widget metadata widget[Picture] = { "gtk_picture_", -- GTK function prefix for Picture widget {Widget}, -- Inherits from base Widget -- List of GTK Picture methods with their parameter and return types: {"get_alternative_text", {P}, S}, -- Get alternative text (string) {"get_can_shrink", {P}, B}, -- Get whether image can shrink (boolean) {"get_content_fit", {P}, B}, -- Get content fit property (boolean) {"get_file", {P}, S}, -- Get filename or URI (string) {"get_keep_aspect_ratio", {P}, B}, -- Get whether aspect ratio is kept (boolean) {"get_paintable", {P}, B}, -- Get paintable state (boolean) -- Constructors for different ways to create a Picture: {"new_for_file", {P, S}}, -- Create from file (pointer, string) {"new_for_filename", {P, S}}, -- Create from filename (pointer, string) {"new_for_paintable", {P, P}}, -- Create from paintable object {"new_for_pixbuf", {P, P}}, -- Create from GdkPixbuf object {"new_for_resource", {P, S}}, -- Create from resource path -- Setters for various properties: {"set_alternative_text", {P, S}}, {"set_can_shrink", {P, B}}, {"set_content_fit", {P, B}}, {"set_file", {P, S}}, {"set_filename", {P, S}}, {"set_keep_aspect_ratio", {P, B}}, {"set_paintable", {P, B}}, {"set_pixbuf", {P, P}}, {"set_resource", {P, S}}, "GtkPicture" -- GTK type name for the widget } object self = widget[Picture]-- Reference to the Picture widget metadata ------------------------------------------------------ export function new(object f) ------------------------------------------------------ -- Exported function to create a new Picture widget -- from a filename (string f) -- Define the C function pointer for gtk_picture_new_for_filename atom fn = define_c_func(LIB, self[1] & "new_for_filename", {P}, P) -- Allocate the filename string as a C string and call GTK to create the Picture widget atom handle = c_func(fn, {allocate_string(f)}) -- Initialize Picture widget in registry (sets up properties, etc.) init(Picture) -- Register and return the widget handle return register(Picture, handle) end function
Here's a screenshot: https://photos.app.goo.gl/Yo3RjS2aGqED3B5JA