ed_toolbar.py :  » GUI » wxPython » wxPython-src-2.8.11.0 » wxPython » wx » tools » Editra » src » 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 » GUI » wxPython 
wxPython » wxPython src 2.8.11.0 » wxPython » wx » tools » Editra » src » ed_toolbar.py
###############################################################################
# Name: ed_toolbar.py                                                         #
# Purpose: Editra's Toolbar                                                   #
# Author: Cody Precord <cprecord@editra.org>                                  #
# Copyright: (c) 2008 Cody Precord <staff@editra.org>                         #
# License: wxWindows License                                                  #
###############################################################################

"""
This module creates Editra's toolbar. This toolbar is very simple and only adds
automatic icon theming to whats already available in the base toolbar class.

@summary: Editra's ToolBar class

"""

__author__ = "Cody Precord <cprecord@editra.org>"
__svnid__ = "$Id: ed_toolbar.py 62466 2009-10-21 23:35:41Z CJP $"
__revision__ = "$Revision: 62466 $"

#--------------------------------------------------------------------------#
# Dependencies
import wx
import ed_glob
import ed_msg
from profiler import Profile_Get

_ = wx.GetTranslation
#--------------------------------------------------------------------------#
# Global Variables
TOOL_ID = [ ed_glob.ID_NEW, ed_glob.ID_OPEN, ed_glob.ID_SAVE, ed_glob.ID_PRINT,
            ed_glob.ID_UNDO, ed_glob.ID_REDO, ed_glob.ID_COPY, ed_glob.ID_CUT,
            ed_glob.ID_PASTE, ed_glob.ID_FIND, ed_glob.ID_FIND_REPLACE ]

#--------------------------------------------------------------------------#

class EdToolBar(wx.ToolBar):
    """Toolbar wrapper class
    @todo: make it more dynamic/configurable

    """
    def __init__(self, parent):
        """Initializes the toolbar
        @param parent: parent window of this toolbar

        """
        sstyle = wx.TB_HORIZONTAL | wx.NO_BORDER
        if wx.Platform == '__WXGTK__':
            sstyle = sstyle | wx.TB_DOCKABLE
        wx.ToolBar.__init__(self, parent, style=sstyle)

        # Attributes
        self._theme = Profile_Get('ICONS')
        self.SetToolBitmapSize(Profile_Get('ICON_SZ', 'size_tuple'))
        self._PopulateTools()

        # Message Handlers
        ed_msg.Subscribe(self.OnThemeChange, ed_msg.EDMSG_THEME_CHANGED)

        self.Realize()

    def __del__(self):
        ed_msg.Unsubscribe(self.OnThemeChange)

    #---- End Init ----#

    #---- Function Definitions----#
    def _PopulateTools(self):
        """Sets the tools in the toolbar
        @postcondition: all default tools are added to toolbar

        """
        # Place Icons in toolbar
        self.AddSimpleTool(ed_glob.ID_NEW, _("New"), _("Start a New File"))
        self.AddSimpleTool(ed_glob.ID_OPEN, _("Open"), _("Open"))
        self.AddSimpleTool(ed_glob.ID_SAVE, _("Save"), _("Save Current File"))
        self.AddSimpleTool(ed_glob.ID_PRINT, _("Print"),
                           _("Print Current File"))
        self.AddSeparator()
        self.AddSimpleTool(ed_glob.ID_UNDO, _("Undo"), _("Undo Last Action"))
        self.AddSimpleTool(ed_glob.ID_REDO, _("Redo"), _("Redo Last Undo"))
        self.AddSeparator()
        self.AddSimpleTool(ed_glob.ID_CUT, _("Cut"),
                           _("Cut Selected Text from File"))
        self.AddSimpleTool(ed_glob.ID_COPY, _("Copy"),
                           _("Copy Selected Text to Clipboard"))
        self.AddSimpleTool(ed_glob.ID_PASTE, _("Paste"),
                           _("Paste Text from Clipboard to File"))
        self.AddSeparator()
        self.AddSimpleTool(ed_glob.ID_FIND, _("Find"), _("Find Text"))
        self.AddSimpleTool(ed_glob.ID_FIND_REPLACE, _("Find/Replace"),
                           _("Find and Replace Text"))
        self.AddSeparator()

    def AddSimpleTool(self, tool_id, lbl, helpstr):
        """Overides the default function to allow for easier tool
        generation/placement by automatically getting an appropriate icon from
        the art provider.
        @param tool_id: Id of tool to add
        @param lbl: tool label
        @param helpstr: tool help string

        """
        if self.GetToolBitmapSize() == (16, 16):
            client = wx.ART_MENU
        else:
            client = wx.ART_TOOLBAR
        tool_bmp = wx.ArtProvider.GetBitmap(str(tool_id), client)
        wx.ToolBar.AddSimpleTool(self, tool_id, tool_bmp, _(lbl), _(helpstr))

    def GetToolTheme(self):
        """Returns the name of the current toolsets theme
        @return: name of icon theme used by this toolbar

        """
        return self._theme

    def OnThemeChange(self, msg):
        """Update the icons when the icon theme has changed
        @param msg: Message object

        """
        self.ReInit()

    def ReInit(self):
        """Re-Initializes the tools in the toolbar
        @postcondition: all tool icons are changed to match current theme

        """
        self._theme = Profile_Get('ICONS')
        csize = self.GetToolBitmapSize()
        self.SetToolBitmapSize(Profile_Get('ICON_SZ', 'size_tuple'))
        if self.GetToolBitmapSize() == (16, 16):
            client = wx.ART_MENU
        else:
            client = wx.ART_TOOLBAR

        for tool_id in TOOL_ID:
            bmp = wx.ArtProvider.GetBitmap(str(tool_id), client)
            self.SetToolNormalBitmap(tool_id, bmp)

        # HACK: to make toolbar resize properly when icon size changes
        if csize != self.GetToolBitmapSize():
            self.GetParent().Freeze()
            self.Hide()
            self.Show()
            self.GetParent().Thaw()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.