Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: third_party/twisted_8_1/twisted/spread/ui/gtkutil.py

Issue 12261012: Remove third_party/twisted_8_1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1
2 # Copyright (c) 2001-2004 Twisted Matrix Laboratories.
3 # See LICENSE for details.
4
5
6 import gtk
7 import string
8
9 from twisted.spread import pb
10 from twisted import copyright
11 from twisted.python import reflect
12 from twisted.cred.credentials import UsernamePassword
13
14 normalFont = gtk.load_font("-adobe-courier-medium-r-normal-*-*-120-*-*-m-*-iso88 59-1")
15 boldFont = gtk.load_font("-adobe-courier-bold-r-normal-*-*-120-*-*-m-*-iso8859-1 ")
16 errorFont = gtk.load_font("-adobe-courier-medium-o-normal-*-*-120-*-*-m-*-iso885 9-1")
17
18
19 def selectAll(widget,event):
20 widget.select_region(0,-1)
21
22 def cbutton(name, callback):
23 b = gtk.GtkButton(name)
24 b.connect('clicked', callback)
25 return b
26
27 class ButtonBar:
28 barButtons = None
29 def getButtonList(self, prefix='button_', container=None):
30 result = []
31 buttons = self.barButtons or \
32 reflect.prefixedMethodNames(self.__class__, prefix)
33 for b in buttons:
34 bName = string.replace(b, '_', ' ')
35 result.append(cbutton(bName, getattr(self,prefix+b)))
36 if container:
37 map(container.add, result)
38 return result
39
40 def scrollify(widget):
41 #widget.set_word_wrap(gtk.TRUE)
42 scrl=gtk.GtkScrolledWindow()
43 scrl.add(widget)
44 scrl.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
45 # scrl.set_update_policy(gtk.POLICY_AUTOMATIC)
46 return scrl
47
48 def defocusify(widget):
49 widget.unset_flags(gtk.CAN_FOCUS)
50
51 class GetString(gtk.GtkWindow):
52 def __init__(self, im, desc):
53 gtk.GtkWindow.__init__(self, gtk.WINDOW_TOPLEVEL)
54 self.set_title(desc)
55 self.im = im
56 button = cbutton(desc, self.clicked)
57 self.entry = gtk.GtkEntry()
58 self.entry.connect('activate', self.clicked)
59 hb = gtk.GtkHBox()
60 hb.add(self.entry)
61 hb.add(button)
62 self.add(hb)
63 self.show_all()
64
65 def clicked(self, btn):
66 raise NotImplementedError
67
68
69 class Login(gtk.GtkWindow):
70
71 _resetTimeout = None
72
73 def __init__(self, callback,
74 referenceable=None,
75 initialUser="guest", initialPassword="guest",
76 initialHostname="localhost",initialPortno=str(pb.portno),
77 initialService="", initialPerspective=""):
78 gtk.GtkWindow.__init__(self,gtk.WINDOW_TOPLEVEL)
79 version_label = gtk.GtkLabel("Twisted v%s" % copyright.version)
80 self.pbReferenceable = referenceable
81 self.pbCallback = callback
82 # version_label.show()
83 self.username = gtk.GtkEntry()
84 self.password = gtk.GtkEntry()
85 self.service = gtk.GtkEntry()
86 self.perspective = gtk.GtkEntry()
87 self.hostname = gtk.GtkEntry()
88 self.port = gtk.GtkEntry()
89 self.password.set_visibility(gtk.FALSE)
90
91 self.username.set_text(initialUser)
92 self.password.set_text(initialPassword)
93 self.service.set_text(initialService)
94 self.perspective.set_text(initialPerspective)
95 self.hostname.set_text(initialHostname)
96 self.port.set_text(str(initialPortno))
97
98 userlbl=gtk.GtkLabel("Username:")
99 passlbl=gtk.GtkLabel("Password:")
100 servicelbl=gtk.GtkLabel("Service:")
101 perspeclbl=gtk.GtkLabel("Perspective:")
102 hostlbl=gtk.GtkLabel("Hostname:")
103 portlbl=gtk.GtkLabel("Port #:")
104 self.allLabels = [
105 userlbl, passlbl, servicelbl, perspeclbl, hostlbl, portlbl
106 ]
107 self.logstat = gtk.GtkLabel("Protocol PB-%s" % pb.Broker.version)
108 self.okbutton = cbutton("Log In", self.login)
109 self.okbutton["can_default"] = 1
110 self.okbutton["receives_default"] = 1
111
112 okbtnbx = gtk.GtkHButtonBox()
113 okbtnbx.add(self.okbutton)
114
115 vbox = gtk.GtkVBox()
116 vbox.add(version_label)
117 table = gtk.GtkTable(2,6)
118 row=0
119 for label, entry in [(userlbl, self.username),
120 (passlbl, self.password),
121 (hostlbl, self.hostname),
122 (servicelbl, self.service),
123 (perspeclbl, self.perspective),
124 (portlbl, self.port)]:
125 table.attach(label, 0, 1, row, row+1)
126 table.attach(entry, 1, 2, row, row+1)
127 row = row+1
128
129 vbox.add(table)
130 vbox.add(self.logstat)
131 vbox.add(okbtnbx)
132 self.add(vbox)
133 self.username.grab_focus()
134 self.okbutton.grab_default()
135 for fld in self.username, self.password, self.hostname, self.service, se lf.perspective:
136 fld.signal_connect('activate',self.login)
137 fld.signal_connect('focus_in_event',selectAll)
138 self.signal_connect('destroy',gtk.mainquit,None)
139
140 def loginReset(self):
141 print 'doing login reset'
142 self.logstat.set_text("Idle.")
143 self._resetTimeout = None
144 return 0
145
146 def loginReport(self, txt):
147 print 'setting login report',repr(txt)
148 self.logstat.set_text(txt)
149 if not (self._resetTimeout is None):
150 gtk.timeout_remove(self._resetTimeout)
151
152 self._resetTimeout = gtk.timeout_add(59000, self.loginReset)
153
154 def login(self, btn):
155 host = self.hostname.get_text()
156 port = self.port.get_text()
157 service = self.service.get_text()
158 perspective = self.perspective.get_text()
159 # Maybe we're connecting to a unix socket, so don't make any
160 # assumptions
161 try:
162 port = int(port)
163 except:
164 pass
165 user = self.username.get_text()
166 pswd = self.password.get_text()
167 self.loginReport("connecting...")
168 # putting this off to avoid a stupid bug in gtk where it won't redraw
169 # if you input_add a connecting socket (!??)
170 self.user_tx = user
171 self.pswd_tx = pswd
172 self.host_tx = host
173 self.port_tx = port
174 self.service_tx = service
175 self.perspective_tx = perspective or user
176 afterOneTimeout(10, self.__actuallyConnect)
177
178 def __actuallyConnect(self):
179 from twisted.application import internet
180
181 f = pb.PBClientFactory()
182 internet.TCPClient(self.host_tx, self.port_tx, f)
183 creds = UsernamePassword(self.user_tx, self.pswd_tx)
184 f.login(creds, self.pbReferenceable
185 ).addCallbacks(self.pbCallback, self.couldNotConnect
186 ).setTimeout(30
187 )
188
189 def couldNotConnect(self, msg):
190 self.loginReport("couldn't connect: %s" % str(msg))
191
192
193 class _TimerOuter:
194 def __init__(self, timeout, cmd, args):
195 self.args = args
196 self.cmd = cmd
197 self.tid = gtk.timeout_add(timeout, self.doIt)
198
199 def doIt(self):
200 gtk.timeout_remove(self.tid)
201 apply(self.cmd, self.args)
202
203 def afterOneTimeout(timeout, cmd, *args):
204 _TimerOuter(timeout, cmd, args)
OLDNEW
« no previous file with comments | « third_party/twisted_8_1/twisted/spread/ui/gtk2util.py ('k') | third_party/twisted_8_1/twisted/spread/ui/login2.glade » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698