connectwin.py :  » Network » FtpCube » ftpcube-0.5.1 » libftpcube » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » FtpCube 
FtpCube » ftpcube 0.5.1 » libftpcube » connectwin.py
"""
FtpCube
Copyright (C) Michael Gilfix

This file is part of FtpCube.

You should have received a file COPYING containing license terms
along with this program; if not, write to Michael Gilfix
(mgilfix@eecs.tufts.edu) for a copy.

This version of FtpCube is open source; you can redistribute it and/or
modify it under the terms listed in the file COPYING.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
"""

import dialog
import messages
import transports.loader
import url
import utils

import wx

import re

class ConnectionWindow(dialog.DialogWindow):
    """Window describing the configuration to connect to a remote site.

    This class provides a window for configuring all the connection options for connecting
    to a remote site. The connection window can be used from the main application window
    to open up a new connection or be populated from the bookmark management window.

    The connection window contains three tabs: a login tab containing basic connection
    information, an advanced tab for specifying advanced connection options, and a settings
    tab for configuring Ftpcube behaviors for the connection.

    Calling the 'getOptions' method returns a dictionary containing all the connection
    information. The connection options can be retrieved after displaying the connection
    window to the user."""

    def __init__(self, parent, opts=None, title=None):
        """Creates and displays the connection window.

        If 'opts' is specified with a dictionary of connection options, those options are
        used to populate the current connection window."""
        if title is None:
            title = _("Ftpcube - Connect")
        if __debug__:
            print "Making a connection window. Title: %s" %title
        dialog.DialogWindow.__init__(self, parent, title)
        self.SetIcon(utils.getAppIcon())

        panel = self.getDialogPanel()
        notebook = wx.Notebook(panel, -1)

        self.login_tab = LoginTab(notebook, opts)
        notebook.AddPage(self.login_tab, _("Login info"))
        self.advanced_tab = AdvancedTab(notebook, opts)
        notebook.AddPage(self.advanced_tab, _("Advanced"))
        self.settings_tab = SettingsTab(notebook, opts)
        notebook.AddPage(self.settings_tab, _("Settings"))

        esizer = wx.BoxSizer(wx.VERTICAL)
        esizer.Add(notebook, 1, wx.EXPAND)
        panel.SetAutoLayout(True)
        panel.SetSizer(esizer)
        esizer.Fit(panel)
        esizer.SetSizeHints(panel)

        self.SetSizeHints(400, -1)
        self.renderDialog()

    def getOptions(self):
        """Returns a dictionary containing the connection window's options.

        The following options are defined:
            'host' - The host to connect to
            'port' - The port to connect to
            'username' - The user name to use for the connection
            'password' - The password to use for the connection
            'remotedir' - The remote directory to change to upon connection
            'localdir' - The local directory to change to upon connection
            'limit' - The number of logins allowed
            'retries' - The number of retries for a connection
            'main_idle' - The length of idle time before closing the connection
            'timeout' - The timeout to use for opening the connection
            'delay' - The delay between retries of logins
            'passive' - Whether to use active or passive transfers
            'transport' - The back-end transport (FTP/SFTP/etc.)
        """
        try:
            opts = { }
            opts.update(self.login_tab.getOptions())
            opts.update(self.advanced_tab.getOptions())
            opts.update(self.settings_tab.getOptions())
            return opts
        except Exception, strerror:
            return None

class LoginTab(wx.Panel):
    """Notebook tab showing basic login information for the connection."""

    idHOST      = wx.NewId()
    idPORT      = wx.NewId()
    idUSER      = wx.NewId()
    idPASS      = wx.NewId()
    idTRANSPORT = wx.NewId()
    idPERSONAL  = wx.NewId()
    idANON      = wx.NewId()
    idRADIO     = wx.NewId()

    def __init__(self, parent, opts=None):
        """Creates the login tab.

        If the supplied 'opts' dictionary is provided, then the controls are initialized to
        the values in the specified dictionary."""
        wx.Panel.__init__(self, parent, -1)

        host_label = wx.StaticText(self, -1, _("Host or URL"))
        port_label = wx.StaticText(self, -1, _("Port"))
        trans_label = wx.StaticText(self, -1, _("Transport"))
        rsizer = wx.GridSizer(1, 2)
        rsizer.AddMany([
            (port_label, 0, wx.EXPAND),
            (trans_label, 0, wx.EXPAND),
        ])
        rsizer.SetHGap(10)
        lsizer1 = wx.GridSizer(1, 2)
        lsizer1.AddMany([
            (host_label, 0, wx.EXPAND),
            (rsizer, 0, wx.EXPAND),
        ])
        lsizer1.SetHGap(20)

        self.host_entry = wx.TextCtrl(self, self.idHOST)
        if opts and opts['host']:
            self.host_entry.SetValue(opts['host'])
        self.port_entry = wx.TextCtrl(self, self.idPORT)
        if opts and opts['port']:
            self.port_entry.SetValue(str(opts['port']))
        trans_headers = transports.loader.listLoadedTransports()
        self.trans_box = wx.ComboBox(self, self.idTRANSPORT, trans_headers[0],
            choices=trans_headers, style=wx.CB_READONLY | wx.CB_SORT)
        if opts and opts['transport'] and opts['transport'] in trans_headers:
            self.trans_box.SetStringSelection(opts['transport'])
        if opts and not opts['port']:
            default_port = transports.loader.getDefaultPortForProtocol(trans_headers[0])
            self.port_entry.SetValue(str(opts['port']))
        subsizer = wx.BoxSizer(wx.HORIZONTAL)
        subsizer.Add(self.port_entry, 0, wx.EXPAND)
        subsizer.Add((10, 5), 1, wx.EXPAND)
        subsizer.Add(self.trans_box, 0, wx.EXPAND)
        esizer1 = wx.GridSizer(1, 2)
        esizer1.AddMany([
            (self.host_entry, 0, wx.EXPAND),
            (subsizer, 0, wx.EXPAND)
        ])
        esizer1.SetHGap(20)

        self.host_entry.Bind(wx.EVT_KILL_FOCUS, self.onHostURL)
        self.Bind(wx.EVT_TEXT, self.onPortChange, id=self.idPORT)
        self.Bind(wx.EVT_COMBOBOX, self.onTransportSelect, id=self.idTRANSPORT)

        user_label = wx.StaticText(self, -1, _("Username"))
        pass_label = wx.StaticText(self, -1, _("Password"))
        lsizer2 = wx.GridSizer(1, 2)
        lsizer2.AddMany([
            (user_label, 0, wx.EXPAND),
            (pass_label, 0, wx.EXPAND),
        ])
        lsizer2.SetHGap(20)

        self.user_entry = wx.TextCtrl(self, self.idUSER)
        if opts and opts['username']:
            self.user_entry.SetValue(opts['username'])
        self.pass_entry = wx.TextCtrl(self, self.idPASS, style=wx.TE_PASSWORD)
        if opts and opts['password']:
            self.pass_entry.SetValue(opts['password'])
        esizer2 = wx.GridSizer(1, 2)
        esizer2.AddMany([
            (self.user_entry, 0, wx.EXPAND),
            (self.pass_entry, 0, wx.EXPAND),
        ])
        esizer2.SetHGap(20)

        self.Bind(wx.EVT_TEXT, self.onTextUpdate, id=self.idUSER)
        self.Bind(wx.EVT_TEXT, self.onTextUpdate, id=self.idPASS)

        remote_label = wx.StaticText(self, -1, _("Remote Directory"))
        self.remote_entry = wx.TextCtrl(self, -1)
        if opts and opts['remotedir']:
            self.remote_entry.SetValue(opts['remotedir'])

        self.personal_button = wx.RadioButton(self, self.idPERSONAL, _("Personal Login"))
        self.anon_button = wx.RadioButton(self, self.idANON, _("Anonymous Login"))
        if opts and opts['username'] != utils.getApplicationConfiguration()['username']:
            self.personal_button.SetValue(True)
        else:
            self.onAnonClicked(None)
        bsizer = wx.BoxSizer(wx.HORIZONTAL)
        bsizer.Add((5, 1), 1, wx.EXPAND)
        bsizer.Add(self.personal_button, 0, wx.EXPAND)
        bsizer.Add((20, 1), 0, wx.EXPAND)
        bsizer.Add(self.anon_button, 0, wx.EXPAND)
        bsizer.Add((5, 1), 1, wx.EXPAND)

        self.Bind(wx.EVT_RADIOBUTTON, self.onPersonalClicked, id=self.idPERSONAL)
        self.Bind(wx.EVT_RADIOBUTTON, self.onAnonClicked, id=self.idANON)

        flexsizer = wx.FlexGridSizer(14, 3)
        flexsizer.AddMany([
            ((10, 10)), ((10, 10)), ((10, 10)),
            ((10, 5)), (lsizer1, 0, wx.EXPAND), ((10, 5)),
            ((10, 5)), ((10, 5)), ((10, 5)),
            ((10, 5)), (esizer1, 0, wx.EXPAND), ((10, 5)),
            ((10, 5)), ((10, 5)), ((10, 5)),
            ((10, 5)), (lsizer2, 0, wx.EXPAND), ((10, 5)),
            ((10, 5)), ((10, 5)), ((10, 5)),
            ((10, 5)), (esizer2, 0, wx.EXPAND), ((10, 5)),
            ((10, 5)), ((10, 5)), ((10, 5)),
            ((10, 5)), (remote_label, 1, wx.EXPAND), ((10, 5)),
            ((10, 5)), ((10, 5)), ((10, 5)),
            ((10, 5)), (self.remote_entry, 1, wx.EXPAND), ((10, 5)),
            ((10, 5)), ((10, 5)), ((10, 5)),
            ((10, 5)), (bsizer, 0, wx.EXPAND), ((10, 5)),
        ])
        flexsizer.AddGrowableCol(1)

        box = wx.StaticBox(self, -1, '')
        boxsizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
        boxsizer.Add(flexsizer, 1, wx.EXPAND)

        sizer = wx.FlexGridSizer(3, 3)
        sizer.AddMany([
            ((10, 10)), ((10, 10)), ((10, 10)),
            ((10, 10)), (boxsizer, 1, wx.EXPAND), ((10, 10)),
            ((10, 10)), ((10, 10)), ((10, 10)),
        ])
        sizer.AddGrowableCol(1)
        sizer.AddGrowableRow(1)
        self.SetAutoLayout(True)
        self.SetSizer(sizer)
        sizer.Fit(self)
        sizer.SetSizeHints(self)

    def onHostURL(self, event):
        """Checks the update of the HOST or URL text entry box to determine if the supplied
        content is a URL.

        If a URL is detected, then the information is extracted from the URL and used to
        populate the login page."""
        try:
            conn_url = url.URL(self.host_entry.GetValue())
        except ValueError:
            return
        config = utils.getApplicationConfiguration()

        user = conn_url.getUser()
        if user:
            if user == config['username']:
                self.anon_button.SetValue(True)
            else:
                self.personal_button.SetValue(True)
            self.user_entry.SetValue(user)
            passwd = conn_url.getPassword()
            if passwd:
                self.pass_entry.SetValue(passwd)
        else:
            self.onAnonClicked(None)

        self.host_entry.SetValue(conn_url.getHost())

        schema = conn_url.getSchema().upper()
        if schema in transports.loader.listLoadedTransports():
            self.trans_box.SetStringSelection(schema)
            self.onTransportSelect(None)

        port = conn_url.getPort()
        if port:
            self.port_entry.SetValue(str(port))
        else:
            # Set automatically by setting the transport box
            pass

        remote_path = conn_url.getPath()
        if remote_path:
            self.remote_entry.SetValue(remote_path)
        else:
            self.remote_entry.SetValue('')

    def onTransportSelect(self, event):
        """Handles the selection of a new transport.

        The port box is updated to the default port for the newly selected transport."""
        selected = self.trans_box.GetValue()
        default_port = transports.loader.getDefaultPortForProtocol(selected)
        self.port_entry.SetValue(str(default_port))

    def onPortChange(self, event):
        """Handles a change to the port text box.

        The port can never be a blank value or a non-int value. This resets the text box
        to contain the default port value in such cases."""
        valid = True
        try:
            int(self.port_entry.GetValue())
        except:
            valid = False
        if not valid:
            self.onTransportSelect(event)

    def onTextUpdate(self, event):
        """Handles an update to either the username and password fields.

        This results in the radio button being set to a personal login value."""
        self.personal_button.SetValue(True)

    def onPersonalClicked(self, event):
        """Handles the clicking of a personal login radio button.

        This wipes out the contents of the username and password boxes as set with the
        anonymous username and password."""
        self.user_entry.SetValue('')
        self.pass_entry.SetValue('')
        self.personal_button.SetValue(True)

    def onAnonClicked(self, event):
        """Handles the clicking of an anonymous login by populating the username and password
        fields with the anonmyous values."""
        config = utils.getApplicationConfiguration()
        if config['username'] is not None:
            self.user_entry.SetValue(config['username'])
        if config['password'] is not None:
            self.pass_entry.SetValue(config['password'])
        self.anon_button.SetValue(True)

    def getOptions(self):
        """Returns a dictionary of connection options from this page."""
        opts = {
            'host' : self.host_entry.GetValue().strip(),
            'port' : int(self.port_entry.GetValue()),
            'transport' : self.trans_box.GetValue(),
            'username' : self.user_entry.GetValue().strip(),
            'password' : self.pass_entry.GetValue().strip(),
            'remotedir' : self.remote_entry.GetValue(),
        }
        return opts

class AdvancedTab(wx.Panel):
    """Advanced connections settings tab."""

    idBUTTON_BROWSE   = wx.NewId()
    idRADIO_UNLIMITED = wx.NewId()
    idRADIO_ONCE      = wx.NewId()
    idRADIO_LIMIT     = wx.NewId()
    idLIMIT_ENTRY     = wx.NewId()

    def __init__(self, parent, opts=None):
        """Creates the advanced tab.

        If the supplied 'opts' dictionary is provided, then the controls are initialized to
        the values in the specified dictionary."""
        wx.Panel.__init__(self, parent, -1)

        label = wx.StaticText(self, -1, _("Local Directory"))
        self.local_entry = wx.TextCtrl(self, -1)
        if opts and opts['localdir']:
            self.local_entry.SetValue(opts['localdir'])
        self.browse_button = wx.Button(self, self.idBUTTON_BROWSE, '...', size=wx.Size(25, 25))

        self.Bind(wx.EVT_BUTTON, self.onBrowseClicked, id=self.idBUTTON_BROWSE)

        lsizer = wx.BoxSizer(wx.HORIZONTAL)
        lsizer.Add((10, 1))
        lsizer.Add(label, 0, wx.EXPAND)
        lsizer.Add((10, 1))
        esizer = wx.BoxSizer(wx.HORIZONTAL)
        esizer.Add((10, 1))
        esizer.Add(self.local_entry, 1, wx.EXPAND)
        esizer.Add((20, 1))
        esizer.Add(self.browse_button, 0, wx.EXPAND)
        esizer.Add((10, 1))
        box = wx.StaticBox(self, -1, '')
        bsizer1 = wx.StaticBoxSizer(box, wx.VERTICAL)
        bsizer1.Add((1, 10))
        bsizer1.Add(lsizer, 0, wx.EXPAND)
        bsizer1.Add((1, 5))
        bsizer1.Add(esizer, 0, wx.EXPAND)
        bsizer1.Add((1, 10))
        hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
        hsizer1.Add((10, 1))
        hsizer1.Add(bsizer1, 1, wx.EXPAND)
        hsizer1.Add((10, 1))

        label = wx.StaticText(self, -1, _("Number of Logins Allowed:"))
        self.unlimited_button = wx.RadioButton(self, self.idRADIO_UNLIMITED, _("Unlimited"))
        self.once_button = wx.RadioButton(self, self.idRADIO_ONCE, _("Login Only Once"))
        self.limit_button = wx.RadioButton(self, self.idRADIO_LIMIT, _("Limited"))
        self.limit_entry = wx.TextCtrl(self, self.idLIMIT_ENTRY, size=wx.Size(35, -1))
        if opts and opts['limit']:
            limit = opts['limit']
            if limit == 0:
                self.unlimited_button.SetValue(True)
            elif limit == 1:
                self.once_button.SetValue(True)
            else:
                self.limit_button.SetValue(True)
                self.limit_entry.SetValue(str(opts['limit']))
        else:
            self.unlimited_button.SetValue(True)

        self.Bind(wx.EVT_TEXT, self.onLimitChanged, id=self.idLIMIT_ENTRY)

        lsizer = wx.BoxSizer(wx.HORIZONTAL)
        lsizer.Add((10, 1), 1, wx.EXPAND)
        lsizer.Add(label, 0, wx.EXPAND)
        lsizer.Add((10, 1), 1, wx.EXPAND)
        rsizer = wx.BoxSizer(wx.HORIZONTAL)
        rsizer.Add(self.unlimited_button, 0, wx.EXPAND)
        rsizer.Add((10, 1), 1, wx.EXPAND)
        rsizer.Add(self.once_button, 0, wx.EXPAND)
        rsizer.Add((10, 1))
        rsizer.Add(self.limit_button, 0, wx.EXPAND)
        rsizer.Add((10, 1))
        rsizer.Add(self.limit_entry, 0, wx.EXPAND)
        rsizer.Add((10, 1), 1, wx.EXPAND)
        box = wx.StaticBox(self, -1, '')
        bsizer2 = wx.StaticBoxSizer(box, wx.VERTICAL)
        bsizer2.Add((1, 10))
        bsizer2.Add(lsizer, 0, wx.EXPAND)
        bsizer2.Add((1, 5))
        bsizer2.Add(rsizer, 0, wx.EXPAND)
        bsizer2.Add((1, 10))
        hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
        hsizer2.Add((10, 1))
        hsizer2.Add(bsizer2, 1, wx.EXPAND)
        hsizer2.Add((10, 1))

        box = wx.StaticBox(self, -1, '')
        boxsizer = wx.StaticBoxSizer(box, wx.VERTICAL)
        boxsizer.Add((1, 10))
        boxsizer.Add(hsizer1, 0, wx.EXPAND)
        boxsizer.Add((1, 10), 1, wx.EXPAND)
        boxsizer.Add(hsizer2, 0, wx.EXPAND)
        boxsizer.Add((1, 10))

        sizer = wx.FlexGridSizer(3, 3)
        sizer.AddMany([
            ((10, 10)), ((10, 10)), ((10, 10)),
            ((10, 10)), (boxsizer, 0, wx.EXPAND), ((10, 10)),
            ((10, 10)), ((10, 10)), ((10, 10)),
        ])
        sizer.AddGrowableCol(1)
        sizer.AddGrowableRow(1)
        self.SetAutoLayout(True)
        self.SetSizer(sizer)
        sizer.Fit(self)
        sizer.SetSizeHints(self)

    def onLimitChanged(self, event):
        """Handles a change to the limit text box to valid that the contents contain an
        integer.

        If an invalid input is provided, then the input is reset to the configuration
        default."""
        valid = True
        try:
            int(self.limit_entry.GetValue())
        except:
            valid = False
        if not valid:
            config = utils.getApplicationConfiguration()
            self.limit_entry.SetValue(str(config['limit']))

    def onBrowseClicked(self, event):
        """Displays a browser window to select a local directory."""
        path = messages.displayFileDialog(self, _("Ftpcube - Browse"))
        if path:
            self.local_entry.SetValue(path)

    def getOptions(self):
        """Returns a dictionary containing the advanced tab information."""
        limit = None
        if self.once_button.GetValue():
            limit = 1
        elif self.limit_button.GetValue():
            text = self.limit_entry.GetValue()
            if text:
                limit = int(text)

        opts = {
            'limit' : limit,
            'localdir' : self.local_entry.GetValue(),
        }
        return opts

class SettingsTab(wx.Panel):
    """Ftpcube behavior settings tab for this connection."""

    idRETRY   = wx.NewId()
    idIDLE    = wx.NewId()
    idTIMEOUT = wx.NewId()
    idDELAY   = wx.NewId()

    def __init__(self, parent, opts=None):
        """Creates the settings tab.

        If the supplied 'opts' dictionary is provided, then the controls are initialized to
        the values in the specified dictionary."""
        wx.Panel.__init__(self, parent, -1)

        label1 = wx.StaticText(self, -1, _("Connection Retries"))
        label2 = wx.StaticText(self, -1, _("Idle Timeout (sec)"))
        label3 = wx.StaticText(self, -1, _("Connect Timeout (sec)"))
        label4 = wx.StaticText(self, -1, _("Login Retry Delay (sec)"))
        self.retry_entry = wx.TextCtrl(self, self.idRETRY)
        if opts and opts['retries']:
            self.retry_entry.SetValue(str(opts['retries']))
        self.idle_entry = wx.TextCtrl(self, self.idIDLE)
        if opts and opts['main_idle']:
            self.idle_entry.SetValue(str(opts['main_idle']))
        self.timeout_entry = wx.TextCtrl(self, self.idTIMEOUT)
        if opts and opts['timeout']:
            self.timeout_entry.SetValue(str(opts['timeout']))
        self.delay_entry = wx.TextCtrl(self, self.idDELAY)
        if opts and opts['delay']:
            self.delay_entry.SetValue(str(opts['delay']))
        self.Bind(wx.EVT_TEXT, self.onRetryChange, id=self.idRETRY)
        self.Bind(wx.EVT_TEXT, self.onIdleChange, id=self.idIDLE)
        self.Bind(wx.EVT_TEXT, self.onTimeoutChange, id=self.idTIMEOUT)
        self.Bind(wx.EVT_TEXT, self.onDelayChange, id=self.idDELAY)

        fsizer = wx.FlexGridSizer(9, 2)
        fsizer.AddMany([
            ((1, 10)), ((1, 10)),
            (label1, 0, wx.EXPAND), (label2, 0, wx.EXPAND),
            ((1, 5)), ((1, 5)),
            (self.retry_entry, 0, wx.EXPAND), (self.idle_entry, 0, wx.EXPAND),
            ((1, 5)), ((1, 5)),
            (label3, 0, wx.EXPAND), (label4, 0, wx.EXPAND),
            ((1, 5)), ((1, 5)),
            (self.timeout_entry, 0, wx.EXPAND), (self.delay_entry, 0, wx.EXPAND),
            ((1, 10)), ((1, 10)),
        ])
        fsizer.SetHGap(40)
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        hsizer.Add((1, 1), 1, wx.EXPAND)
        hsizer.Add(fsizer, 0, wx.EXPAND)
        hsizer.Add((1, 1), 1, wx.EXPAND)
        box = wx.StaticBox(self, -1, '')
        bsizer1 = wx.StaticBoxSizer(box, wx.VERTICAL)
        bsizer1.Add(hsizer, 1, wx.EXPAND)
        hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
        hsizer1.Add((10, 1))
        hsizer1.Add(bsizer1, 1, wx.EXPAND)
        hsizer1.Add((10, 1))

        self.passive_button = wx.CheckBox(self, -1, _("Use Passive Transfers"),
            style=wx.NO_BORDER)
        if opts and opts['passive']:
            self.passive_button.SetValue(True)
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        hsizer.Add((10, 1), 1, wx.EXPAND)
        hsizer.Add(self.passive_button, 0, wx.EXPAND)
        hsizer.Add((10, 1), 1, wx.EXPAND)
        box = wx.StaticBox(self, -1, '')
        bsizer2 = wx.StaticBoxSizer(box, wx.VERTICAL)
        bsizer2.Add(hsizer, 1, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)
        hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
        hsizer2.Add((10, 1))
        hsizer2.Add(bsizer2, 1, wx.EXPAND)
        hsizer2.Add((10, 1))

        box = wx.StaticBox(self, -1, '')
        boxsizer = wx.StaticBoxSizer(box, wx.VERTICAL)
        boxsizer.Add((1, 10))
        boxsizer.Add(hsizer1, 0, wx.EXPAND)
        boxsizer.Add((1, 5), 1, wx.EXPAND)
        boxsizer.Add(hsizer2, 0, wx.EXPAND)
        boxsizer.Add((1, 10))

        sizer = wx.FlexGridSizer(3, 3)
        sizer.AddMany([
            ((10, 10)), ((10, 10)), ((10, 10)),
            ((10, 10)), (boxsizer, 0, wx.EXPAND), ((10, 10)),
            ((10, 10)), ((10, 10)), ((10, 10)),
        ])
        sizer.AddGrowableCol(1)
        sizer.AddGrowableRow(1)
        self.SetAutoLayout(True)
        self.SetSizer(sizer)
        sizer.Fit(self)
        sizer.SetSizeHints(self)

    def onRetryChange(self, event):
        """Validates the input change to verify that it is an integer or the default
        configuration is substituted."""
        valid = True
        try:
            int(self.retry_entry.GetValue())
        except:
            valid = False
        if not valid:
            config = utils.getApplicationConfiguration()
            retries = config['retries']
            if retries is None:
                retries = 5
            self.retry_entry.SetValue(int(retries))

    def onIdleChange(self, event):
        """Validates the input change to verify that it is an integer or the default
        configuration is substituted."""
        valid = True
        try:
            int(self.idle_entry.GetValue())
        except:
            valid = False
        if not valid:
            config = utils.getApplicationConfiguration()
            idle = config['main_idle']
            if idle is None:
                idle = 300
            self.idle_entry.SetValue(int(idle))

    def onTimeoutChange(self, event):
        """Validates the input change to verify that it is an integer or the default
        configuration is substituted."""
        valid = True
        try:
            int(self.timeout_entry.GetValue())
        except:
            valid = False
        if not valid:
            config = utils.getApplicationConfiguration()
            timeout = config['timeout']
            if timeout is None:
                timeout = 120
            self.timeout_entry.SetValue(int(timeout))

    def onDelayChange(self, event):
        """Validates the input change to verify that it is an integer or the default
        configuration is substituted."""
        valid = True
        try:
            int(self.delay_entry.GetValue())
        except:
            valid = False
        if not valid:
            config = utils.getApplicationConfiguration()
            delay = config['delay']
            if delay is None:
                delay = 5
            self.delay_entry.SetValue(int(delay))

    def getOptions(self):
        """Returns a dictionary containing the settings tab information."""
        opts = {
            'retries' : int(self.retry_entry.GetValue()),
            'main_idle' : int(self.idle_entry.GetValue()),
            'timeout' : int(self.timeout_entry.GetValue()),
            'delay' : int(self.delay_entry.GetValue()),
            'passive' : bool(self.passive_button.GetValue()),
        }
        return opts
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.