(SOLVED) How to replicate this zenity dialogue?

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
ericramos1990

(SOLVED) How to replicate this zenity dialogue?

Post by ericramos1990 »

I attached a picture.

I would like to make a zenity dialogue box like the example, except, I want to label my own boxes, and have them do specific commands


I have been looking for a solution for quite some time!

If anyone knows where this dialogue box is located at, or if you know how to make a zenity box with more than 2 options, PLEASE let me know! Thanks!
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29615
Joined: Wed Jul 06, 2011 3:58 am

Re: How to replicate this zenity dialogue?

Post by xenopeek »

You can't do that with zenity as shown. You could something similar it with a selection list:

Code: Select all

zenity --title 'Do you want to run "firefoxgoogle", or display its contents?' --text '"firefoxgoogle" is an executable text file.'  --height 264 --list --radiolist --column 1 --column 2 --hide-header 1 "Run in Terminal" 2 "Display" 3 "Run"
If the OK button is pressed, $? is 0. If cancel, $? is 1. If $? is 0, the output of the command is 1, 2, 3, or blank depending on what item in the list was selected.
Image
ericramos1990

Re: How to replicate this zenity dialogue?

Post by ericramos1990 »

Habitual:
Yea I have heard of yad, but I'm hoping to do a zenity version since it is defaulted with many distros!

Xenopeek:
Thanks I have tried several methods such as that in the past actually through some google searching.
But to be honest, I am not satisfied with them because I can't just use the arrow keys and the return/enter key.
With some, I have to use the tab key, and your example the mouse or space key too!

Is there a reason why it's not possible to replicate it ourselves?

Thanks for the help guys
User avatar
xenopeek
Level 25
Level 25
Posts: 29615
Joined: Wed Jul 06, 2011 3:58 am

Re: How to replicate this zenity dialogue?

Post by xenopeek »

ericramos1990 wrote:Is there a reason why it's not possible to replicate it ourselves?
Of course you can replicate it. But you asked to do it with Bash :) If you write a Python script for example, you can do this--as it has bindings for Gtk. You can program a Gtk dialog with as many buttons as you want. Or put in a small C program that you call from your Bash script, etc.
Image
ericramos1990

Re: How to replicate this zenity dialogue?

Post by ericramos1990 »

Oh my apologies, I didn't know the thread was just bash, I thought it was "bash and other types of scripts"

But it's true, I don't know anything else besides bash lol

But I have concluded just now that I am going to try to learn python :)

Any sources on a head start on what I plan to do with a zenity dialogue?

Thanks man!
User avatar
xenopeek
Level 25
Level 25
Posts: 29615
Joined: Wed Jul 06, 2011 3:58 am

Re: How to replicate this zenity dialogue?

Post by xenopeek »

Well, I made it look a lot easier than it is I guess... Programming Python and using Gtk is a big step up from Bash with zenity. You can ask about Python scripting here also, I just assumed you meant to want to do it with Bash.

To learn Python you could do the Google Python Class (https://developers.google.com/edu/python/), follow up with the Hitchhiker's Guide to Python (http://docs.python-guide.org/en/latest/index.html), and keep the link to the official documentation close (https://docs.python.org/3/).

Programming Gtk you do with PyGI: https://wiki.gnome.org/action/show/Proj ... =PyGObject. Here's a tutorial of programming dialogs: http://python-gtk-3-tutorial.readthedoc ... alogs.html
Image
akashsydney

Re: How to replicate this zenity dialogue?

Post by akashsydney »

You can use 2 zenity dialog

zenity --question --text="<b>Do you want to run\"fireggogle\", or display its contents?</b>\n \"firefoxgoogle\" is an <i>execuable</i> file." --ok-label="_Run/Display" --cancel-label="Exit"
if [ $? -eq 0 ];then a=$(zenity --list --hide-header --text="Select the option" --column="" Run Display "Run in terminal" ) ;fi


$a will be containing Selected option, 'Run' ,'Display', 'Run in terminal' you can check for cancel with $?
This method will allow you to put as many option as you want.
ericramos1990

Re: How to replicate this zenity dialogue?

Post by ericramos1990 »

Hi akashsydney, I am already familiar with that type of zenity dialogue, but I don't like it because I just want to use the arrow keys and enter and it requires more than that! :x

Xenopeek, I actually still haven't managed to get what I wanted! I found the following python code somewhere, but I would REALLY like to control the buttons by moving with the arrow keys, and then pressing enter to confirm.

Can anyone please help me if you know what to do? I just want to use the arrow keys and enter. Thanks!

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pygtk
pygtk.require('2.0')
import gtk
import os

class DoTheLogOut:

    # Cancel/exit
    def delete_event(self, widget, event, data=None):
        gtk.main_quit()
        return False

    # Logout
    def logout(self, widget):
        os.system("openbox --exit")

    # Reboot
    def reboot(self, widget):
        os.system("sudo shutdown -r now && openbox --exit")

    # Shutdown
    def shutdown(self, widget):
        os.system("sudo shutdown -h now && openbox --exit")

    # Hibernate
    def hibernate(self, widget):
        os.system("sudo hibernate")


    def __init__(self):
        # Create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("Exit? Choose an option:")
        self.window.set_resizable(False)
        self.window.set_position(1)
        self.window.connect("delete_event", self.delete_event)
        self.window.set_border_width(20)

        # Create an accelgroup and add it to the window
        accel_group = gtk.AccelGroup()
        self.window.add_accel_group(accel_group)

        # Create a box to pack widgets into
        self.box1 = gtk.HBox(False, 0)
        self.window.add(self.box1)

        # Create cancel button
        self.button1 = gtk.Button("Cancel")
        self.button1.set_border_width(10)
        self.button1.connect("clicked", self.delete_event, "closed")
        self.box1.pack_start(self.button1, True, True, 0)
        self.button1.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('Escape'), 0, 0)
        self.button1.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('c'), 0, 0)
        self.button1.show()

        # Create logout button
        self.button2 = gtk.Button("Logout")
        self.button2.set_border_width(10)
        self.button2.connect("clicked", self.logout)
        self.box1.pack_start(self.button2, True, True, 0)
        self.button2.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('l'), 0, 0)
        self.button2.show()

        # Create reboot button
        self.button3 = gtk.Button("Reboot")
        self.button3.set_border_width(10)
        self.button3.connect("clicked", self.reboot)
        self.box1.pack_start(self.button3, True, True, 0)
        self.button3.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('r'), 0, 0)
        self.button3.show()

        # Create shutdown button
        self.button4 = gtk.Button("Shutdown")
        self.button4.set_border_width(10)
        self.button4.connect("clicked", self.shutdown)
        self.box1.pack_start(self.button4, True, True, 0)
        self.button4.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('s'), 0, 0)
        self.button4.show()

        # Create hibernate button
        self.button5 = gtk.Button("Hibernate")
        self.button5.set_border_width(10)
        self.button5.connect("clicked", self.hibernate)
        self.box1.pack_start(self.button5, True, True, 0)
        self.button5.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('h'), 0, 0)
        self.button5.show()

        self.box1.show()
        self.window.show()

def main():
    gtk.main()

if __name__ == "__main__":
    run_it = DoTheLogOut()
    main()
Jamesc359

Re: How to replicate this zenity dialogue?

Post by Jamesc359 »

According to the docs you need to set the CAN_DEFAULT flag on the button widget. e.g. self.button1.set_flags(gtk.CAN_DEFAULT) from there that button can now accept keyboard input. You should also be able to call the grab_default method to set that button as the active one, however I can't get that to work. :-/

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pygtk
pygtk.require('2.0')
import gtk
import os

class DoTheLogOut:

    # Cancel/exit
    def delete_event(self, widget, event, data=None):
        gtk.main_quit()
        return False

    # Logout
    def logout(self, widget):
        os.system("openbox --exit")

    # Reboot
    def reboot(self, widget):
        os.system("sudo shutdown -r now && openbox --exit")

    # Shutdown
    def shutdown(self, widget):
        os.system("sudo shutdown -h now && openbox --exit")

    # Hibernate
    def hibernate(self, widget):
        os.system("sudo hibernate")


    def __init__(self):
        # Create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("Exit? Choose an option:")
        self.window.set_resizable(False)
        self.window.set_position(1)
        self.window.connect("delete_event", self.delete_event)
        self.window.set_border_width(20)

        # Create an accelgroup and add it to the window
        accel_group = gtk.AccelGroup()
        self.window.add_accel_group(accel_group)

        # Create a box to pack widgets into
        self.box1 = gtk.HBox(False, 0)
        self.window.add(self.box1)

        # Create cancel button
        self.button1 = gtk.Button("Cancel")
        self.button1.set_border_width(10)
        self.button1.connect("clicked", self.delete_event, "closed")
        self.box1.pack_start(self.button1, True, True, 0)
        self.button1.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('Escape'), 0, 0)
        self.button1.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('c'), 0, 0)
        self.button1.set_flags(gtk.CAN_DEFAULT)
        self.button1.show()
        
        # Create logout button
        self.button2 = gtk.Button("Logout")
        self.button2.set_border_width(10)
        self.button2.connect("clicked", self.logout)
        self.box1.pack_start(self.button2, True, True, 0)
        self.button2.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('l'), 0, 0)
        self.button2.set_flags(gtk.CAN_DEFAULT)
        self.button2.show()

        # Create reboot button
        self.button3 = gtk.Button("Reboot")
        self.button3.set_border_width(10)
        self.button3.connect("clicked", self.reboot)
        self.box1.pack_start(self.button3, True, True, 0)
        self.button3.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('r'), 0, 0)
        self.button3.set_flags(gtk.CAN_DEFAULT)
        self.button3.show()

        # Create shutdown button
        self.button4 = gtk.Button("Shutdown")
        self.button4.set_border_width(10)
        self.button4.connect("clicked", self.shutdown)
        self.box1.pack_start(self.button4, True, True, 0)
        self.button4.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('s'), 0, 0)
        self.button4.set_flags(gtk.CAN_DEFAULT)
        self.button4.show()

        # Create hibernate button
        self.button5 = gtk.Button("Hibernate")
        self.button5.set_border_width(10)
        self.button5.connect("clicked", self.hibernate)
        self.box1.pack_start(self.button5, True, True, 0)
        self.button5.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('h'), 0, 0)
        self.button5.set_flags(gtk.CAN_DEFAULT)
        self.button5.show()
        
        self.button5.grab_default()
        
        self.box1.show()
        self.window.show()

def main():
    gtk.main()

if __name__ == "__main__":
    run_it = DoTheLogOut()
    main()
ericramos1990

Re: How to replicate this zenity dialogue?

Post by ericramos1990 »

James: Thank you!!!!

That would have been nice to set a default button, but no worries, I will just simply rearrange the most common to the beginning.

Once again thanks, I have been pretty lazy to learn python just for that simple thing, and I probably won't ever need python ever again, so thank you, you saved me a lot of trouble, have a good one everyone!
ericramos1990

Re: How to replicate this zenity dialogue?

Post by ericramos1990 »

I'm sorry to bug again, but by any chance, is it possible to make these buttons in a rows x columns format?

For example, 3 x 3 buttons:

B1 B2 B3
B4 B5 B6
B7 B8 B9

Please give me some insight if it's easy to do, thanks! :P
User avatar
Pilosopong Tasyo
Level 6
Level 6
Posts: 1432
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: How to replicate this zenity dialogue?

Post by Pilosopong Tasyo »

ericramos1990 wrote:...by any chance, is it possible to make these buttons in a rows x columns format?
...
Please give me some insight if it's easy to do
Image

The 3x3 all-buttons dialog box can be easily coded with YAD. Even the example dialog box in your initial post can be coded in one line using YAD. Easy navigation using the arrow keys. And the enter key/space bar to execute the button.

Then again, you're not inclined to use, let alone install YAD, based on your reply earlier. And by your own admission, you're pretty lazy to learn python just for that simple thing [sic].

Just saying. :wink:
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
ericramos1990

Re: How to replicate this zenity dialogue?

Post by ericramos1990 »

Lol man so witty, you're getting me on all angles!

Well the reason I don't want to use YAD is because I'm trying to be less internet-dependent (installing YAD) and more future-proof and flexible (other distros), at least to my knowledge!

Sorry if I sound really stubborn and unreasonable, that's just how I look at things, I guess I'm a doomsday prepper lol.

And yeah I don't know diddly squat of coding on python, I'm just really used to bash, so I can't really complain lol

But Pilosopong, go ahead and leave the code, in case I ever give up on python, or it helps another reader in the future. Thanks buddy! :mrgreen:
Jamesc359

Re: How to replicate this zenity dialogue?

Post by Jamesc359 »

You need to use a table, add the table to the window and then attach your buttons to the table. Sounds complex? It's really not.

This is 4am coding at it's finest, but it is functional at least. :-)

Code: Select all

#!/usr/bin/env python

import pygtk
import gtk

def delete(widget, event, data=None):
	gtk.main_quit()
	return False

window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("Hello World")
window.connect("delete_event", delete)

table = gtk.Table(3, 3, True)
window.add(table)

# table.attach(widget, col1, col2, row1, row2)
# col1 = starting column, col2 = ending column
# row1 = starting row, row2 = ending row
# This allows you to span a widget across multiple rows/columns
# as demonstrated with Button 8

# Row 1
button = gtk.Button("Button 1")
table.attach(button, 0, 1, 0, 1)
button.show()

button = gtk.Button("Button 2")
table.attach(button, 1, 2, 0, 1)
button.show()

button = gtk.Button("Button 3")
table.attach(button, 2, 3, 0, 1)
button.show()

# Row 2
button = gtk.Button("Button 4")
table.attach(button, 0, 1, 1, 2)
button.show()

button = gtk.Button("Button 5")
table.attach(button, 1, 2, 1, 2)
button.show()

button = gtk.Button("Button 6")
table.attach(button, 2, 3, 1, 2)
button.show()

# Row 3
button = gtk.Button("Button 7")
table.attach(button, 0, 1, 2, 3)
button.show()

button = gtk.Button("Button 8")
table.attach(button, 1, 3, 2, 3)
button.show()

#button = gtk.Button("Button 9")
#table.attach(button, 2, 3, 2, 3)
#button.show()


table.show()
window.show()
gtk.main()

ericramos1990

Re: How to replicate this zenity dialogue?

Post by ericramos1990 »

Jamesc359!!!

I got it! I managed to merge both scripts you sent me, and I got to do what I wanted!

Thanks man, I kind of understand python now! I tend to learn from top to bottom rather than the way around. I know it's ineffecient for learning properly, but hey it works!

Also thanks for putting in this comment:
# table.attach(widget, col1, col2, row1, row2)
# col1 = starting column, col2 = ending column
# row1 = starting row, row2 = ending row
# This allows you to span a widget across multiple rows/columns
# as demonstrated with Button 8
It helped a lot too!

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pygtk
#pygtk.require('2.0')
import gtk
import os

class DoTheLogOut:

    def delete(widget, event, data=None):
	gtk.main_quit()
	return False

    # Vlc all
    def vlcall(self, widget):
        os.system("~/scripts/vlcall")
        gtk.main_quit()

    def vlc1(self, widget):
        os.system("~/scripts/vlc1")
        gtk.main_quit()
    def vlc2(self, widget):
        os.system("~/scripts/vlc2")
        gtk.main_quit()
    def vlc3(self, widget):
        os.system("~/scripts/vlc3")
        gtk.main_quit()
    def vlc4(self, widget):
        os.system("~/scripts/vlc4")
        gtk.main_quit()
    def vlc5(self, widget):
        os.system("~/scripts/vlc5")
        gtk.main_quit()

    # Pandora
    def pandora(self, widget):
        os.system("aplay ~/sounds/notifications/sickdrummerintro.wav & killall vlc & firefox -new-window www.pandora.com &> /dev/null &")
        gtk.main_quit()

    # Ringtones
    def ringtones(self, widget):
        os.system("~/scripts/vlcringtones")
        gtk.main_quit()

    # Ding
    def ding(self, widget):
        os.system("aplay ~/sounds/notifications/ding.wav &")

    # Cancel/exit
    def delete_event(self, widget, event, data=None):
        gtk.main_quit()
        return False

    def __init__(self):
        # Create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("Play music!")
        self.window.set_resizable(True)
        self.window.set_position(1)
        self.window.connect("delete_event", self.delete_event)
        self.window.set_border_width(20)

        # Create an accelgroup and add it to the window
        accel_group = gtk.AccelGroup()
        self.window.add_accel_group(accel_group)

        # Create a table to pack widgets into
        self.table = gtk.Table(3, 5, True)
        self.window.add(self.table)

        # VLC All Button
        self.button = gtk.Button("VLC All")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.vlcall)
	self.table.attach(self.button, 0, 2, 0, 1)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('s'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()

        # Pandora Button
        self.button = gtk.Button("Pandora")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.vlcall)
	self.table.attach(self.button, 2, 4, 0, 1)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('s'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()

        # Vlc Ringtones Button
        self.button = gtk.Button("Ringtones")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.ringtones)
	self.table.attach(self.button, 4, 6, 0, 1)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('r'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()

        # VLC1 Button
        self.button = gtk.Button("VLC 1")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.vlc1)
	self.table.attach(self.button, 0, 1, 1, 2)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('s'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()
        # VLC2 Button
        self.button = gtk.Button("VLC 2")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.vlc2)
	self.table.attach(self.button, 1, 2, 1, 2)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('s'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()
        # VLC3 Button
        self.button = gtk.Button("VLC 3")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.vlc3)
	self.table.attach(self.button, 2, 3, 1, 2)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('s'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()
        # VLC4 Button
        self.button = gtk.Button("VLC 4")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.vlc4)
	self.table.attach(self.button, 3, 4, 1, 2)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('s'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()
        # VLC5 Button
        self.button = gtk.Button("VLC 5")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.vlc5)
	self.table.attach(self.button, 4, 5, 1, 2)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('s'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()

        # Create ding button
        self.button = gtk.Button("Ding")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.ding)
	self.table.attach(self.button, 5, 6, 1, 2)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('h'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()

        # Create cancel button
        self.button = gtk.Button("Cancel")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.delete_event, "closed")
	self.table.attach(self.button, 0, 6, 2, 3)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('Escape'), 0, 0)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('c'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()

        #Default button
        self.button.grab_default()
        

        self.table.show()
        self.window.show()

def main():
    gtk.main()

if __name__ == "__main__":
    run_it = DoTheLogOut()
    main()
I do have a small question, when the first button is highlighted "VLC All", and then I press the down arrow key, the focus goes to "VLC 2" instead of "VLC 1" like I would like it to.

If you have a solution, please let me know, otherwise, I appreciate all the help regardless, I am marking this as SOLVED!
ericramos1990

Re: How to replicate this zenity dialogue?

Post by ericramos1990 »

Jamesc359 wrote:According to the docs you need to set the CAN_DEFAULT flag on the button widget. e.g. self.button1.set_flags(gtk.CAN_DEFAULT) from there that button can now accept keyboard input. You should also be able to call the grab_default method to set that button as the active one, however I can't get that to work. :-/
Hey Jamesc359, I ended up figuring out why the grab_default didn't work.

Simply swich the table and window commands as such:

Code: Select all

        self.table.show()
        self.window.show()
Use this instead:

Code: Select all

        self.window.show()
        self.table.show()
Hope it helps you in the future! :D
Jamesc359

Re: (SOLVED) How to replicate this zenity dialogue?

Post by Jamesc359 »

It's usually the simplest of things that cause and solve problems. :)
ericramos1990

Re: (SOLVED) How to replicate this zenity dialogue?

Post by ericramos1990 »

I still didn't get it to work properly, however. The button I assigned as default does show up as default, but when I press a direction arrow key, it doesn't behave that it is "coming" from there!

Please give it a shot if you have the time :P

Try pressing an arrow key after the window is open to see what I mean :lol:

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pygtk
#pygtk.require('2.0')
import gtk
import os

# table.attach(widget, col1, col2, row1, row2)
# col1 = starting column, col2 = ending column
# row1 = starting row, row2 = ending row
# This allows you to span a widget across multiple rows/columns
# as demonstrated with Button 8

class DoTheLogOut:

    def delete(widget, event, data=None):
	gtk.main_quit()
	return False

    # Vlc all
    def vlcall(self, widget):
        os.system("~/scripts/vlcall")
        gtk.main_quit()

    def vlc1(self, widget):
        os.system("~/scripts/vlc1")
        gtk.main_quit()
    def vlc2(self, widget):
        os.system("~/scripts/vlc2")
        gtk.main_quit()
    def vlc3(self, widget):
        os.system("~/scripts/vlc3")
        gtk.main_quit()
    def vlc4(self, widget):
        os.system("~/scripts/vlc4")
        gtk.main_quit()
    def vlc5(self, widget):
        os.system("~/scripts/vlc5")
        gtk.main_quit()
    def vlc1and2(self, widget):
        os.system("~/scripts/vlc1and2")
        gtk.main_quit()
    def vlc4and5(self, widget):
        os.system("~/scripts/vlc4and5")
        gtk.main_quit()
    def fff(self, widget):
        os.system("~/scripts/fff")
        gtk.main_quit()

    # Pandora
    def pandora(self, widget):
        os.system("aplay ~/sounds/notifications/sickdrummerintro.wav & killall vlc & firefox -new-window http://www.pandora.com &> /dev/null &")
        gtk.main_quit()

    # Ringtones
    def ringtones(self, widget):
        os.system("~/scripts/vlcringtones")
        gtk.main_quit()

    # Ding
    def ding(self, widget):
        os.system("aplay ~/sounds/notifications/ding.wav &")

    # Cancel/exit
    def delete_event(self, widget, event, data=None):
        gtk.main_quit()
        return False

    def __init__(self):
        # Create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("Play Music")
        self.window.set_size_request(500, 300)
        #self.window.set_position(gtk.WIN_POS_CENTER)
        self.window.set_resizable(True)
        self.window.set_position(1)
        self.window.connect("delete_event", self.delete_event)
        self.window.set_border_width(20)

        # Create an accelgroup and add it to the window
        accel_group = gtk.AccelGroup()
        self.window.add_accel_group(accel_group)

        # Create a table to pack widgets into
        self.table = gtk.Table(4, 5, True)
        self.window.add(self.table)

        # VLC All Button
        self.button = gtk.Button("VLC All")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.vlcall)
	self.table.attach(self.button, 0, 2, 0, 1)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('s'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()

        # Pandora Button
        self.button = gtk.Button("Pandora")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.pandora)
	self.table.attach(self.button, 2, 4, 0, 1)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('s'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()

        # Vlc Ringtones Button
        self.button = gtk.Button("Ringtones")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.ringtones)
	self.table.attach(self.button, 4, 6, 0, 1)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('r'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()

        # VLC1 Button
        self.button = gtk.Button("VLC 1")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.vlc1)
	self.table.attach(self.button, 0, 1, 1, 2)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('s'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()
        # VLC2 Button
        self.button = gtk.Button("VLC 2")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.vlc2)
	self.table.attach(self.button, 1, 2, 1, 2)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('s'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()
        # VLC3 Button
        self.button = gtk.Button("VLC 3")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.vlc3)
	self.table.attach(self.button, 2, 4, 1, 2)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('s'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()
        #Default button
        self.button.grab_default()

        # VLC4 Button
        self.button = gtk.Button("VLC 4")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.vlc4)
	self.table.attach(self.button, 4, 5, 1, 2)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('s'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()
        # VLC5 Button
        self.button = gtk.Button("VLC 5")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.vlc5)
	self.table.attach(self.button, 5, 6, 1, 2)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('s'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()
        # VLC1and2 Button
        self.button = gtk.Button("VLC 1+2")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.vlc1and2)
	self.table.attach(self.button, 0, 2, 2, 3)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('s'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()
        # VLC3 Button
        self.button = gtk.Button("VLC 3")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.vlc3)
	self.table.attach(self.button, 2, 4, 2, 3)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('s'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()
        # VLC4and5 Button
        self.button = gtk.Button("VLC 4+5")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.vlc4and5)
	self.table.attach(self.button, 4, 6, 2, 3)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('s'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()

        #Create fff button
        self.button = gtk.Button("VLC None")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.fff)
	self.table.attach(self.button, 0, 3, 3, 4)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('h'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()

        #Create cancel button
        self.button = gtk.Button("Cancel")
        self.button.set_border_width(10)
        self.button.connect("clicked", self.delete_event, "closed")
	self.table.attach(self.button, 3, 6, 3, 4)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('Escape'), 0, 0)
        self.button.add_accelerator("clicked", accel_group,
            gtk.gdk.keyval_from_name('c'), 0, 0)
        self.button.set_flags(gtk.CAN_DEFAULT)
        self.button.show()
        
        self.window.show()
        self.table.show()


def main():
    gtk.main()

if __name__ == "__main__":
    run_it = DoTheLogOut()
    main()
Habitual

Re: (SOLVED) How to replicate this zenity dialogue?

Post by Habitual »

ericramos1990 wrote:I still didn't get it to work properly, however. The button I assigned as default does show up as default, but when I press a direction arrow key, it doesn't behave that it is "coming" from there!
Did you try the <tab> key to move to another button?
Locked

Return to “Scripts & Bash”