Re: ChatGPT & Euphoria
- Posted by irv 2 weeks ago
- 530 views
ChatGPT is helping me write a new GTK4 "wrapper". Most of the widgets are working. Here's an example, formatted and commented by ChatGPT:
/* 💡 What This Program Does: Loads a GTK CSS stylesheet for styling widgets. Creates a window with: ⏺ A bold-label "Hello World!" ⏺ An image (apple-red.png) ⏺ Two buttons: Exit (left) and OK (right) Uses ActionBar, Box, Label, Button, Picture, and GTK CSS theming. */ -- Include necessary modules include gtk4.e include action_bar.e -- Path to the CSS file used for styling constant css_file = locate_file("gtk.css") -- Create a new GTK application instance object app = Application:new("org.gtk.example") ------------------------------------------------------------- function interface(object app, object data) -- Callback function called when the GTK application starts -- Sets up the interface and UI components ------------------------------------------------------------- -- Create a new CSS provider and load the CSS file object css = CssProvider:new() set(css, "load from path", css_file) set(css, "add provider") -- Attach CSS to the style context -- Create the main application window object window = ApplicationWindow:new(app) set(window, "name", "Main") set(window, "title", "Main Window") set(window, "default size", 300, 100) set(window, "present") -- Make the window visible -- Create a vertical box container for layout object panel = Box:new(1, 10) -- Orientation: vertical (1), spacing: 10 set(panel, "name", "Main") set(window, "child", panel) -- Create a label with styled text object lbl = Label:new() set(lbl, "name", "L1") set(lbl, "tooltip text", "Label with markup") set(lbl, "markup", "<b>Hello World!</b>") -- Bold markup set(panel, "append", lbl) -- First horizontal box for row of widgets object bx1 = Box:new(1, 5) -- Horizontal (1), spacing: 5 set(panel, "append", bx1) -- Add an image to the first row object img = Picture:new(locate_file("apple-red.png")) set(img, "size request", 50, 50) -- Fixed size for the image set(bx1, "append", img) -- Second row: use a CenterBox for better layout control object btnbox2 = CenterBox:new() set(panel, "append", btnbox2) -- Add a GTK ActionBar at the bottom object ab = ActionBar:new() set(panel, "append", ab) -- Exit button on the left of the ActionBar object btn1 = Button:new("E_xit") set(btn1, "name", "styled") set(ab, "pack start", btn1) connect(btn1, "clicked", "quit", app) -- Quit app on click -- OK button on the right of the ActionBar object btn3 = Button:new("_OK") set(btn3, "name", "styled") set(window, "default widget", btn3) -- Triggered by Enter key set(ab, "pack end", btn3) -- Uncomment this to enable GTK interactive debugging -- interactive_debugging(1) return 1 -- Return success end function -- Register the interface function as a callback for app activation constant init = call_back(routine_id("interface")) ------------------------------------------------------------- -- Entry point: connects app activation to interface callback -- and starts the GTK application event loop function main() connect(app, "activate", init, 0) return Application:run(app) end function -- Run the program main()