Hash :
d0f8e533
Author :
Jeremy JEANNE
Date :
2024-12-19T15:35:12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
#!/usr/bin/env ikc3
defmodule Kmsg do
require Gtk4
require Gtk4.ActionMap
require Gtk4.Application
require Gtk4.ApplicationWindow
require Gtk4.Box
require Gtk4.Button
require Gtk4.Frame
require Gtk4.Label
require Gtk4.ListBox
require Gtk4.Menu
require Gtk4.MenuItem
require Gtk4.Paned
require Gtk4.ScrolledWindow
require Gtk4.SimpleAction
require Gtk4.TextView
require Gtk4.Widget
require Gtk4.Window
require List
def on_connect_ok = fn (action, void){
puts("Kmsg.connect_ok")
}
def on_connect = fn (action, void) {
puts("Kmsg.connect")
window = Gtk4.Window.new()
Gtk4.Window.set_title(window, "Kmsg: Connect")
vbox = Gtk4.Box.new(:vertical, 1)
hbox = Gtk4.Box.new(:horizontal, 0)
label = Gtk4.Label.new("Host")
button = Gtk4.Button.new_with_label("Ok")
entry = Gtk4.Entry.new()
Gtk4.Box.append(hbox, label)
Gtk4.Box.append(hbox, entry)
Gtk4.Box.append(vbox, hbox)
Gtk4.Box.append(vbox, button)
Gtk4.Window.set_child(window, vbox)
Gtk4.Window.present(window)
}
def on_send = fn (action, %{window: window,
text_view_w: text_view_w}) {
message = Gtk4.TextView.get_text(text_view_w)
puts("Kmsg.send #{inspect(message)}")
Gtk4.TextView.set_text(text_view_w, "")
}
def activate = fn (app, void) {
window = Gtk4.ApplicationWindow.new(app)
Gtk4.Window.set_title(window, "Kmsg")
Gtk4.Window.set_default_size(window, (Uw) 640, (Uw) 480)
paned = Gtk4.Paned.new(:horizontal)
Gtk4.Widget.set_size_request(paned, 200, 200);
scrolled_window1 = Gtk4.ScrolledWindow.new()
channels = Gtk4.ListBox.new()
labels1 = List.map(List.count(20), fn (x) {
label = Gtk4.Label.new("Label")
Gtk4.Widget.set_halign(label, :start)
Gtk4.ListBox.append(channels, label)
label
})
Gtk4.ScrolledWindow.set_child(scrolled_window1, channels)
Gtk4.Paned.set_start_child(paned, scrolled_window1)
Gtk4.Paned.set_resize_start_child(paned, true)
Gtk4.Paned.set_shrink_start_child(paned, false)
box1 = Gtk4.Box.new(:vertical, 0)
scrolled_window2 = Gtk4.ScrolledWindow.new()
list_box = Gtk4.ListBox.new()
Gtk4.Widget.set_vexpand(list_box, true)
labels2 = List.map(List.count(200), fn (x) {
label = Gtk4.Label.new("<b>thodg</b>: Message <i>with <b>markup</b></i> !")
Gtk4.Label.set_use_markup(label, true)
Gtk4.Widget.set_halign(label, :start)
Gtk4.ListBox.append(list_box, label)
label
})
Gtk4.Paned.set_resize_end_child(paned, false)
Gtk4.Paned.set_shrink_end_child(paned, false)
Gtk4.ScrolledWindow.set_child(scrolled_window2, list_box)
Gtk4.Box.append(box1, scrolled_window2)
box2 = Gtk4.Box.new(:horizontal, 0)
Gtk4.Box.append(box1, box2)
Gtk4.Paned.set_end_child(paned, box1)
Gtk4.Window.set_child(window, paned)
text_view_w = Gtk4.TextView.new()
Gtk4.TextView.set_monospace(text_view_w, true)
Gtk4.Widget.set_hexpand(text_view_w, true)
Gtk4.Box.append(box2, text_view_w)
button = Gtk4.Button.new_with_label("Send")
Gtk4.signal_connect(button, "clicked", Kmsg.on_send,
%{window: window, text_view_w: text_view_w})
Gtk4.Box.append(box2, button)
Gtk4.Paned.set_position(paned, 240);
connect_action = Gtk4.SimpleAction.new("connect", Kmsg.on_connect, void)
Gtk4.ActionMap.add_action(app, connect_action)
Gtk4.Application.set_accel_for_action(app, "app.connect", "<Control>N");
menu = Gtk4.Menu.new()
file_menu = Gtk4.Menu.new()
item = Gtk4.MenuItem.new("Connect", "app.connect")
Gtk4.Menu.append_item(file_menu, item)
Gtk4.Menu.append_section(menu, "File", file_menu)
Gtk4.Application.set_menubar(app, menu)
Gtk4.Window.present(window)
}
def main = fn () {
puts("Kmsg.main: starting, please wait...")
Gtk4.init()
app = Gtk4.Application.new("Kmsg", "io.kmx.kmsg")
Gtk4.signal_connect(app, "activate", Kmsg.activate, void)
status = Gtk4.Application.run(app)
puts("Kmsg.main: exiting: #{inspect(status)}")
Gtk4.Application.delete(app)
status
}
end
Kmsg.main()