consolewin.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 » consolewin.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 events
import utils
import version

import wx

class ConsoleWindow(wx.TextCtrl):
    """Main application console window.

    This serves as the primary console for displaying FTP commands and initialization
    information. The console window is color coded, differentiating between local, remote,
    and error messages. To write to the console window, widgets should post console
    events."""

    idPOPUP_CLEAR = wx.NewId()

    # Message kinds
    LOCAL  = 'local'
    REMOTE = 'remote'
    ERROR  = 'error'

    def __init__(self, parent):
        """Creates the console window."""
        if __debug__:
            print "Making console window."
        wx.TextCtrl.__init__(self, parent, -1, style=wx.TE_MULTILINE | wx.TE_READONLY |
            wx.NO_BORDER | wx.TE_RICH2)

        self.format = {
            self.LOCAL  : _("LOCAL > %s\n"),
            self.REMOTE : _("REMOTE> %s\n"),
            self.ERROR  : _("! - %s\n"),
        }

        self.colors = {
            self.LOCAL  : None,
            self.REMOTE : None,
            self.ERROR  : None, 
        }

        self.wxColors = {
            self.LOCAL  : None,
            self.REMOTE : None,
            self.ERROR  : None,
        }

        # Set ourselves to receive all console events
        self.Bind(events.EVT_CONSOLE, self.onConsoleEvent)
        evt_registry = events.getEventRegistry()
        evt_registry.registerEventListener(events.EVT_CONSOLE_TYPE, self)

        # Set up the console menu handler
        self.Bind(wx.EVT_RIGHT_DOWN, self.onRightClick, self)

    def displayBanner(self):
        """Displays the application startup banner."""
        self.insertColorText(self.LOCAL, _("Welcome to Ftpcube v%(ver)s")
            %{ 'ver' : version.getVersion() })
        self.insertColorText(self.LOCAL, _("Copyright (C) Michael Gilfix"))
        self.insertColorText(self.LOCAL, '===============================================')
        self.insertColorText(self.LOCAL, '')

    def insertColorText(self, kind, text):
        """Writes text to the console window in the appropriate color for the kind of
        message."""
        color = self.getColor(kind)
        text = self.format[kind] %text
        self.SetDefaultStyle(wx.TextAttr(color))
        self.AppendText(text)

    def getColor(self, kind):
        """Gets the wx color object for the specified text kind."""
        config = utils.getApplicationConfiguration()
        current_color = config[kind + '_color']
        if self.colors[kind] == current_color:
            wx_color = self.wxColors[kind]
        else:
            wx_color = apply(wx.Color, current_color)
            self.colors[kind] = current_color
            self.wxColors[kind] = wx_color
        return wx_color

    def onConsoleEvent(self, event):
        """Processes a console event by displaying the contents of the event to the console
        window."""
        self.insertColorText(event.kind, event.msg)

    def onRightClick(self, event):
        """Handles a right click by displaying the popupmenu at the click point."""
        menu = self.makePopupMenu()
        self.PopupMenu(menu, event.GetPosition())

    def makePopupMenu(self):
        """Creates the popup menu for operations on the console window."""
        menu = wx.Menu()
        menu.Append(self.idPOPUP_CLEAR, _("Clear Console"))

        self.Bind(wx.EVT_MENU, self.onClear, id=self.idPOPUP_CLEAR)
        return menu

    def onClear(self, event):
        """Processes a clearing of the console window event."""
        if __debug__:
            print "Clearing console window."
        self.Clear()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.