source: moxy/trunk/src/moxy/moxy_wx/tools.py @ 837

Last change on this file since 837 was 837, checked in by jemian, 11 years ago

refactor common code

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Date Revision Author HeadURL Id
File size: 3.4 KB
Line 
1#!/usr/bin/env python
2
3########### SVN repository information ###################
4# $Date: 2012-04-26 18:45:52 +0000 (Thu, 26 Apr 2012) $
5# $Author: jemian $
6# $Revision: 837 $
7# $URL: moxy/trunk/src/moxy/moxy_wx/tools.py $
8# $Id: tools.py 837 2012-04-26 18:45:52Z jemian $
9########### SVN repository information ###################
10
11'''
12tools and objects to build GUI
13
14Copyright (c) 2009 - 2012, UChicago Argonne, LLC.
15See LICENSE file for details.
16'''
17
18
19# - - - - - - - - - - - - - - - - - - Imports
20
21import wx                   #@UnusedImport
22import wx.lib.buttons
23import wx.lib.stattext
24
25
26# - - - - - - - - - - - - - - - - - - Global
27
28
29__svnid__ = "$Id: tools.py 837 2012-04-26 18:45:52Z jemian $"
30
31COLOR_MOVING = wx.Colour(179, 250, 142)         # pale green
32COLOR_NOT_MOVING = wx.Colour(200, 191, 140)     # not exactly background color
33COLOR_BACKGROUND = wx.Colour(237, 233, 227)     # boa-constructor uses this
34COLOR_PV_AUTOFILL = wx.Colour(200, 200, 200)    # pale grey
35COLOR_PV_NOT_OK = wx.Colour(254, 232, 255)      # pale pink
36COLOR_PV_OK = wx.Colour(235, 254, 231)          # pale green (another)
37
38COLOR_PV_NOT_DEFINED = COLOR_BACKGROUND
39
40COLOR_PALE_PURPLE = wx.Colour(200, 200, 255)    # my name for this
41COLOR_LIGHTGREEN = wx.Colour(200, 255, 200)     # my name for this
42COLOR_LIGHTRED = wx.Colour(255, 200, 200)       # my name for this
43COLOR_RED = wx.RED
44
45# - - - - - - - - - - - - - - - - - - classes
46
47
48class Button(wx.lib.buttons.GenButton):
49    '''custom Button widget'''
50   
51    def __init__(self, parent, label, name, tip, binding):
52        wx.lib.buttons.GenButton.__init__(self, id=wx.ID_ANY, 
53                              label=label, name=name, parent=parent)
54        self.SetToolTipString(tip)
55        self.Bind(wx.EVT_BUTTON, binding)
56
57
58class TextEntry(wx.TextCtrl):
59    '''custom wx.TextCtrl widget'''
60   
61    def __init__(self, parent, value='', 
62                       editable=True, 
63                       tooltip='', 
64                       handler=None,
65                       bgColor=None):
66        '''
67        Create and return a TextCtrl object.
68        [Enter] key event is bound to widget to call handler.
69       
70        :param obj parent: widget panel that will contain this TextCtrl
71        :param str|float value: initial value to set in the entry field
72        :param bool editable: should the entry field be editable?
73        :param str tooltip: short description of this field
74        :param obj handler: None or method to be called when [Enter] is pressed in this field
75        :param obj bgColor: None or background wx.Colour() object
76        :return: wx.TextCtrl object
77        '''
78        style = wx.TE_PROCESS_ENTER
79        wx.TextCtrl.__init__(self, parent, wx.ID_ANY, 'DemoView', style=style)
80        self.SetEditable( editable )
81        if value is not None:
82            self.SetValue( str(value) )
83        self.SetToolTipString( tooltip )
84        if handler is not None:
85            self.Bind(wx.EVT_TEXT_ENTER, handler)
86        if bgColor is not None:
87            self.SetBackgroundColour(bgColor)
88
89
90class Label(wx.lib.stattext.GenStaticText):
91    '''custom label widget'''
92   
93    def __init__(self, parent, label, tooltip=''):
94        wx.lib.stattext.GenStaticText.__init__(self, 
95           parent, wx.ID_ANY, str(label))
96        self.SetToolTipString(tooltip)
97
98
99# - - - - - - - - - - - - - - - - - - methods
100
101
102   
103def AcknowledgeDialog(parent, msg):
104    ''' present a modal dialog box with a message to be acknowledged '''
105    dlg = wx.MessageDialog(parent, msg,
106                "Acknowledge", wx.OK|wx.ICON_EXCLAMATION)
107    dlg.ShowModal()
108    dlg.Destroy()
109
110
111# - - - - - - - - - - - - - - - - - - main
Note: See TracBrowser for help on using the repository browser.