SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2012-12-09 23:28:51

Anthryx
New Member
Registered: 2012-12-09
Posts: 8

How To: Openbox Suspend Option

Hey there,

I was greatly annoyed with the ootb crunchbang not having a suspend-to-ram option on the exit menu by default.
I'm sure it's been done before, but I just couldn't find an off-the-shelf solution on the internet, so I rewrote my openbox script on my own. It now features a new button solely dedicated for suspending your system to RAM. I tested it on two different machines, it works fine and fast. After all, it's not much effort, but I feel like dedicating somethin to this project, so here you guys go.

1.) Make a Backup of your local script (sudo cp /usr/bin/cb-exit /usr/bin/cp-exit.bak)

2.) Open the cb-exit script with the editor of your choice (i.e. gksudo sublime /usr/bin/cb-exit) and overwrite all existing code with this snippet:

#!/usr/bin/env python

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.hibernate.set_sensitive(False)
		self.reboot.set_sensitive(False)
		self.shutdown.set_sensitive(False)
		self.suspend.set_sensitive(False)

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

	def logout_action(self,btn):
		self.disable_buttons()
		self.status.set_label("Exiting Openbox, please standby...")
		os.system("openbox --exit")

	def suspend_action(self, btn):
		self.disable_buttons()
		self.status.set_label("Suspending, please standby...")
		os.system("dbus-send --session --dest=org.freedesktop.PowerManagement --type=method_call --print-reply --reply-timeout=2000 /org/freedesktop/PowerManagement org.freedesktop.PowerManagement.Suspend")
		gtk.main_quit()

	def hibernate_action(self,btn):
		self.disable_buttons()
		self.status.set_label("Hibernating, please standby...")
		os.system("cb-lock")
		os.system("dbus-send --print-reply --system --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Hibernate")
		gtk.main_quit()

	def reboot_action(self,btn):
		self.disable_buttons()
		self.status.set_label("Rebooting, please standby...")
		os.system("dbus-send --print-reply --system --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Reboot")

	def shutdown_action(self,btn):
		self.disable_buttons()
		self.status.set_label("Shutting down, please standby...")
		os.system("dbus-send --print-reply --system --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown")

	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()
		
		#Hibernate button
		self.hibernate = gtk.Button("_Hibernate")
		self.hibernate.set_border_width(4)
		self.hibernate.connect("clicked", self.hibernate_action)
		self.button_box.pack_start(self.hibernate)
		self.hibernate.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("_Shutdown")
		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.creahttp://crunchbang.org/forums/post.php?fid=8#te_window()


def main():
    gtk.main()

if __name__ == "__main__":
    go = cb_exit()
    main()

3. Save your code.

4. ???

5. Profit!

screenvjk.png
Enjoy your new Suspend Button!

Last edited by Anthryx (2012-12-10 11:33:14)

Offline

Be excellent to each other!

#2 2012-12-10 06:46:04

merelyjim
#! Die Hard
From: Fort Worth, Texas
Registered: 2010-04-07
Posts: 2,303
Website

Re: How To: Openbox Suspend Option

Nice. smile

I've been using sudo pm-suspend from the command-line...


"When I enter a command... I expect ass to be hauled and the coffeelike aroma of hustle delicately hovering in the air." -thalassophile

My attempt at a blog; http://waitingonragnarok.blogspot.com/

Offline

#3 2012-12-10 08:08:51

Anthryx
New Member
Registered: 2012-12-09
Posts: 8

Re: How To: Openbox Suspend Option

Me too, but I got annoyed by typing my password everytime I wanted to quickly suspend the system. I got the command mapped to the corresponding FN Keys on my Notebook aswell now, I'm just wondering why such a feature is not included in a stable Release? Anyway I'm glad I could help some of you  smile

Offline

#4 2012-12-14 05:18:19

stolid
#! CrunchBanger
Registered: 2012-09-06
Posts: 206

Re: How To: Openbox Suspend Option

Are you all using Statler or Waldorf? I used to run Statler on my laptop, and I had hibernate but not suspend. Now, I run Waldorf and I have Suspend but not hibernate. I don't get what changed.


Registered Linux User #555399
crunchbox:     Phenom II X6 1055T | 8GB RAM | OCZ Vertex 4 128GB | Radeon 7870XT | Win7 / #! 11 (i3 WM)
lambdacore:     4x Opteron 8431 | 16GB RAM | 2x1TB mirrored (ZFSoL) | Debian 7 (headless)
crunchtop:     Acer Aspire 1410 11.6" | 2GB RAM | Crucial M4 128GB | #! 11 (i3 WM)

Offline

#5 2012-12-18 08:01:47

Anthryx
New Member
Registered: 2012-12-09
Posts: 8

Re: How To: Openbox Suspend Option

Now that's a bit odd.
I'm running Statler, and only had the Hibernate Option.
Using this script should give you the Hiberbate Option back though smile

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo