~ubuntu-branches/ubuntu/hardy/gnue-common/hardy

« back to all changes in this revision

Viewing changes to src/cursing/GraphicObject.py

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2005-03-09 11:06:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050309110631-8gvvn39q7tjz1kj6
Tags: upstream-0.5.14
ImportĀ upstreamĀ versionĀ 0.5.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# This file is part of GNU Enterprise.
 
3
#
 
4
# GNU Enterprise is free software; you can redistribute it
 
5
# and/or modify it under the terms of the GNU General Public
 
6
# License as published by the Free Software Foundation; either
 
7
# version 2, or (at your option) any later version.
 
8
#
 
9
# GNU Enterprise is distributed in the hope that it will be
 
10
# useful, but WITHOUT ANY WARRANTY; without even the implied
 
11
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 
12
# PURPOSE. See the GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public
 
15
# License along with program; see the file COPYING. If not,
 
16
# write to the Free Software Foundation, Inc., 59 Temple Place
 
17
# - Suite 330, Boston, MA 02111-1307, USA.
 
18
#
 
19
# Copyright 2002-2005 Free Software Foundation
 
20
#
 
21
# FILE:
 
22
# GraphicObject.py
 
23
#
 
24
# DESCRIPTION:
 
25
#
 
26
# NOTES:
 
27
#
 
28
 
 
29
 
 
30
import curses
 
31
 
 
32
from constants import *
 
33
 
 
34
class GraphicObject:
 
35
  """
 
36
  GraphicObject is the base class for Container: the full screen
 
37
  container, as well as for Control: the base class for all of the on-
 
38
  screen controls.
 
39
 
 
40
  GraphicObject maintains a private dictionary of properties and is used
 
41
  heavily throughout to modify appearance and behaviour.  GraphicObject
 
42
  methods are mostly concerned with managing data in the _Properties dict.
 
43
  """
 
44
 
 
45
  _InheritedProperties=[ "LOLIGHT_COLOR", "HILIGHT_COLOR" ]
 
46
 
 
47
 
 
48
  def __init__( self, sioScreen, **properties):
 
49
    self.__dict__.update(properties)
 
50
    self.SCREEN = sioScreen
 
51
    self.breakUp = 0
 
52
    self.SetColor( colorLow,colorHi)
 
53
    self.PRIOR_COLOR = colorLow
 
54
    self.active = 1
 
55
 
 
56
 
 
57
  def GetProperty(self, pptyName):
 
58
    return self.__dict__[pptyName]
 
59
 
 
60
 
 
61
  def SetProperty(self, pptyName, pptyVal):
 
62
    self.__dict__[pptyName] = pptyVal
 
63
 
 
64
 
 
65
  def HasProperty(self, pptyName):
 
66
    "Equally well named pptyExists(x)"
 
67
    return self.__dict__.has_key(pptyName)
 
68
 
 
69
 
 
70
  def IsPropertyInherited( self, pptyName):
 
71
    "True if arguement is an inherited property, false otherwise."
 
72
    return pptyName in self._InheritedProperties
 
73
 
 
74
 
 
75
  def InheritProperties(self, fromObj):
 
76
    """
 
77
    A beefy method.  InheritProperties uses each element in the private
 
78
    list, _InheritedProperties, verifies that each member exists in
 
79
    'fromObj' and that it DOESN'T exist in self before adding to self.
 
80
    """
 
81
    for pptyName in self._InheritedProperties:
 
82
      if fromObj.HasProperty(pptyName) and not self.HasProperty(pptyName):
 
83
          self.SetProperty(pptyName, fromObj.GetProperty(pptyName))
 
84
 
 
85
  #
 
86
  # various (of how much) utility methods
 
87
  #
 
88
 
 
89
  def Verify( self, arg1, arg2, arg3):
 
90
    return self.active
 
91
 
 
92
 
 
93
  def SetColor( self, color, focusColor=None):
 
94
    ""
 
95
    if type(color) == type(""):
 
96
      color = self.SCREEN.colors.__dict__['C_%s' % color]
 
97
    if focusColor == None:
 
98
      focusColor = color
 
99
    elif type(focusColor) == type(""):
 
100
      focusColor = self.SCREEN.colors.__dict__['C_%s' % focusColor]
 
101
 
 
102
    self.COLOR = color
 
103
    self.FOCUSCOLOR = focusColor
 
104
 
 
105
 
 
106
  def LoLight (self):
 
107
#    return
 
108
    Screen = self.SCREEN
 
109
    self._SetLight("LOLIGHT_COLOR", Screen.SetColor, Screen.LoLight)
 
110
 
 
111
 
 
112
  def HiLight(self):
 
113
    return
 
114
    Screen = self.SCREEN
 
115
    self._SetLight("HILIGHT_COLOR", Screen.SetColor, Screen.HiLight)
 
116
 
 
117
  #
 
118
  # private methods
 
119
  #
 
120
 
 
121
  def _SetLight(self, PropertyName, Setter, DefaultSetter):
 
122
    try:
 
123
      if curses.has_colors():
 
124
        Setter(self.__dict__[PropertyName])
 
125
        return
 
126
    except (KeyError, AttributeError):
 
127
      pass
 
128
    DefaultSetter()
 
129
 
 
130