13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>wxPython</strong> griptshttp://www.zetcode.com/wxpython/gripts/self.PlaceIcon()def PlaceIcon(self):rect = self.GetFieldRect(1)self.icon.SetPosition((rect.x+3, rect.y+3))def OnSize(self, event):self.PlaceIcon()class Kika(wx.Frame):def __init__(self, parent, id, title):wx.Frame.__init__(self, parent, id, title, size=(250, 270))wx.StaticText(self, -1, 'Ftp site', (10, 20))wx.StaticText(self, -1, 'Login', (10, 60))wx.StaticText(self, -1, 'Password', (10, 100))self.ftpsite = wx.TextCtrl(self, -1, '', (110, 15), (120, -1))self.login = wx.TextCtrl(self, -1, '', (110, 55), (120, -1))self.password = wx.TextCtrl(self, -1, '', (110, 95), (120, -1), style=wx.TE_PASSWORD)self.ftp = Nonecon = wx.Button(self, 1, 'Connect', (10, 160))discon = wx.Button(self, 2, 'DisConnect', (120, 160))self.Bind(wx.EVT_BUTTON, self.OnConnect, id=1)self.Bind(wx.EVT_BUTTON, self.OnDisConnect, id=2)self.statusbar = MyStatusBar(self)self.SetStatusBar(self.statusbar)self.Centre()self.Show()def OnConnect(self, event):if not self.ftp:ftpsite = self.ftpsite.GetValue()login = self.login.GetValue()password = self.password.GetValue()try:self.ftp = FTP(ftpsite)var = self.ftp.login(login, password)self.statusbar.SetStatusText('User connected')self.statusbar.icon.SetBitmap(wx.Bitmap('icons/connected.png'))except AttributeError:self.statusbar.SetForegroundColour(wx.RED)self.statusbar.SetStatusText('Incorrect params')self.ftp = Noneexcept all_errors, err:self.statusbar.SetStatusText(str(err))self.ftp = Nonedef OnDisConnect(self, event):if self.ftp:self.ftp.quit()self.ftp = Noneself.statusbar.SetStatusText('User disconnected')self.statusbar.icon.SetBitmap(wx.Bitmap('icons/disconnected.png'))app = wx.App()Kika(None, -1, 'Kika')app.MainLoop()9 de 12 27/04/2008 1:09

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!