class NodeView(wx.Panel): def __init__(self, parent): super(NodeView, self).__init__(parent, size=(380,600)) self.list = wx.ListCtrl(self,style=wx.LC_REPORT) self.list.InsertColumn(0, "ip") self.list.SetColumnWidth(0, 80) self.list.InsertColumn(1, "port") self.list.SetColumnWidth(1, 50) self.list.InsertColumn(2, "status") self.list.SetColumnWidth(2, 80) self.list.InsertColumn(3, "version") self.list.SetColumnWidth(3, 80) self.list.InsertColumn(4, "height") self.list.SetColumnWidth(4, 80) self.banned_label = wx.StaticText(self, -1, "Banned nodes:") self.banned_nodes = wx.ListCtrl(self,style=wx.LC_REPORT) self.banned_nodes.InsertColumn(0, "ip") self.banned_nodes.SetColumnWidth(0, 80) self.banned_nodes.InsertColumn(1, "port") self.banned_nodes.SetColumnWidth(1, 50) self.banned_nodes.InsertColumn(2, "reason") self.banned_nodes.SetColumnWidth(2, 150) self.sizer = wx.BoxSizer(orient=wx.VERTICAL) self.sizer.Add(self.list, 3, wx.EXPAND) self.sizer.Add(self.banned_label) self.sizer.Add(self.banned_nodes, 1, wx.EXPAND) self.SetSizer(self.sizer) self.listitem_id_pool = IdPool() self.connections = {} # SockAddr => listitem_id def contains_peer(self, sockaddr): return sockaddr in self.connections def add_peer(self, sockaddr): id = self.listitem_id_pool.get_id() self.connections[sockaddr] = id index = self.list.InsertStringItem(self.list.GetItemCount(), str(sockaddr.ip)) self.list.SetStringItem(index, 1, str(sockaddr.port)) self.list.SetStringItem(index, 2, "Connecting...") self.list.SetItemData(index, id) def add_banned_peer(self, sockaddr, reason): index = self.banned_nodes.InsertStringItem(self.list.GetItemCount(), str(sockaddr.ip)) self.banned_nodes.SetStringItem(index, 1, str(sockaddr.port)) self.banned_nodes.SetStringItem(index, 2, reason) def set_peer_status(self, sockaddr, status, color): id = self.connections[sockaddr] index = self.list.FindItemData(-1, id) self.list.SetStringItem(index, 2, status) self.list.SetItemBackgroundColour(index, color) def set_peer_version(self, sockaddr, version): id = self.connections[sockaddr] index = self.list.FindItemData(-1, id) self.list.SetStringItem(index, 3, version) def set_peer_height(self, sockaddr, height): id = self.connections[sockaddr] index = self.list.FindItemData(-1, id) self.list.SetStringItem(index, 4, height) def remove_peer(self, sockaddr): id = self.connections[sockaddr] index = self.list.FindItemData(-1, id) self.list.DeleteItem(index) self.listitem_id_pool.release_id(id) del self.connections[sockaddr]
class WalletPanel(wx.Panel, Observable): EVT_SEND = Observable.createevent() EVT_RECEIVE = Observable.createevent() EVT_SHOWHIDE_PRIVATE_KEYS = Observable.createevent() def __init__(self, parent): wx.Panel.__init__(self, parent) #, style=wx.SIMPLE_BORDER Observable.__init__(self) # Controls self.balance = BalancePanel(self) self.send_button = wx.Button(self, label="Send") self.receive_button = wx.Button(self, label="Receive") self.keylist = wx.ListCtrl(self, style=wx.LC_REPORT, size=(400,100)) self.keylist.InsertColumn(0, "Public Key") self.keylist.InsertColumn(1, "Private Key") self.keylist.InsertColumn(2, "Address") self.keylist.InsertColumn(3, "Description") self.keylist.SetColumnWidth(2, 250) self.keylist.SetColumnWidth(3, 250) self.show_hide_private_keys_button = wx.Button(self, label="Show Hide Private Keys") self.txhistory_list = wx.ListCtrl(self,style=wx.LC_REPORT, size=(400,100)) self.txhistory_list.InsertColumn(0, "Date") self.txhistory_list.InsertColumn(1, "Address") self.txhistory_list.InsertColumn(2, "Label") self.txhistory_list.InsertColumn(3, "Amount") self.txhistory_list.InsertColumn(4, "Confirmed") self.txhistory_list.SetColumnWidth(0, 120) self.txhistory_list.SetColumnWidth(1, 250) # Sizers self.sizer = wx.BoxSizer(orient=wx.VERTICAL) self.sizer.Add(self.balance, 0, wx.EXPAND) send_receive_sizer = wx.BoxSizer(orient=wx.HORIZONTAL) send_receive_sizer.Add(self.send_button, 0, wx.LEFT) send_receive_sizer.Add(self.receive_button, 0, wx.LEFT) self.sizer.Add(send_receive_sizer, 0, wx.EXPAND) self.sizer.Add(wx.StaticText(self, -1, "Keys: "), 0) self.sizer.Add(self.keylist, 0, wx.EXPAND) self.sizer.Add(self.show_hide_private_keys_button, 0) #self.sizer.Add(self.address_book, 0, wx.EXPAND) self.sizer.Add(wx.StaticText(self, -1, "Transactions: "), 0) self.sizer.Add(self.txhistory_list, 1, wx.EXPAND) self.SetSizer(self.sizer) # Events self.show_hide_private_keys_button.Bind(wx.EVT_BUTTON, self.on_show_hide_private_keys) self.send_button.Bind(wx.EVT_BUTTON, self.on_send) self.receive_button.Bind(wx.EVT_BUTTON, self.on_receive) # ChildViews (could be moved into some View directory service) self.send_view = SendView(self) self.receive_view = ReceiveView(self) self.enter_passphrase_view = EnterPassphraseView(self) # Initialize private data self.keylist_idpool = IdPool() self.keys = {} self.key_itemids = {} self.itemdata_ids = IdPool() self.tx_history_items = {} # id => itemdata_ids def create_enter_passphrase_view(self): return EnterPassphraseView(self) def on_send(self, event): self.fire(self.EVT_SEND) def on_receive(self, event): self.fire(self.EVT_RECEIVE) def add_key(self, id, public_key, private_key, address, description): itemid = self.keylist_idpool.get_id() self.keys[itemid] = (public_key, private_key, address, description) self.key_itemids[id] = itemid index = self.keylist.InsertStringItem(self.keylist.GetItemCount(), hexstr(public_key)) self.keylist.SetItemData(index, itemid) self.keylist.SetStringItem(index, 1, private_key) self.keylist.SetStringItem(index, 2, address) self.keylist.SetStringItem(index, 3, description) def set_key_description(self, id, description): itemid = self.key_itemids[id] index = self.keylist.FindItemData(-1, itemid) self.keylist.SetStringItem(index, 3, description) def set_key_private_key(self, id, private_key): itemid = self.key_itemids[id] index = self.keylist.FindItemData(-1, itemid) self.keylist.SetStringItem(index, 1, private_key) def select_key(self, id): itemid = self.key_itemids[id] index = self.keylist.FindItemData(-1, itemid) #Deselect all idx = self.keylist.GetFirstSelected() while idx != -1: self.keylist.Select(index, False) idx = self.keylist.GetNextSelected(idx) #Select and Focus self.keylist.Select(index) self.keylist.Focus(index) def add_transaction_history_item(self, id, txtime, address, label, amount, confirmed): itemdata = self.itemdata_ids.get_id() self.tx_history_items[id] = itemdata timestr = time.strftime("%Y-%m-%d %H:%m:%S", time.localtime(txtime)) index = self.txhistory_list.InsertStringItem(self.keylist.GetItemCount(),timestr) self.txhistory_list.SetStringItem(index, 1, address) self.txhistory_list.SetStringItem(index, 2, label) self.txhistory_list.SetStringItem(index, 3, str(amount * 1.0 / COIN )) self.txhistory_list.SetStringItem(index, 4, confirmed and "Yes" or "No") self.txhistory_list.SetItemData(index, itemdata) #if (amount < 0): # self.txhistory_list.SetItemBackgroundColour(index, (255, 200, 200)) #else: # self.txhistory_list.SetItemBackgroundColour(index, (200, 255, 200)) if confirmed: self.txhistory_list.SetItemBackgroundColour(index, (255, 255, 255)) else: self.txhistory_list.SetItemBackgroundColour(index, (255, 230, 148)) def set_confirmed(self, id, confirmed): itemdata = self.tx_history_items[id] index = self.txhistory_list.FindItemData(-1, itemdata) self.txhistory_list.SetStringItem(index, 4, confirmed and "Yes" or "No") if confirmed: self.txhistory_list.SetItemBackgroundColour(index, (255, 255, 255)) else: self.txhistory_list.SetItemBackgroundColour(index, (255, 230, 230)) def on_show_hide_private_keys(self, event): self.fire(self.EVT_SHOWHIDE_PRIVATE_KEYS)
class NodeView(wx.Panel): def __init__(self, parent): super(NodeView, self).__init__(parent, size=(380, 600)) self.list = wx.ListCtrl(self, style=wx.LC_REPORT) self.list.InsertColumn(0, "ip") self.list.SetColumnWidth(0, 80) self.list.InsertColumn(1, "port") self.list.SetColumnWidth(1, 50) self.list.InsertColumn(2, "status") self.list.SetColumnWidth(2, 80) self.list.InsertColumn(3, "version") self.list.SetColumnWidth(3, 80) self.list.InsertColumn(4, "height") self.list.SetColumnWidth(4, 80) self.banned_label = wx.StaticText(self, -1, "Banned nodes:") self.banned_nodes = wx.ListCtrl(self, style=wx.LC_REPORT) self.banned_nodes.InsertColumn(0, "ip") self.banned_nodes.SetColumnWidth(0, 80) self.banned_nodes.InsertColumn(1, "port") self.banned_nodes.SetColumnWidth(1, 50) self.banned_nodes.InsertColumn(2, "reason") self.banned_nodes.SetColumnWidth(2, 150) self.sizer = wx.BoxSizer(orient=wx.VERTICAL) self.sizer.Add(self.list, 3, wx.EXPAND) self.sizer.Add(self.banned_label) self.sizer.Add(self.banned_nodes, 1, wx.EXPAND) self.SetSizer(self.sizer) self.listitem_id_pool = IdPool() self.connections = {} # SockAddr => listitem_id def contains_peer(self, sockaddr): return sockaddr in self.connections def add_peer(self, sockaddr): id = self.listitem_id_pool.get_id() self.connections[sockaddr] = id index = self.list.InsertStringItem(self.list.GetItemCount(), str(sockaddr.ip)) self.list.SetStringItem(index, 1, str(sockaddr.port)) self.list.SetStringItem(index, 2, "Connecting...") self.list.SetItemData(index, id) def add_banned_peer(self, sockaddr, reason): index = self.banned_nodes.InsertStringItem(self.list.GetItemCount(), str(sockaddr.ip)) self.banned_nodes.SetStringItem(index, 1, str(sockaddr.port)) self.banned_nodes.SetStringItem(index, 2, reason) def set_peer_status(self, sockaddr, status, color): id = self.connections[sockaddr] index = self.list.FindItemData(-1, id) self.list.SetStringItem(index, 2, status) self.list.SetItemBackgroundColour(index, color) def set_peer_version(self, sockaddr, version): id = self.connections[sockaddr] index = self.list.FindItemData(-1, id) self.list.SetStringItem(index, 3, version) def set_peer_height(self, sockaddr, height): id = self.connections[sockaddr] index = self.list.FindItemData(-1, id) self.list.SetStringItem(index, 4, height) def remove_peer(self, sockaddr): id = self.connections[sockaddr] index = self.list.FindItemData(-1, id) self.list.DeleteItem(index) self.listitem_id_pool.release_id(id) del self.connections[sockaddr]