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

Side by Side Diff: third_party/twisted_8_1/twisted/words/im/jyaccount.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 # Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 #
5 from twisted.words.im.baseaccount import AccountManager
6 from twisted.words.im.pbsupport import PBAccount
7 from twisted.words.im.tocsupport import TOCAccount
8 from twisted.words.im.ircsupport import IRCAccount
9 import twisted.words.im.jychat
10
11 from java.awt import GridLayout, FlowLayout, BorderLayout, Container
12 import sys
13 from java.awt.event import ActionListener
14 from javax.swing import JTextField, JPasswordField, JComboBox, JPanel, JLabel,\
15 JCheckBox, JFrame, JButton, BoxLayout, JTable, JScrollPane, \
16 ListSelectionModel
17 from javax.swing.border import TitledBorder
18 from javax.swing.table import DefaultTableModel
19
20 doublebuffered = 0
21 stype = "twisted.words"
22
23
24 class NewAccountGUI:
25 def __init__(self, amgui):
26 self.amgui = amgui
27 self.am = amgui.acctmanager
28 self.buildgwinfo()
29 self.autologin = JCheckBox("Automatically Log In")
30 self.acctname = JTextField()
31 self.gwoptions = JPanel(doublebuffered)
32 self.gwoptions.border = TitledBorder("Gateway Options")
33 self.buildgwoptions("Twisted")
34 self.mainframe = JFrame("New Account Window")
35 self.buildpane()
36
37 def buildgwinfo(self):
38 self.gateways = {"Twisted" : {"ident" : JTextField(),
39 "passwd" : JPasswordField(),
40 "host" : JTextField("twistedmatrix.com"),
41 "port" : JTextField("8787"),
42 "service" : JTextField("twisted.words"),
43 "persp" : JTextField()},
44 "AIM" : {"ident" : JTextField(),
45 "passwd" : JPasswordField(),
46 "host" : JTextField("toc.oscar.aol.com"),
47 "port" : JTextField("9898")},
48 "IRC" : {"ident" : JTextField(),
49 "passwd" : JPasswordField(),
50 "host" : JTextField(),
51 "port" : JTextField("6667"),
52 "channels" : JTextField()}
53 }
54 self.displayorder = { "Twisted" : [["Identity Name", "ident"],
55 ["Password", "passwd"],
56 ["Host", "host"],
57 ["Port", "port"],
58 ["Service Name", "service"],
59 ["Perspective Name", "persp"]],
60 "AIM" : [["Screen Name", "ident"],
61 ["Password", "passwd"],
62 ["Host", "host"],
63 ["Port", "port"]],
64 "IRC" : [["Nickname", "ident"],
65 ["Password", "passwd"],
66 ["Host", "host"],
67 ["Port", "port"],
68 ["Channels", "channels"]]
69 }
70
71 def buildgwoptions(self, gw):
72 self.gwoptions.removeAll()
73 self.gwoptions.layout = GridLayout(len(self.gateways[gw]), 2)
74 for mapping in self.displayorder[gw]:
75 self.gwoptions.add(JLabel(mapping[0]))
76 self.gwoptions.add(self.gateways[gw][mapping[1]])
77
78 def buildpane(self):
79 gw = JPanel(GridLayout(1, 2), doublebuffered)
80 gw.add(JLabel("Gateway"))
81 self.gwlist = JComboBox(self.gateways.keys())#, actionPerformed=self.cha ngegw)
82 self.gwlist.setSelectedItem("Twisted")
83 gw.add(self.gwlist)
84
85 stdoptions = JPanel(GridLayout(2, 2), doublebuffered)
86 stdoptions.border = TitledBorder("Standard Options")
87 stdoptions.add(JLabel())
88 stdoptions.add(self.autologin)
89 stdoptions.add(JLabel("Account Name"))
90 stdoptions.add(self.acctname)
91
92 buttons = JPanel(FlowLayout(), doublebuffered)
93 buttons.add(JButton("OK", actionPerformed=self.addaccount))
94 buttons.add(JButton("Cancel", actionPerformed=self.cancel))
95
96 mainpane = self.mainframe.getContentPane()
97 mainpane.layout = BoxLayout(mainpane, BoxLayout.Y_AXIS)
98 mainpane.add(gw)
99 mainpane.add(self.gwoptions)
100 mainpane.add(stdoptions)
101 mainpane.add(buttons)
102
103 def show(self):
104 self.mainframe.setLocation(100, 100)
105 self.mainframe.pack()
106 self.mainframe.show()
107
108 #actionlisteners
109 def changegw(self, ae):
110 self.buildgwoptions(self.gwlist.getSelectedItem())
111 self.mainframe.pack()
112 self.mainframe.show()
113
114 def addaccount(self, ae):
115 gwselection = self.gwlist.getSelectedItem()
116 gw = self.gateways[gwselection]
117 name = gw["ident"].text
118 passwd = gw["passwd"].text
119 host = gw["host"].text
120 port = int(gw["port"].text)
121 autologin = self.autologin.isSelected()
122 acctname = self.acctname.text
123
124 if gwselection == "Twisted":
125 sname = gw["service"].text
126 perspective = gw["persp"].text
127 self.am.addAccount(PBAccount(acctname, autologin, name, passwd,
128 host, port,
129 [[stype, sname, perspective]]))
130 elif gwselection == "AIM":
131 self.am.addAccount(TOCAccount(acctname, autologin, name, passwd,
132 host, port))
133 elif gwselection == "IRC":
134 channels = gw["channels"].text
135 self.am.addAccount(IRCAccount(acctname, autologin, name, passwd,
136 host, port, channels))
137
138 self.amgui.update()
139 print "Added new account"
140 self.mainframe.dispose()
141
142 def cancel(self, ae):
143 print "Cancelling new account creation"
144 self.mainframe.dispose()
145
146
147 class UneditableTableModel(DefaultTableModel):
148 def isCellEditable(self, x, y):
149 return 0
150
151 class AccountManagementGUI:
152 def __init__(self):
153 self.acctmanager = AccountManager()
154 self.mainframe = JFrame("Account Manager")
155 self.chatui = None
156 self.headers = ["Account Name", "Status", "Autologin", "Gateway"]
157 self.data = UneditableTableModel([], self.headers)
158 self.table = JTable(self.data)
159 self.table.columnSelectionAllowed = 0 #cannot select columns
160 self.table.selectionMode = ListSelectionModel.SINGLE_SELECTION
161
162 self.connectbutton = JButton("Connect", actionPerformed=self.connect)
163 self.dconnbutton = JButton("Disconnect", actionPerformed=self.disconnect )
164 self.deletebutton = JButton("Delete", actionPerformed=self.deleteAccount )
165 self.buildpane()
166 self.mainframe.pack()
167 self.mainframe.show()
168
169 def buildpane(self):
170 buttons = JPanel(FlowLayout(), doublebuffered)
171 buttons.add(self.connectbutton)
172 buttons.add(self.dconnbutton)
173 buttons.add(JButton("New", actionPerformed=self.addNewAccount))
174 buttons.add(self.deletebutton)
175 buttons.add(JButton("Quit", actionPerformed=self.quit))
176
177 mainpane = self.mainframe.getContentPane()
178 mainpane.layout = BoxLayout(mainpane, BoxLayout.Y_AXIS)
179 mainpane.add(JScrollPane(self.table))
180 mainpane.add(buttons)
181 self.update()
182
183 def update(self):
184 self.data.setDataVector(self.acctmanager.getSnapShot(), self.headers)
185 if self.acctmanager.isEmpty():
186 self.deletebutton.setEnabled(0)
187 self.connectbutton.setEnabled(0)
188 self.dconnbutton.setEnabled(0)
189 else:
190 self.deletebutton.setEnabled(1)
191 if not 1 in self.acctmanager.getConnectionInfo(): #all disconnected
192 self.dconnbutton.setEnabled(0)
193 self.connectbutton.setEnabled(1)
194 elif not 0 in self.acctmanager.getConnectionInfo(): #all connected
195 self.dconnbutton.setEnabled(1)
196 self.connectbutton.setEnabled(0)
197 else:
198 self.dconnbutton.setEnabled(1)
199 self.connectbutton.setEnabled(1)
200
201 #callable button actions
202 def connect(self, ae):
203 print "Trying to connect"
204 row = self.table.getSelectedRow()
205 if row < 0:
206 print "Trying to connect to an account but no account selected"
207 else:
208 acctname = self.data.getValueAt(row, 0)
209 if not self.chatui:
210 self.chatui = twisted.words.im.jychat.JyChatUI()
211 self.acctmanager.connect(acctname, self.chatui)
212 self.update()
213
214 def disconnect(self, ae):
215 print "Trying to disconnect"
216 row = self.table.getSelectedRow()
217 if row < 0:
218 print "Trying to logoff an account but no account was selected."
219 else:
220 acctname = self.data.getValueAt(row, 0)
221 self.acctmanager.disconnect(acctname)
222 self.update()
223
224 def addNewAccount(self, ae):
225 print "Starting new account creation"
226 NewAccountGUI(self).show()
227
228 def deleteAccount(self, ae):
229 print "Deleting account"
230 row = self.table.getSelectedRow()
231 if row < 0:
232 print "Trying to delete an account but no account selected"
233 else:
234 acctname = self.data.getValueAt(row, 0)
235 self.acctmanager.delAccount(acctname)
236 self.update()
237
238 def quit(self, ae):
239 self.acctmanager.quit()
240 sys.exit()
241
242 if __name__ == "__main__":
243 n = AccountManagementGUI()
OLDNEW
« no previous file with comments | « third_party/twisted_8_1/twisted/words/im/ircsupport.py ('k') | third_party/twisted_8_1/twisted/words/im/jychat.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698