📄 client_ui.py
字号:
'''This file is part of PypMsg.PypMsg is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.PypMsg is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with PypMsg. If not, see <http://www.gnu.org/licenses/>.'''import wxfrom core.client import Clientclass ClientWin(wx.Frame): def __init__(self, parent=None, id=-1, title='PypMsg: New Message', show=False, server1=None): #self.attachments = {'fils':[], 'dirs':[]} self.server = server1 self.client = Client(self.server) wx.Frame.__init__(self, parent, id, title, size=(450,300)) panel = wx.Panel(self, -1) self.hostCtrl = wx.TextCtrl(panel) self.atchCtrl = wx.TextCtrl(panel) self.messCtrl = wx.TextCtrl(panel, style=wx.TE_MULTILINE | wx.VSCROLL) fgs = wx.FlexGridSizer(3, 2, 7, 15) fgs.AddMany([ (wx.StaticText(panel, label='Host IP')), (self.hostCtrl, 1, wx.EXPAND), (wx.StaticText(panel, label='Attach')), (self.atchCtrl, 1, wx.EXPAND), (wx.StaticText(panel, label='Message')), (self.messCtrl, 1, wx.EXPAND) ]) fgs.AddGrowableRow(2, 1) fgs.AddGrowableCol(1, 1) self.atchList = wx.ListCtrl(panel, style=wx.LC_LIST) addAtchBtn = wx.Button(panel, label='Attach') addAtchBtn.Bind(wx.EVT_BUTTON, self.addAttachment) remAtchBtn = wx.Button(panel, label='Remove') remAtchBtn.Bind(wx.EVT_BUTTON, self.remAttachment) sendBtn = wx.Button(panel, label='Send') sendBtn.Bind(wx.EVT_BUTTON, self.sendMsg) vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(wx.StaticText(panel, label='Attachments:'), 0, wx.EXPAND | wx.BOTTOM, 5) vbox.Add(self.atchList, 1, wx.EXPAND | wx.ALL) vbox.Add(addAtchBtn, 0, wx.EXPAND | wx.TOP, 10) vbox.Add(remAtchBtn, 0, wx.EXPAND | wx.TOP, 10) vbox.Add(sendBtn, 0, wx.EXPAND | wx.TOP, 10) hbox = wx.BoxSizer() hbox.Add(fgs, 1, wx.EXPAND | wx.ALL, 15) hbox.Add(vbox, .2, wx.EXPAND | wx.TOP | wx.BOTTOM | wx.RIGHT, 15) panel.SetSizer(hbox) if show: self.Show() def sendMsg(self, event): self.client.sendMsg(self.hostCtrl.GetValue(), self.messCtrl.GetValue()) self.Close() def addAttachment(self, event): atch = self.atchCtrl.GetValue() atchStatus = self.client.addAttachment(atch) if 'Success' in atchStatus: if 'File' in atchStatus: self.atchList.InsertStringItem(len(self.client.attachments['fils']) + len(self.client.attachments['dirs']) - 1, atch) elif 'Folder' in atchStatus: self.atchList.InsertStringItem(len(self.client.attachments['dirs']) - 1, atch) else: self.atchList.InsertStringItem(0, '#ERROR#') else: wx.MessageDialog(None, atchStatus, 'Attachment', wx.OK | wx.ICON_EXCLAMATION | wx.CENTRE).ShowModal() def remAttachment(self, event): atch = self.atchList.GetNextSelected(-1) if not atch >= 0: wx.MessageDialog(None, 'Please select an attachment from the list to be removed.', 'Attachment', wx.OK | wx.ICON_EXCLAMATION | wx.CENTRE).ShowModal() return remStatus = self.client.remAttachment(self.atchList.GetItemText(atch)) if 'Success' in remStatus: self.atchList.DeleteItem(atch) else: wx.MessageDialog(None, remStatus, 'Attachment', wx.OK | wx.ICON_EXCLAMATION | wx.CENTRE).ShowModal()if __name__ == '__main__': app=wx.App() clWin = ClientWin(show = True) app.MainLoop()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -