controls/EnhancedStatusBar.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Tue, 17 Jan 2017 16:34:24 +0300
changeset 1638 3f86e9768f14
parent 1583 d91356480df9
child 1730 64d8f52bc8c8
permissions -rw-r--r--
merge
1574
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     1
# --------------------------------------------------------------------------- #
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     2
# ENHANCEDSTATUSBAR wxPython IMPLEMENTATION
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     3
# Python Code By:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     4
#
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     5
# Andrea Gavana, @ 31 May 2005
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     6
# Nitro, @ 21 September 2005
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     7
# Latest Revision: 21 September 2005, 19.57.20 GMT+2
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     8
# Latest Revision before Latest Revision: 21 September 2005, 18.29.35 GMT+2
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     9
# Latest Revision before Latest Revision before Latest Revision: 31 May 2005, 23.17 CET
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    10
#
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    11
#
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    12
# TODO List/Caveats
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    13
#
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    14
# 1. Some Requests/Features To Add?
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    15
#
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    16
#
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    17
# For All Kind Of Problems, Requests Of Enhancements And Bug Reports, Please
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    18
# Write To Me At:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    19
# 
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    20
#
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    21
# andrea.gavana@agip.it
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    22
# andrea_gavan@tin.it
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    23
#
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    24
# Or, Obviously, To The wxPython Mailing List!!!
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    25
#
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    26
#
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    27
# licensed under wxWidgets License (GPL compatible)
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    28
# End Of Comments
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    29
# --------------------------------------------------------------------------- #
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    30
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    31
""" Description:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    32
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    33
EnhancedStatusBar Is A Slight Modification (Actually A Subclassing) Of wx.StatusBar.
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    34
It Allows You To Add Almost Any Widget You Like To The wx.StatusBar Of Your Main
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    35
Frame Application And Also To Layout Them Properly.
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    36
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    37
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    38
What It Can Do:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    39
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    40
1) Almost All The Functionalities Of wx.StatusBar Are Still Present;
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    41
2) You Can Add Different Kind Of Widgets Into Every Field Of The EnhancedStatusBar;
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    42
3) The AddWidget() Methods Accepts 2 Layout Inputs:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    43
   - horizontalalignment: This Specify The Horizontal Alignment For Your Widget,
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    44
     And Can Be ESB_EXACT_FIT, ESB_ALIGN_CENTER_HORIZONTAL, ESB_ALIGN_LEFT And
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    45
     ESB_ALIGN_RIGHT;
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    46
   - varticalalignment: This Specify The Vertical Alignment For Your Widget,
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    47
     And Can Be ESB_EXACT_FIT, ESB_ALIGN_CENTER_VERTICAL, ESB_ALIGN_BOTTOM And
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    48
     ESB_ALIGN_LEFT;
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    49
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    50
EnhancedStatusBar Is Freeware And Distributed Under The wxPython License. 
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    51
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    52
Latest Revision: 21 September 2005, 19.57.20 GMT+2
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    53
Latest Revision before Latest Revision: 21 September 2005, 18.29.35 GMT+2
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    54
Latest Revision before Latest Revision before Latest Revision: 31 May 2005, 23.17 CET
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    55
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    56
"""
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    57
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    58
import wx
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    59
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    60
# Horizontal Alignment Constants
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    61
ESB_ALIGN_CENTER_VERTICAL = 1
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    62
ESB_ALIGN_TOP = 2
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    63
ESB_ALIGN_BOTTOM = 3
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    64
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    65
# Vertical Alignment Constants
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    66
ESB_ALIGN_CENTER_HORIZONTAL = 11
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    67
ESB_ALIGN_LEFT = 12
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    68
ESB_ALIGN_RIGHT = 13
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    69
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    70
# Exact Fit (Either Horizontal Or Vertical Or Both) Constant
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    71
ESB_EXACT_FIT = 20
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    72
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    73
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    74
# ---------------------------------------------------------------
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    75
# Class EnhancedStatusBar
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    76
# ---------------------------------------------------------------
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    77
# This Is The Main Class Implementation. See The Demo For Details
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    78
# ---------------------------------------------------------------
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    79
class EnhancedStatusBarItem(object):
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    80
    def __init__(self, widget, pos, horizontalalignment=ESB_ALIGN_CENTER_HORIZONTAL, verticalalignment=ESB_ALIGN_CENTER_VERTICAL):
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    81
        self.__dict__.update( locals() )
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    82
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    83
class EnhancedStatusBar(wx.StatusBar):
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    84
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    85
    def __init__(self, parent, id=wx.ID_ANY, style=wx.ST_SIZEGRIP,
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    86
                 name="EnhancedStatusBar"):
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    87
        """Default Class Constructor.
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    88
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    89
        EnhancedStatusBar.__init__(self, parent, id=wx.ID_ANY,
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    90
                                   style=wx.ST_SIZEGRIP,
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    91
                                   name="EnhancedStatusBar")
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    92
        """
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    93
        
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    94
        wx.StatusBar.__init__(self, parent, id, style, name)
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    95
        
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    96
        self._items = {}
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    97
        self._curPos = 0
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    98
        self._parent = parent
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    99
        
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   100
        wx.EVT_SIZE(self, self.OnSize) 
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   101
        wx.CallAfter(self.OnSize, None)
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   102
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   103
            
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   104
    def OnSize(self, event):
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   105
        """Handles The wx.EVT_SIZE Events For The StatusBar.
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   106
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   107
        Actually, All The Calculations Linked To HorizontalAlignment And
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   108
        VerticalAlignment Are Done In This Function."""
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   109
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   110
        for pos, item in self._items.items():
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   111
            widget, horizontalalignment, verticalalignment = item.widget, item.horizontalalignment, item.verticalalignment
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   112
           
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   113
            rect = self.GetFieldRect(pos)
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   114
            widgetpos = widget.GetPosition()
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   115
            widgetsize = widget.GetSize()
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   116
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   117
            rect = self.GetFieldRect(pos)
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   118
            
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   119
            if horizontalalignment == ESB_EXACT_FIT:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   120
                
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   121
                if verticalalignment == ESB_EXACT_FIT:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   122
                    """ 1 September 2015 Fix fit align """
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   123
                    widget.SetSize((rect.width-4, rect.height-4))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   124
                    widget.SetPosition((rect.x+2, rect.y+2))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   125
                elif verticalalignment == ESB_ALIGN_CENTER_VERTICAL:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   126
                    if widgetsize[1] < rect.width - 1:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   127
                        diffs = (rect.height - widgetsize[1])/2
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   128
                        widget.SetSize((rect.width-2, widgetsize[1]))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   129
                        widget.SetPosition((rect.x-1, rect.y+diffs))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   130
                    else:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   131
                        widget.SetSize((rect.width-2, widgetsize[1]))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   132
                        widget.SetPosition((rect.x-1, rect.y-1))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   133
                elif verticalalignment == ESB_ALIGN_TOP:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   134
                    widget.SetSize((rect.width-2, widgetsize[1]))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   135
                    widget.SetPosition((rect.x-1, rect.y))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   136
                elif verticalalignment == ESB_ALIGN_BOTTOM:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   137
                    widget.SetSize((rect.width-2, widgetsize[1]))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   138
                    widget.SetPosition((rect.x-1, rect.height-widgetsize[1]))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   139
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   140
            elif horizontalalignment == ESB_ALIGN_LEFT:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   141
                
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   142
                xpos = rect.x - 1
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   143
                if verticalalignment == ESB_EXACT_FIT:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   144
                    widget.SetSize((widgetsize[0], rect.height-2))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   145
                    widget.SetPosition((xpos, rect.y-1))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   146
                elif verticalalignment == ESB_ALIGN_CENTER_VERTICAL:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   147
                    if widgetsize[1] < rect.height - 1:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   148
                        diffs = (rect.height - widgetsize[1])/2
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   149
                        widget.SetPosition((xpos, rect.y+diffs))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   150
                    else:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   151
                        widget.SetSize((widgetsize[0], rect.height-2))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   152
                        widget.SetPosition((xpos, rect.y-1))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   153
                elif verticalalignment == ESB_ALIGN_TOP:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   154
                    widget.SetPosition((xpos, rect.y))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   155
                elif verticalalignment == ESB_ALIGN_BOTTOM:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   156
                    widget.SetPosition((xpos, rect.height-widgetsize[1]))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   157
                
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   158
            elif horizontalalignment == ESB_ALIGN_RIGHT:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   159
                
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   160
                xpos = rect.x + rect.width - widgetsize[0] - 1
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   161
                if verticalalignment == ESB_EXACT_FIT:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   162
                    widget.SetSize((widgetsize[0], rect.height-2))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   163
                    widget.SetPosition((xpos, rect.y-1))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   164
                elif verticalalignment == ESB_ALIGN_CENTER_VERTICAL:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   165
                    if widgetsize[1] < rect.height - 1:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   166
                        diffs = (rect.height - widgetsize[1])/2
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   167
                        widget.SetPosition((xpos, rect.y+diffs))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   168
                    else:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   169
                        widget.SetSize((widgetsize[0], rect.height-2))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   170
                        widget.SetPosition((xpos, rect.y-1))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   171
                elif verticalalignment == ESB_ALIGN_TOP:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   172
                    widget.SetPosition((xpos, rect.y))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   173
                elif verticalalignment == ESB_ALIGN_BOTTOM:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   174
                    widget.SetPosition((xpos, rect.height-widgetsize[1]))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   175
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   176
            elif horizontalalignment == ESB_ALIGN_CENTER_HORIZONTAL:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   177
                
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   178
                xpos = rect.x + (rect.width - widgetsize[0])/2 - 1
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   179
                if verticalalignment == ESB_EXACT_FIT:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   180
                    widget.SetSize((widgetsize[0], rect.height))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   181
                    widget.SetPosition((xpos, rect.y))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   182
                elif verticalalignment == ESB_ALIGN_CENTER_VERTICAL:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   183
                    if widgetsize[1] < rect.height - 1:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   184
                        diffs = (rect.height - widgetsize[1])/2
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   185
                        widget.SetPosition((xpos, rect.y+diffs))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   186
                    else:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   187
                        widget.SetSize((widgetsize[0], rect.height-1))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   188
                        widget.SetPosition((xpos, rect.y+1))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   189
                elif verticalalignment == ESB_ALIGN_TOP:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   190
                    widget.SetPosition((xpos, rect.y))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   191
                elif verticalalignment == ESB_ALIGN_BOTTOM:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   192
                    widget.SetPosition((xpos, rect.height-widgetsize[1]))
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   193
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   194
                
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   195
        if event is not None:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   196
            event.Skip()
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   197
        
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   198
        
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   199
    def AddWidget(self, widget, horizontalalignment=ESB_ALIGN_CENTER_HORIZONTAL,
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   200
                  verticalalignment=ESB_ALIGN_CENTER_VERTICAL, pos = -1):
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   201
        """Add A Widget To The EnhancedStatusBar.
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   202
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   203
        Parameters:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   204
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   205
        - horizontalalignment: This Can Be One Of:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   206
          a) ESB_EXACT_FIT: The Widget Will Fit Horizontally The StatusBar Field Width;
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   207
          b) ESB_ALIGN_CENTER_HORIZONTAL: The Widget Will Be Centered Horizontally In
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   208
             The StatusBar Field;
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   209
          c) ESB_ALIGN_LEFT: The Widget Will Be Left Aligned In The StatusBar Field;
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   210
          d) ESB_ALIGN_RIGHT: The Widget Will Be Right Aligned In The StatusBar Field;
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   211
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   212
        - verticalalignment:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   213
          a) ESB_EXACT_FIT: The Widget Will Fit Vertically The StatusBar Field Height;
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   214
          b) ESB_ALIGN_CENTER_VERTICAL: The Widget Will Be Centered Vertically In
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   215
             The StatusBar Field;
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   216
          c) ESB_ALIGN_BOTTOM: The Widget Will Be Bottom Aligned In The StatusBar Field;
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   217
          d) ESB_ALIGN_TOP: The Widget Will Be TOP Aligned In The StatusBar Field;
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   218
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   219
        """
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   220
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   221
        if pos == -1:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   222
            pos = self._curPos
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   223
            self._curPos += 1
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   224
        
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   225
        if self.GetFieldsCount() <= pos:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   226
            raise "\nERROR: EnhancedStatusBar has a max of %d items, you tried to set item #%d" % (self.GetFieldsCount(), pos)
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   227
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   228
        if horizontalalignment not in [ESB_ALIGN_CENTER_HORIZONTAL, ESB_EXACT_FIT,
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   229
                                       ESB_ALIGN_LEFT, ESB_ALIGN_RIGHT]:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   230
            raise '\nERROR: Parameter "horizontalalignment" Should Be One Of '\
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   231
                  '"ESB_ALIGN_CENTER_HORIZONTAL", "ESB_ALIGN_LEFT", "ESB_ALIGN_RIGHT"' \
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   232
                  '"ESB_EXACT_FIT"'
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   233
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   234
        if verticalalignment not in [ESB_ALIGN_CENTER_VERTICAL, ESB_EXACT_FIT,
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   235
                                     ESB_ALIGN_TOP, ESB_ALIGN_BOTTOM]:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   236
            raise '\nERROR: Parameter "verticalalignment" Should Be One Of '\
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   237
                  '"ESB_ALIGN_CENTER_VERTICAL", "ESB_ALIGN_TOP", "ESB_ALIGN_BOTTOM"' \
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   238
                  '"ESB_EXACT_FIT"'
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   239
        
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   240
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   241
        try:
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   242
            self.RemoveChild(self._items[pos].widget)
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   243
            self._items[pos].widget.Destroy()
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   244
        except KeyError: pass
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   245
        
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   246
        self._items[pos] = EnhancedStatusBarItem(widget, pos, horizontalalignment, verticalalignment)
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   247
        
ce9c0e68389c add progress bar to status bar
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   248
        wx.CallAfter(self.OnSize, None)