Skip to content

Instantly share code, notes, and snippets.

@wolfiestyle
Created August 20, 2016 22:23
Show Gist options
  • Save wolfiestyle/f6295baea9aef910a03a5f7f35b85242 to your computer and use it in GitHub Desktop.
Save wolfiestyle/f6295baea9aef910a03a5f7f35b85242 to your computer and use it in GitHub Desktop.
the Awoo Tool™
#!/usr/bin/env lua
-- Awoo Tool by @wolfiestyle
-- license: MIT/X11
-- demo: https://twitter.com/wolfiestyle/status/767124329461084161
local lgi = require "lgi"
local Gtk = lgi.Gtk
local GLib = lgi.GLib
local window = Gtk.Window{
title = "awoo tool v0.1-alpha",
default_width = 320,
default_height = 200,
on_destroy = Gtk.main_quit,
Gtk.Box{
orientation = Gtk.Orientation.VERTICAL,
margin = 30,
spacing = 10,
Gtk.Button{ id = "button", label = "Awoo" },
Gtk.Box{
spacing = 5,
halign = Gtk.Align.CENTER,
Gtk.Spinner{ id = "spinner", no_show_all = true },
Gtk.Label{ id = "msg", label = "Click to start a howl" },
},
{ Gtk.ProgressBar{ id = "progbar", text = "Ready", show_text = true }, pack_type = Gtk.PackType.END },
}
}
local button, progbar, spinner, msg =
window.child.button, window.child.progbar, window.child.spinner, window.child.msg
local function dialog(text, secondary)
local dlg = Gtk.MessageDialog{
title = "awoo",
buttons = Gtk.ButtonsType.OK,
text = text,
secondary_text = secondary,
on_response = Gtk.Widget.destroy,
}
dlg:set_transient_for(window)
local x, y = window:get_position()
dlg:move(x + math.random(-50, 100), y + math.random(-50, 100))
dlg:show()
end
local function reset()
spinner:stop()
spinner:hide()
msg.label = "Click to start a howl"
progbar.text = "Ready"
progbar.fraction = 0
button.sensitive = true
end
function window.child.button:on_clicked()
self.sensitive = false
msg.label = "Awooing..."
spinner:show()
spinner:start()
progbar.text = "Initializing..."
GLib.timeout_add(GLib.PRIORITY_DEFAULT_IDLE, 1000, coroutine.create(function()
progbar.text = "Loading waffs..."
progbar.fraction = 0.25
coroutine.yield(true)
progbar.text = "Disabling fines..."
progbar.fraction = 0.5
coroutine.yield(true)
progbar.text = "*inhales*"
progbar.fraction = 0.75
coroutine.yield(true)
progbar.text = "Awoooooooooo!"
progbar.fraction = 1
coroutine.yield(true)
coroutine.yield(true)
for _= 1, 10 do
dialog("Awoooooooooo!", "awooooooooooooooooooo\noooooooooooooooooo...")
end
return reset()
end))
end
window:show_all()
Gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment