def __init__(self): self.acctmanager = AccountManager() self.mainframe = JFrame("Account Manager") self.chatui = None self.headers = ["Account Name", "Status", "Autologin", "Gateway"] self.data = UneditableTableModel([], self.headers) self.table = JTable(self.data) self.table.columnSelectionAllowed = 0 #cannot select columns self.table.selectionMode = ListSelectionModel.SINGLE_SELECTION self.connectbutton = JButton("Connect", actionPerformed=self.connect) self.dconnbutton = JButton("Disconnect", actionPerformed=self.disconnect) self.deletebutton = JButton("Delete", actionPerformed=self.deleteAccount) self.buildpane() self.mainframe.pack() self.mainframe.show()
def __init__(self): self.acctmanager = AccountManager() self.mainframe = JFrame("Account Manager") self.chatui = None self.headers = ["Account Name", "Status", "Autologin", "Gateway"] self.data = UneditableTableModel([], self.headers) self.table = JTable(self.data) self.table.columnSelectionAllowed = 0 # cannot select columns self.table.selectionMode = ListSelectionModel.SINGLE_SELECTION self.connectbutton = JButton("Connect", actionPerformed=self.connect) self.dconnbutton = JButton("Disconnect", actionPerformed=self.disconnect) self.deletebutton = JButton("Delete", actionPerformed=self.deleteAccount) self.buildpane() self.mainframe.pack() self.mainframe.show()
class AccountManagementGUI: def __init__(self): self.acctmanager = AccountManager() self.mainframe = JFrame("Account Manager") self.chatui = None self.headers = ["Account Name", "Status", "Autologin", "Gateway"] self.data = UneditableTableModel([], self.headers) self.table = JTable(self.data) self.table.columnSelectionAllowed = 0 #cannot select columns self.table.selectionMode = ListSelectionModel.SINGLE_SELECTION self.connectbutton = JButton("Connect", actionPerformed=self.connect) self.dconnbutton = JButton("Disconnect", actionPerformed=self.disconnect) self.deletebutton = JButton("Delete", actionPerformed=self.deleteAccount) self.buildpane() self.mainframe.pack() self.mainframe.show() def buildpane(self): buttons = JPanel(FlowLayout(), doublebuffered) buttons.add(self.connectbutton) buttons.add(self.dconnbutton) buttons.add(JButton("New", actionPerformed=self.addNewAccount)) buttons.add(self.deletebutton) buttons.add(JButton("Quit", actionPerformed=self.quit)) mainpane = self.mainframe.getContentPane() mainpane.layout = BoxLayout(mainpane, BoxLayout.Y_AXIS) mainpane.add(JScrollPane(self.table)) mainpane.add(buttons) self.update() def update(self): self.data.setDataVector(self.acctmanager.getSnapShot(), self.headers) if self.acctmanager.isEmpty(): self.deletebutton.setEnabled(0) self.connectbutton.setEnabled(0) self.dconnbutton.setEnabled(0) else: self.deletebutton.setEnabled(1) if not 1 in self.acctmanager.getConnectionInfo( ): #all disconnected self.dconnbutton.setEnabled(0) self.connectbutton.setEnabled(1) elif not 0 in self.acctmanager.getConnectionInfo(): #all connected self.dconnbutton.setEnabled(1) self.connectbutton.setEnabled(0) else: self.dconnbutton.setEnabled(1) self.connectbutton.setEnabled(1) #callable button actions def connect(self, ae): print "Trying to connect" row = self.table.getSelectedRow() if row < 0: print "Trying to connect to an account but no account selected" else: acctname = self.data.getValueAt(row, 0) if not self.chatui: self.chatui = twisted.words.im.jychat.JyChatUI() self.acctmanager.connect(acctname, self.chatui) self.update() def disconnect(self, ae): print "Trying to disconnect" row = self.table.getSelectedRow() if row < 0: print "Trying to logoff an account but no account was selected." else: acctname = self.data.getValueAt(row, 0) self.acctmanager.disconnect(acctname) self.update() def addNewAccount(self, ae): print "Starting new account creation" NewAccountGUI(self).show() def deleteAccount(self, ae): print "Deleting account" row = self.table.getSelectedRow() if row < 0: print "Trying to delete an account but no account selected" else: acctname = self.data.getValueAt(row, 0) self.acctmanager.delAccount(acctname) self.update() def quit(self, ae): self.acctmanager.quit() sys.exit()
class AccountManagementGUI: def __init__(self): self.acctmanager = AccountManager() self.mainframe = JFrame("Account Manager") self.chatui = None self.headers = ["Account Name", "Status", "Autologin", "Gateway"] self.data = UneditableTableModel([], self.headers) self.table = JTable(self.data) self.table.columnSelectionAllowed = 0 # cannot select columns self.table.selectionMode = ListSelectionModel.SINGLE_SELECTION self.connectbutton = JButton("Connect", actionPerformed=self.connect) self.dconnbutton = JButton("Disconnect", actionPerformed=self.disconnect) self.deletebutton = JButton("Delete", actionPerformed=self.deleteAccount) self.buildpane() self.mainframe.pack() self.mainframe.show() def buildpane(self): buttons = JPanel(FlowLayout(), doublebuffered) buttons.add(self.connectbutton) buttons.add(self.dconnbutton) buttons.add(JButton("New", actionPerformed=self.addNewAccount)) buttons.add(self.deletebutton) buttons.add(JButton("Quit", actionPerformed=self.quit)) mainpane = self.mainframe.getContentPane() mainpane.layout = BoxLayout(mainpane, BoxLayout.Y_AXIS) mainpane.add(JScrollPane(self.table)) mainpane.add(buttons) self.update() def update(self): self.data.setDataVector(self.acctmanager.getSnapShot(), self.headers) if self.acctmanager.isEmpty(): self.deletebutton.setEnabled(0) self.connectbutton.setEnabled(0) self.dconnbutton.setEnabled(0) else: self.deletebutton.setEnabled(1) if not 1 in self.acctmanager.getConnectionInfo(): # all disconnected self.dconnbutton.setEnabled(0) self.connectbutton.setEnabled(1) elif not 0 in self.acctmanager.getConnectionInfo(): # all connected self.dconnbutton.setEnabled(1) self.connectbutton.setEnabled(0) else: self.dconnbutton.setEnabled(1) self.connectbutton.setEnabled(1) # callable button actions def connect(self, ae): print "Trying to connect" row = self.table.getSelectedRow() if row < 0: print "Trying to connect to an account but no account selected" else: acctname = self.data.getValueAt(row, 0) if not self.chatui: self.chatui = twisted.words.im.jychat.JyChatUI() self.acctmanager.connect(acctname, self.chatui) self.update() def disconnect(self, ae): print "Trying to disconnect" row = self.table.getSelectedRow() if row < 0: print "Trying to logoff an account but no account was selected." else: acctname = self.data.getValueAt(row, 0) self.acctmanager.disconnect(acctname) self.update() def addNewAccount(self, ae): print "Starting new account creation" NewAccountGUI(self).show() def deleteAccount(self, ae): print "Deleting account" row = self.table.getSelectedRow() if row < 0: print "Trying to delete an account but no account selected" else: acctname = self.data.getValueAt(row, 0) self.acctmanager.delAccount(acctname) self.update() def quit(self, ae): self.acctmanager.quit() sys.exit()