Lines 3-13
Link Here
|
3 |
# Bluetooth PIN helper |
3 |
# Bluetooth PIN helper |
4 |
# Written by Maxim Krasnyansky <maxk@qualcomm.com> |
4 |
# Written by Maxim Krasnyansky <maxk@qualcomm.com> |
5 |
# |
5 |
# |
6 |
import sys, os, string, popen2 |
6 |
import sys, os, string, popen2, pygtk |
|
|
7 |
|
8 |
pygtk.require('2.0') |
7 |
|
9 |
|
8 |
# X Display initialization. |
10 |
# X Display initialization. |
9 |
# Find running X Server and parse it's arguments. |
11 |
# Find running X Server and parse its arguments. |
10 |
# Set enviroment variables DISPLAY and XAUTHORITY |
12 |
# Set environment variables DISPLAY and XAUTHORITY |
11 |
# using info extracted from X Server args. |
13 |
# using info extracted from X Server args. |
12 |
# |
14 |
# |
13 |
def set_display(): |
15 |
def set_display(): |
Lines 24-85
Link Here
|
24 |
elif arg[i] == "-auth": |
26 |
elif arg[i] == "-auth": |
25 |
auth = arg[i+1] |
27 |
auth = arg[i+1] |
26 |
break |
28 |
break |
27 |
|
|
|
28 |
os.environ['DISPLAY'] = disp |
29 |
os.environ['DISPLAY'] = disp |
29 |
os.environ['XAUTHORITY'] = auth |
30 |
os.environ['XAUTHORITY'] = auth |
30 |
|
31 |
|
31 |
# Set X display before initializing GTK |
32 |
# Set X display before initializing GTK |
32 |
set_display() |
33 |
#set_display() |
|
|
34 |
|
35 |
# Some versions of fontconfig will segfault if HOME isn't set. |
36 |
#os.environ['HOME'] = "" |
33 |
|
37 |
|
34 |
from gtk import * |
38 |
import gtk |
35 |
|
39 |
|
36 |
# Dialog Class |
40 |
# Dialog Class |
37 |
DLG_OK = 1 |
41 |
DLG_OK = 1 |
38 |
DLG_CANCEL = 2 |
42 |
DLG_CANCEL = 2 |
39 |
class Dialog(GtkDialog): |
43 |
class Dialog(gtk.Dialog): |
40 |
result = DLG_CANCEL |
44 |
result = DLG_CANCEL |
41 |
args = {} |
45 |
args = {} |
42 |
def __init__(self, modal=FALSE, mesg=None, args = {}): |
46 |
def __init__(self, modal=gtk.FALSE, mesg=None, args = {}): |
43 |
GtkDialog.__init__(self) |
47 |
gtk.Dialog.__init__(self) |
44 |
self.args = args |
48 |
self.args = args |
45 |
self.set_modal(modal) |
49 |
self.set_modal(modal) |
46 |
self.set_usize(400, 0) |
50 |
# self.set_usize(400, 0) |
47 |
self.set_uposition(300,300) |
51 |
# self.set_uposition(300,300) |
48 |
|
52 |
|
49 |
self.connect("destroy", self.quit) |
53 |
self.connect("destroy", self.quit) |
50 |
self.connect("delete_event", self.quit) |
54 |
self.connect("delete_event", self.quit) |
51 |
|
55 |
|
52 |
self.action_area.set_border_width(2) |
56 |
self.action_area.set_border_width(2) |
53 |
|
57 |
|
54 |
ok = GtkButton("Accept") |
58 |
ok = gtk.Button("Accept") |
55 |
ok.connect("clicked", self.ok) |
59 |
ok.connect("clicked", self.ok) |
56 |
self.action_area.pack_start(ok, padding = 20) |
60 |
self.action_area.pack_start(ok, padding = 20) |
57 |
ok.show() |
61 |
ok.show() |
58 |
|
62 |
|
59 |
cl = GtkButton("Reject") |
63 |
cl = gtk.Button("Reject") |
60 |
cl.connect("clicked", self.cancel) |
64 |
cl.connect("clicked", self.cancel) |
61 |
self.action_area.pack_start(cl, padding = 20) |
65 |
self.action_area.pack_start(cl, padding = 20) |
62 |
cl.show() |
66 |
cl.show() |
63 |
|
67 |
|
64 |
if mesg: |
68 |
if mesg: |
65 |
msg = GtkLabel() |
69 |
msg = gtk.Label("") |
66 |
msg.set_text(mesg) |
70 |
msg.set_text(mesg) |
67 |
self.vbox.pack_start(msg, padding = 10) |
71 |
self.vbox.pack_start(msg, padding = 10) |
68 |
msg.show() |
72 |
msg.show() |
69 |
|
73 |
|
70 |
self.ents = [] |
74 |
self.ents = [] |
71 |
for k in self.args.keys(): |
75 |
for k in self.args.keys(): |
72 |
hbox = GtkHBox() |
76 |
hbox = gtk.HBox() |
73 |
hbox.set_border_width(5) |
77 |
hbox.set_border_width(5) |
74 |
self.vbox.pack_start(hbox) |
78 |
self.vbox.pack_start(hbox) |
75 |
hbox.show() |
79 |
hbox.show() |
76 |
|
80 |
|
77 |
l = GtkLabel() |
81 |
l = gtk.Label("") |
78 |
e = GtkEntry() |
82 |
e = gtk.Entry() |
79 |
l.set_text( k ) |
83 |
l.set_text( k ) |
80 |
e.set_text( self.args[k] ) |
84 |
e.set_text( self.args[k] ) |
81 |
e.connect("key_press_event", self.key_press) |
85 |
e.connect("key_press_event", self.key_press) |
82 |
hbox.pack_start(l, padding = 10, expand = FALSE) |
86 |
hbox.pack_start(l, padding = 10, expand = gtk.FALSE) |
83 |
hbox.pack_start(e) |
87 |
hbox.pack_start(e) |
84 |
l.show() |
88 |
l.show() |
85 |
e.show() |
89 |
e.show() |
Lines 89-98
Link Here
|
89 |
self.ents[0][1].grab_focus() |
93 |
self.ents[0][1].grab_focus() |
90 |
|
94 |
|
91 |
def key_press(self, entry, event): |
95 |
def key_press(self, entry, event): |
92 |
if event.keyval == GDK.Return: |
96 |
if event.keyval == gtk.keysyms.Return: |
93 |
entry.emit_stop_by_name("key_press_event") |
97 |
entry.emit_stop_by_name("key_press_event") |
94 |
self.ok() |
98 |
self.ok() |
95 |
elif event.keyval == GDK.Escape: |
99 |
elif event.keyval == gtk.keysyms.Escape: |
96 |
entry.emit_stop_by_name("key_press_event") |
100 |
entry.emit_stop_by_name("key_press_event") |
97 |
self.cancel() |
101 |
self.cancel() |
98 |
|
102 |
|
Lines 110-122
Link Here
|
110 |
def quit(self, *args): |
114 |
def quit(self, *args): |
111 |
self.hide() |
115 |
self.hide() |
112 |
self.destroy() |
116 |
self.destroy() |
113 |
mainquit() |
117 |
gtk.mainquit() |
114 |
|
118 |
|
115 |
def dialog(title, mesg, args, modal = FALSE): |
119 |
def dialog(title, mesg, args, modal = gtk.FALSE): |
116 |
dlg = Dialog(args = args, mesg = mesg, modal = modal) |
120 |
dlg = Dialog(args = args, mesg = mesg, modal = modal) |
117 |
dlg.set_title(title) |
121 |
dlg.set_title(title) |
118 |
dlg.show() |
122 |
dlg.show() |
119 |
mainloop() |
123 |
gtk.mainloop() |
120 |
return dlg.result |
124 |
return dlg.result |
121 |
|
125 |
|
122 |
def main(*args): |
126 |
def main(*args): |