utils.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 » utils.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 wx

import icons

import os

def getApplication():
    """Gets the application instance object."""
    return wx.GetApp()

def getMainWindow():
    """Gets the main window."""
    app = getApplication()
    return app.getMainWindow()

def getLocalWindow():
    """Gets the local browsing window."""
    app = getApplication()
    return app.getLocalWindow()

def getRemoteWindow():
    """Gets the remote browsing window."""
    app = getApplication()
    return app.getRemoteWindow()

def getControlWindow():
    """Gets the control window."""
    app = getApplication()
    return app.getControlWindow()

def getApplicationConfigDirectory():
    """Returns the directory for application configuration information."""
    app = getApplication()
    return app.getConfigDirectory()

def getApplicationConfiguration():
    """Returns the application configuration object."""
    app = getApplication()
    return app.getConfiguration()

def getLoggers():
    """Returns the application global loggers.

    This returns a tuple of (console logger, download logger, and upload logger. These
    loggers are thread safe."""
    app = getApplication()
    return app.getLoggers()

def getAppIcon():
    """Gets the application main icon.

    The icon is returned as a wxIcon object."""
    icon = wx.Icon('ftpcube_XPM', wx.BITMAP_TYPE_XPM)
    icon.CopyFromBitmap(icons.ftpcube.getBitmap())
    return icon

def getAppThreadManager():
    """Gets the thread manager for the main application."""
    app = getApplication()
    thread_mgr = app.getThreadManager()
    return thread_mgr

def getTransferMethod():
    """Gets the transfer method configured for the main application."""
    app = getApplication()
    return app.getTransferMethod()

def initiateConnection(connect_opts):
    """Initiates a connection to a file transfer server.

    Connection options are a dictionary of attribute/values describing the connection to
    establish."""
    app = getApplication()
    app.initiateConnection(connect_opts)

def getStartPath():
    """Gets starting ptah for constructing related paths.

    This method tries to get the home path using an OS-dependent manner. If
    the start path cannot be determined, then the current working directory
    is used."""
    if os.environ.has_key('HOME'):
        return os.environ['HOME']
    elif os.environ.has_key('HOMEPATH'):
        return os.environ['HOMEPATH']
    else:
        return '.'

def beautifySize(size):
    """Returns a string representing the size in bytes in a more human readable
    way."""
    if size / 1073741824:
        return _("%(size)0.2f GBytes") %{ 'size' : (float(size) / 1073741824.0) }
    elif size / 1048576:
        return _("%(size)0.2f MBytes") %{ 'size' : (float(size) / 1048576.0) }
    elif size / 1024:
        return _("%(size)0.2f KBytes") %{ 'size' : (float(size) / 1024.0) }
    else:
        return _("%(size)s Bytes") %{ 'size' : size }

def addHorizontalSpaceTool(toolbar, width):
    """Adds horizontal space in a portable manner."""
    space = wx.StaticText(toolbar, -1, "")
    space.SetSize((width, -1))
    toolbar.AddControl(space)

def addLineSeparator(toolbar, height):
    """Adds a line separator to a toolbar."""
    addHorizontalSpaceTool(toolbar, 3)
    line = wx.StaticLine(toolbar, -1, style=wx.LI_VERTICAL)
    line.SetSize((-1, height))
    toolbar.AddControl(line)
    addHorizontalSpaceTool(toolbar, 3)

def getColumnText(list, index, col):
    """Gets the text from the specified column entry in a list."""
    item = list.GetItem(index, col)
    return item.GetText()

def getSelected(list):
    """Gets the selected items from a list object."""
    selected = [ ]
    item = -1
    while 1:
        item = list.GetNextItem(item, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)
        if item == -1:
            break
        selected.append(item)
    return selected

def setListColumnAlignment(list, col, align):
    """Sets the column alignment for a column in a list."""
    item_info = list.GetColumn(col)
    item_info.SetAlign(align)
    list.SetColumn(col, item_info)

def colorToTuple(color):
    """Coverts a color object to a tuple RGB tuple representing the color."""
    return (color.Red(), color.Green(), color.Blue())

def isStrOrUnicode(value):
    """Returns true if the value is either a string or a unicode type."""
    return isinstance(value, str) or isinstance(value, unicode)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.