user@linuxtrack:~ $ python -c 'print("Soyez les bienvenus !")'

Vous n'êtes pas identifié(e).

#1 02-11-2013 16:01:00

IceF0x
#! Gourou Linux

[Python3]cb-exit en python3

Voici une reconversion du menu d'extinction de crunchbang en python3 seul souci, j'arrive pas à afficher l’icône de la fenêtre sauf sur une session Gnome sad

#!/usr/bin/env python

from gi.repository import Gtk
import os
import getpass

orig_pack_start = Gtk.Box.pack_start
def pack_start(self, child, expand=True, fill=True, padding=0):
    orig_pack_start(self, child, expand, fill, padding)
Gtk.Box.pack_start = pack_start

class cl_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)

	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 hibernate_action(self,btn):
		self.disable_buttons()
		self.status.set_label("Hibernating, please standby...")
		os.system("cl-lock")
		os.system("dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Hibernate")
		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, 70)
		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.IconSize.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(5)
		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(5)
		self.logout.connect("clicked", self.logout_action)
		self.button_box.pack_start(self.logout)
		self.logout.show()
		
		#Hibernate button
		self.hibernate = Gtk.Button("Hibernate")
		self.hibernate.set_border_width(5)
		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(5)
		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(5)
		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 = cl_exit()
    main()

Utiliser des logiciels propriétaires, c'est comme les plats préparés, on est incapable de dire les conservateurs qu'ils contiennent, on dira toujours que c'est bon, mais ça ne remplacera jamais le repas fait maison par sa maman.
]:D #! Crunchbang & Archlinux GNU/Linux User ]:D

Hors ligne

Pied de page des forums