Author Topic: Perhaps update a script  (Read 338 times)

PackRat

  • Posts: 1769
    • View Profile
Perhaps update a script
« on: January 24, 2017, 03:55:44 PM »
What does the vsido-exit script look like these days? Still using all the dbus commands?

Maybe update the exit script to take advantage of systemd - and any additional enhancements (if any) it brings to the table.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

VastOne

  •      v-ger
  • Posts: 3784
    • View Profile
    • VSIDO Community
Re: Perhaps update a script
« Reply #1 on: January 25, 2017, 07:28:02 PM »
Great question!  This is what works and has been for quite some time.. and only requires consolekit and policykit-1 packages to work

Latest:

vsido-exit

Code: [Select]
#!/usr/bin/env python2

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

class cb_exit:
def disable_buttons(self):
self.cancel.set_sensitive(False)
self.logout.set_sensitive(False)
self.suspend.set_sensitive(False)
self.reboot.set_sensitive(False)
self.shutdown.set_sensitive(False)

def cancel_action(self,btn):
self.disable_buttons()
gtk.main_quit()

def logout_action(self,btn):
self.disable_buttons()
for line in os.popen("wmctrl -m"):
parts = line.split()
if parts[0] == "Name:":
wmName = parts[1].lower()
self.status.set_label("Exiting " + wmName + ", please standby...")
os.system("killall " + wmName)

def suspend_action(self,btn):
self.disable_buttons()
self.status.set_label("Suspending, please standby...")
os.system("cb-lock")
os.system("dbus-send --system --print-reply --dest=\"org.freedesktop.UPower\" /org/freedesktop/UPower org.freedesktop.UPower.Suspend")
gtk.main_quit()

def reboot_action(self,btn):
self.disable_buttons()
self.status.set_label("Rebooting, please standby...")
os.system("dbus-send --system --print-reply --dest=\"org.freedesktop.ConsoleKit\" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart")

def shutdown_action(self,btn):
self.disable_buttons()
self.status.set_label("Shutting down, please standby...")
os.system("dbus-send --system --print-reply --dest=\"org.freedesktop.ConsoleKit\" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop")

def create_window(self):
self.window = gtk.Window()
title = "Log out " + getpass.getuser() + "? Choose an option:"
self.window.set_title(title)
self.window.set_border_width(5)
self.window.set_size_request(500, 80)
self.window.set_resizable(False)
self.window.set_keep_above(True)
self.window.stick
self.window.set_position(1)
self.window.connect("delete_event", gtk.main_quit)
windowicon = self.window.render_icon(gtk.STOCK_QUIT, gtk.ICON_SIZE_MENU)
self.window.set_icon(windowicon)


#Create HBox for buttons
self.button_box = gtk.HBox()
self.button_box.show()

#Cancel button
self.cancel = gtk.Button(stock = gtk.STOCK_CANCEL)
self.cancel.set_border_width(4)
self.cancel.connect("clicked", self.cancel_action)
self.button_box.pack_start(self.cancel)
self.cancel.show()

#Logout button
self.logout = gtk.Button("_Log out")
self.logout.set_border_width(4)
self.logout.connect("clicked", self.logout_action)
self.button_box.pack_start(self.logout)
self.logout.show()

#Suspend button
self.suspend = gtk.Button("_Suspend")
self.suspend.set_border_width(4)
self.suspend.connect("clicked", self.suspend_action)
self.button_box.pack_start(self.suspend)
self.suspend.show()

#Reboot button
self.reboot = gtk.Button("_Reboot")
self.reboot.set_border_width(4)
self.reboot.connect("clicked", self.reboot_action)
self.button_box.pack_start(self.reboot)
self.reboot.show()

#Shutdown button
self.shutdown = gtk.Button("_Power off")
self.shutdown.set_border_width(4)
self.shutdown.connect("clicked", self.shutdown_action)
self.button_box.pack_start(self.shutdown)
self.shutdown.show()

#Create HBox for status label
self.label_box = gtk.HBox()
self.label_box.show()
self.status = gtk.Label()
self.status.show()
self.label_box.pack_start(self.status)

#Create VBox and pack the above HBox's
self.vbox = gtk.VBox()
self.vbox.pack_start(self.button_box)
self.vbox.pack_start(self.label_box)
self.vbox.show()

self.window.add(self.vbox)
self.window.show()

def __init__(self):
self.create_window()


def main():
    gtk.main()

if __name__ == "__main__":
    go = cb_exit()
    main()
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

hakerdefo

  • Posts: 467
    • View Profile
    • Looking at Linux through the Windows of Life
Re: Perhaps update a script
« Reply #2 on: January 26, 2017, 07:19:02 PM »
Should be easy-peasy to write a gui script. Can you guys provide me working systemd commands to suspend-logout-reboot-shutdown a vsido session? Give me commands I give you the script ;)
A challenge for VastOne-PackRat-jedi ;)
Cheers!!!
You Can't Always Git What You Want

VastOne

  •      v-ger
  • Posts: 3784
    • View Profile
    • VSIDO Community
Re: Perhaps update a script
« Reply #3 on: January 26, 2017, 07:50:34 PM »
Power Off = systemctl poweroff
Reboot = systemctl reboot
Suspend = systemctl suspend
Logout = pkill x

Logout = best would be a killall setup ... nothing specific to systemd that I can find for logout.. no systemctl function
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

PackRat

  • Posts: 1769
    • View Profile
Re: Perhaps update a script
« Reply #4 on: January 26, 2017, 07:58:31 PM »
systemctl shutdown [OPTIONS...] [TIME] [WALL...]  <- see the man page.

/sbin/poweroff, /sbin/reboot, and /sbin/shutdown are all symlinked to /bin/systemctl

Ufortunately, the fluxbox exit command is an internal command only, so it cannot be invoked in a script. You'll have to do something like VastOne posted.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

hakerdefo

  • Posts: 467
    • View Profile
    • Looking at Linux through the Windows of Life
Re: Perhaps update a script
« Reply #5 on: January 27, 2017, 05:59:10 AM »
But those commands require super user rights. So the script will be required to run with gksudo. Not elegant perhaps.
You Can't Always Git What You Want

PackRat

  • Posts: 1769
    • View Profile
Re: Perhaps update a script
« Reply #6 on: January 27, 2017, 04:09:45 PM »
I can issue poweroff and reboot from a terminal without sudo and they work - no prompt that they need to be run as root or having to provide a password. I think as long as a user is in the sudo group it's all good.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

hakerdefo

  • Posts: 467
    • View Profile
    • Looking at Linux through the Windows of Life
Re: Perhaps update a script
« Reply #7 on: January 27, 2017, 05:21:18 PM »
That's great then! Now can VastOne link me the VSIDO banner image and icons in high-res for the new vsido-exit :)
Cheers!!!
You Can't Always Git What You Want

VastOne

  •      v-ger
  • Posts: 3784
    • View Profile
    • VSIDO Community
Re: Perhaps update a script
« Reply #8 on: January 28, 2017, 12:49:25 AM »
I like the attached banner and Icon.. really those are what and all that identifies VSIDO
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

hakerdefo

  • Posts: 467
    • View Profile
    • Looking at Linux through the Windows of Life
Re: Perhaps update a script
« Reply #9 on: January 29, 2017, 01:41:52 PM »
You asked for it and here it is  ;)

http://vsido.org/index.php?topic=1273.msg14510#msg14510

Cheers!!!
You Can't Always Git What You Want