Instantly share code, notes, and snippets.
Last active
February 3, 2018 14:21
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save jvalrog/a0aac979f9791e149b1f174b949d8fb8 to your computer and use it in GitHub Desktop.
Pi-Menu, made with GTK3/Glade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!-- Generated with glade 3.20.0 --> | |
<interface> | |
<requires lib="gtk+" version="3.20"/> | |
<object class="GtkAdjustment" id="adjustment1"> | |
<property name="upper">100</property> | |
<property name="step_increment">1</property> | |
<property name="page_increment">10</property> | |
</object> | |
<object class="GtkWindow" id="main_window"> | |
<property name="can_focus">False</property> | |
<property name="title" translatable="yes">Pi-Menu</property> | |
<signal name="delete-event" handler="main_window_quit" swapped="no"/> | |
<child> | |
<object class="GtkAlignment"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<property name="xalign">0</property> | |
<property name="yalign">0</property> | |
<property name="top_padding">10</property> | |
<property name="bottom_padding">10</property> | |
<property name="left_padding">10</property> | |
<property name="right_padding">10</property> | |
<child> | |
<object class="GtkBox"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<property name="orientation">vertical</property> | |
<property name="homogeneous">True</property> | |
<child> | |
<object class="GtkFrame"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<property name="label_xalign">2.2351741291171123e-10</property> | |
<property name="shadow_type">none</property> | |
<child> | |
<object class="GtkAlignment"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<property name="top_padding">12</property> | |
<property name="bottom_padding">12</property> | |
<property name="left_padding">12</property> | |
<property name="right_padding">12</property> | |
<child> | |
<object class="GtkScale" id="volume_scale"> | |
<property name="visible">True</property> | |
<property name="can_focus">True</property> | |
<property name="adjustment">adjustment1</property> | |
<property name="round_digits">0</property> | |
<property name="digits">0</property> | |
<property name="value_pos">right</property> | |
<signal name="value-changed" handler="volume_changed" swapped="no"/> | |
</object> | |
</child> | |
</object> | |
</child> | |
<child type="label"> | |
<object class="GtkLabel"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<property name="label" translatable="yes">VOLUME</property> | |
</object> | |
</child> | |
</object> | |
<packing> | |
<property name="expand">False</property> | |
<property name="fill">True</property> | |
<property name="position">0</property> | |
</packing> | |
</child> | |
<child> | |
<object class="GtkFrame"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<property name="label_xalign">2.2351741291171123e-10</property> | |
<property name="shadow_type">none</property> | |
<child> | |
<object class="GtkAlignment"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<property name="top_padding">12</property> | |
<property name="bottom_padding">12</property> | |
<property name="left_padding">12</property> | |
<property name="right_padding">12</property> | |
<child> | |
<object class="GtkBox"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<property name="spacing">5</property> | |
<property name="homogeneous">True</property> | |
<child> | |
<object class="GtkButton"> | |
<property name="label" translatable="yes">⏮</property> | |
<property name="visible">True</property> | |
<property name="can_focus">True</property> | |
<property name="receives_default">True</property> | |
<signal name="clicked" handler="music_prev" swapped="no"/> | |
</object> | |
<packing> | |
<property name="expand">False</property> | |
<property name="fill">True</property> | |
<property name="position">0</property> | |
</packing> | |
</child> | |
<child> | |
<object class="GtkButton"> | |
<property name="label" translatable="yes">⏯</property> | |
<property name="visible">True</property> | |
<property name="can_focus">True</property> | |
<property name="receives_default">True</property> | |
<signal name="clicked" handler="music_play" swapped="no"/> | |
</object> | |
<packing> | |
<property name="expand">False</property> | |
<property name="fill">True</property> | |
<property name="position">1</property> | |
</packing> | |
</child> | |
<child> | |
<object class="GtkButton"> | |
<property name="label" translatable="yes">⏹</property> | |
<property name="visible">True</property> | |
<property name="can_focus">True</property> | |
<property name="receives_default">True</property> | |
<signal name="clicked" handler="music_stop" swapped="no"/> | |
</object> | |
<packing> | |
<property name="expand">False</property> | |
<property name="fill">True</property> | |
<property name="position">2</property> | |
</packing> | |
</child> | |
<child> | |
<object class="GtkButton"> | |
<property name="label" translatable="yes">⏭</property> | |
<property name="visible">True</property> | |
<property name="can_focus">True</property> | |
<property name="receives_default">True</property> | |
<signal name="clicked" handler="music_next" swapped="no"/> | |
</object> | |
<packing> | |
<property name="expand">False</property> | |
<property name="fill">True</property> | |
<property name="position">3</property> | |
</packing> | |
</child> | |
</object> | |
</child> | |
</object> | |
</child> | |
<child type="label"> | |
<object class="GtkLabel"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<property name="label" translatable="yes">MUSIC</property> | |
</object> | |
</child> | |
</object> | |
<packing> | |
<property name="expand">False</property> | |
<property name="fill">True</property> | |
<property name="position">1</property> | |
</packing> | |
</child> | |
<child> | |
<object class="GtkFrame"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<property name="label_xalign">2.2351741291171123e-10</property> | |
<property name="shadow_type">none</property> | |
<child> | |
<object class="GtkAlignment"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<property name="top_padding">12</property> | |
<property name="bottom_padding">12</property> | |
<property name="left_padding">12</property> | |
<property name="right_padding">12</property> | |
<child> | |
<object class="GtkBox"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<property name="spacing">5</property> | |
<property name="homogeneous">True</property> | |
<child> | |
<object class="GtkButton"> | |
<property name="label" translatable="yes">Reboot</property> | |
<property name="visible">True</property> | |
<property name="can_focus">True</property> | |
<property name="receives_default">True</property> | |
<signal name="clicked" handler="system_reboot" swapped="no"/> | |
</object> | |
<packing> | |
<property name="expand">False</property> | |
<property name="fill">True</property> | |
<property name="position">0</property> | |
</packing> | |
</child> | |
<child> | |
<object class="GtkButton"> | |
<property name="label" translatable="yes">Poweroff</property> | |
<property name="visible">True</property> | |
<property name="can_focus">True</property> | |
<property name="receives_default">True</property> | |
<signal name="clicked" handler="system_poweroff" swapped="no"/> | |
</object> | |
<packing> | |
<property name="expand">False</property> | |
<property name="fill">True</property> | |
<property name="position">1</property> | |
</packing> | |
</child> | |
</object> | |
</child> | |
</object> | |
</child> | |
<child type="label"> | |
<object class="GtkLabel"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<property name="label" translatable="yes">SYSTEM</property> | |
</object> | |
</child> | |
</object> | |
<packing> | |
<property name="expand">False</property> | |
<property name="fill">True</property> | |
<property name="position">2</property> | |
</packing> | |
</child> | |
</object> | |
</child> | |
</object> | |
</child> | |
</object> | |
</interface> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "gtk3" | |
def run(cmd) | |
pid = spawn(cmd) | |
Process.detach(pid) | |
end | |
def music_prev | |
run("music prev") | |
end | |
def music_play | |
run("music play-pause") | |
end | |
def music_stop | |
run("music stop") | |
end | |
def music_next | |
run("music next") | |
end | |
def system_reboot | |
run("sudo reboot") | |
end | |
def system_poweroff | |
run("sudo poweroff") | |
end | |
def main_window_quit | |
Gtk.main_quit | |
end | |
def volume_changed(w) | |
$new_volume = w.value | |
$last_volume_update = Time.now.to_f | |
$update_volume = true | |
end | |
builder = Gtk::Builder.new | |
builder.add_from_file("pi-menu.glade") | |
builder.connect_signals do |handler| | |
method(handler) | |
end | |
volume_scale = builder.get_object("volume_scale") | |
volume_scale.set_value `volume value`.to_i | |
window = builder.get_object("main_window") | |
window.show | |
Thread.new do | |
loop do | |
if $update_volume && (Time.now.to_f - $last_volume_update > 0.5) | |
system("volume #{$new_volume}") | |
$update_volume = false | |
end | |
sleep 0.01 | |
end | |
end | |
Gtk.main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment