Note that sudo and Su are replaced in the GUI.ProgramIt's gksu. Unfortunately, it's an English interface.
You can also use glade to design the GTK interface. Unfortunately, I did not know it after writing this program.
2005.11.18
Encapsulated an imagebutton, which is a further study of Python ~~~ The style of the window has also been modified ~~~ Now it is basically ready for use ~~~ I replaced the exit of my ugly FVWM menu with this ~~
1 # ! /Usr/bin/Python
2 Import Pygtk
3 Import GTK
4 Import OS
5 Import Sys
6
7 Class Basewindow:
8
9 Def Delete_event (self, widget, Data = None ):
10 Print " Delete_event "
11
12 Def Destroy (self, widget, Data = None ):
13 GTK. main_quit ()
14
15 Def Loginout (self, widget, Data = None ):
16 OS. System ( " FVWM-R " )
17
18 Def Shutdown (self, widget, Data = None ):
19 OS. System ( " Shutdown-H now " )
20
21 Def Reboot (self, widget, Data = None ):
22 OS. System ( " Shutdown-R now " )
23
24 Def Restart (self, widget, Data = None ):
25 OS. System ( " FVWM-R " )
26 Def Exit (self, widget, Data = None ):
27 SYS. Exit ()
28
29 Def _ Init __ (Self ):
30 Self. Window = GTK. Window (GTK. window_popup)
31 Self. Window. set_title ( " Xyshutdown " )
32 Self. Window. set_position (GTK. win_pos_center)
33 Self. Window. set_modal (true)
34 Self. Window. set_icon_name ( " GTK-quit " )
35 Self. Window. set_resizable (false)
36 Self. Window. set_decorated (true)
37 Self. Window. set_keep_above (true)
38 Self. Window. Connect ( " Destroy " , Self. Destroy)
39 Self. Window. Connect ( " Delete_event " , Self. delete_event)
40
41 Self. boxv = GTK. vbox (false, 0)
42 Self. Window. Add (self. boxv)
43
44 Self. btnshutdown = Xyimagebutton ( " Turn off your computer " , " Quit. XPM " )
45 Self. btnshutdown. Connect ( " Clicked " , Self. shutdown, none)
46 Self. boxv. pack_start (self. btnshutdown, true, true, 0)
47
48 Self. btnreboot = Xyimagebutton ( " Restart your computer " , " Restart. XPM " )
49 Self. btnreboot. Connect ( " Clicked " , Self. Reboot, none)
50 Self. boxv. pack_start (self. btnreboot, true, true, 0)
51
52 Self. btnrestart = Xyimagebutton ( " Log out " , " Restart. XPM " )
53 Self. btnrestart. Connect ( " Clicked " , Self. Restart, none)
54 Self. boxv. pack_start (self. btnrestart, true, true, 0)
55
56
57 Self. btncancel = Xyimagebutton ( " Cancel operation " , " Exit. XPM " )
58 Self. btncancel. Connect ( " Clicked " , Self. Exit, none)
59 Self. boxv. pack_start (self. btncancel, true, true, 0)
60
61 Self. btncancel. Show ()
62 Self. btnrestart. Show ()
63 Self. btnreboot. Show ()
64 Self. btnshutdown. Show ()
65 Self. boxv. Show ()
66 Self. Window. Show ()
67
68 Def Main (Self ):
69 GTK. Main ()
70
71
72 Class Xyimagebutton (GTK. Button ):
73 Def _ Init __ (Self, text, image ):
74 GTK. Button. _ Init __ (Self)
75 Hbox = GTK. hbox (false, 0)
76 IMG = GTK. Image ()
77 IMG. set_from_file (image)
78 IMG. Show ()
79 Hbox. pack_start (IMG, true, true, 0)
80 LBL = GTK. Label (text)
81 LBL. Show ()
82 Hbox. pack_start (LBL, true, true, 0)
83 Hbox. Show ()
84 Self. Add (hbox)
85
86 Basewindow = Basewindow ()
87 Basewindow. Main ()
88