⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server_ui.py

📁 客户端服务器模式的python文件传输实例
💻 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.server import Serverfrom ui.client_ui import ClientWinclass ServerWin(wx.Frame):    def __init__(self, parent=None, id=-1, title='PypMsg: Main Window', show=False):        #self.msgQue = []        self.server = Server()                wx.Frame.__init__(self, parent, id, title, size=(600,400))                panel = wx.Panel(self, -1)                self.msgList = wx.ListCtrl(panel, style=wx.LC_REPORT)        self.msgList.InsertColumn(0, 'Address')        self.msgList.InsertColumn(1, 'Message')        self.msgList.Bind(wx.EVT_LIST_ITEM_SELECTED, self.showFileList)                msgVbox = wx.BoxSizer(wx.VERTICAL)        msgVbox.Add(self.msgList, 1, wx.EXPAND | wx.ALL)                self.filList = wx.ListCtrl(panel, style=wx.LC_LIST)        self.filList.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.downloadAttachment)        msgBtn = wx.Button(panel, label='New Message')        msgBtn.Bind(wx.EVT_BUTTON, self.newMessageWin)        reloadBtn = wx.Button(panel, label='Reload')        reloadBtn.Bind(wx.EVT_BUTTON, self.reloadMessages)                btnVbox = wx.BoxSizer(wx.VERTICAL)        btnVbox.Add(wx.StaticText(panel, label='Attachments:'), 0, wx.TOP)        btnVbox.Add(self.filList, 1, wx.EXPAND)        btnVbox.Add(msgBtn, 0, wx.EXPAND | wx.TOP, 10)        btnVbox.Add(reloadBtn, 0, wx.EXPAND | wx.TOP, 10)                mainHbox = wx.BoxSizer()        mainHbox.Add(msgVbox, 1, wx.EXPAND | wx.ALL, 10)        mainHbox.Add(btnVbox, 0, wx.EXPAND | wx.TOP | wx.RIGHT | wx.BOTTOM, 10)                panel.SetSizer(mainHbox)                if show:            self.Show()                self.server.startServing()        def downloadAttachment(self, event):        downloadStatus = self.server.downloadAttachment(self.msgList.GetNextSelected(-1), event.GetText())        if 'Success' in downloadStatus:            wx.MessageDialog(None, downloadStatus, 'Download', wx.OK | wx.ICON_INFORMATION | wx.CENTRE).ShowModal()        else:            wx.MessageDialog(None, downloadStatus, 'Attachment', wx.OK | wx.ICON_ERROR | wx.CENTRE).ShowModal()        def OnClose(self, event):        self.server.stopServing()        def reloadMessages(self, event=None):        self.msgList.DeleteAllItems()        self.filList.DeleteAllItems()        for (i, addr, msg) in [(rec['Index'], rec['Address'], rec['Message']) for rec in self.server.msgQue]:            self.msgList.InsertStringItem(i, addr)            self.msgList.SetStringItem(i, 1, msg)        def newMessageWin(self, event=None):        ClientWin(parent=self, show=True, server1=self.server)        def showFileList(self, event=None):        self.filList.DeleteAllItems()        for i, filename in [item['dirs'] for item in self.server.msgQue if item['Index'] == event.GetIndex()][0]:            self.filList.InsertStringItem(i, filename)        for i, filename in [item['fils'] for item in self.server.msgQue if item['Index'] == event.GetIndex()][0]:            self.filList.InsertStringItem(i, filename)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -