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

« back to all changes in this revision

Viewing changes to src/cursing/Notebook.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
# Dialog.py
 
23
#
 
24
# DESCRIPTION:
 
25
#
 
26
# NOTES:
 
27
#
 
28
 
 
29
 
 
30
from constants import *
 
31
import sio
 
32
from utility import _paintBorder
 
33
from Frame import Frame
 
34
 
 
35
class Notebook(Frame):
 
36
  """
 
37
    like a full screen container, but only a smaller portion of it.
 
38
    the user defines a screen region which makes up the Notebook...
 
39
    they may only put controls within this region.
 
40
  """
 
41
  def __init__(self, ParentContainer, r1=0, c1=0, r2=0, c2=0,
 
42
                **properties):
 
43
    SIOInstance = ParentContainer.Screen()
 
44
    Frame.__init__(ParentContainer, r1, c1, r2, c2, border=1, dropshadow=0)
 
45
    Container.__init__(self, SIOInstance, **properties)
 
46
    self._ChildOffsetY += 2
 
47
 
 
48
  def __del__(self):
 
49
     pass
 
50
 
 
51
  def SetPage(self, index):
 
52
    self._CurrentFrame = self.Frames[index]
 
53
    self.Paint()
 
54
 
 
55
  def _PaintBorder(self):
 
56
    self.LoLight()
 
57
    _paintBorder( self, self.Y+2, self.X, self._DialogHeight + 2,
 
58
      self._DialogWidth + 2, self.INSET, caption=self.CAPTION,
 
59
      captionColor=sio.C_DIALOG_TITLE)
 
60
 
 
61
  def NewPage(self, title):
 
62
    page = NotebookPage(self, r1=self.r1, c1=self.c1, r2=self.r2, c2=self.c2, title=title)
 
63
    self.AddFrame(page)
 
64
    self._AddButton(page)
 
65
    if self._CurrentFrame == self:
 
66
      self._CurrentFrame = page
 
67
 
 
68
  def _AddButton(self,page):
 
69
 ##   ctrl =
 
70
    newX = 0
 
71
    if len(self.Controls) > 0:
 
72
      newX  = self.Controls[-1:][0].X
 
73
      newX += len(self.Controls[-1:][0].CAPTION) + 2
 
74
 
 
75
    ctrl.X = newX
 
76
    ctrl.Y = self.Y
 
77
 
 
78
    self.AddControl(ctrl)
 
79
 
 
80
    for page in self.Frames:
 
81
      page.SetPageControls(self.Controls)
 
82
 
 
83
 
 
84
 
 
85
 
 
86
class NotebookButton(FocusedLabel):
 
87
  def __init__(self,Parent,MenuName,Y,X,DisplayName = "",
 
88
               **properties):
 
89
    self.maxLengthFixed = 0
 
90
    DisplayName = self.__FixDisplay(DisplayName)
 
91
    FocusedLabel.__init__(self,Parent,MenuName,Y,X,DisplayName, **properties)
 
92
    self.PARENT = Parent
 
93
    self.SetMethod("CLICK",self.ShowOff)
 
94
    self.items = []
 
95
    self.maxLength = 0
 
96
 
 
97
  def Run(self,v1,v2,v3):
 
98
    if v1 :
 
99
      self.ExecMethod("CLICK", self, None, None)
 
100
      if self.EXITFORM:
 
101
        return 1
 
102
    Container = self.SCREEN;
 
103
    global BACKWARDS
 
104
    while 1:
 
105
      if self.active != 1:
 
106
        self.breakUp = 1
 
107
      if self.breakUp :
 
108
        self.breakUp = 0
 
109
        return 0
 
110
      ch = Container.GetChar()
 
111
      if self.PARENT.BreakOrder(ch) :
 
112
        return
 
113
      if ch in (Container.TokNextField, Container.TokRightArrow):
 
114
        BACKWARDS=0
 
115
        return
 
116
      elif ch == Container.TokLeftArrow:
 
117
        BACKWARDS=1
 
118
        return
 
119
      elif ch in (Container.TokDownArrow,  Container.TokActivate):
 
120
        self.ExecMethod("CLICK", self, None, None)
 
121
        if self.EXITFORM:
 
122
          self.PARENT.Paint()
 
123
          if self.PARENT.__class__ != Container:
 
124
            self.PARENT.Refresh(None,None,None)
 
125
          return 1
 
126
        self.ExecMethod("SYSGOTFOCUS", None, None, None)
 
127
 
 
128
  def ShowOff(self,arg1, arg2,arg3):
 
129
    MenuHeight = len(self.items) + 2
 
130
    MenuWidth  = self.maxLength
 
131
    X = self.X
 
132
    Y = self.Y + 1
 
133
    Parent = self.PARENT
 
134
    Screen = Parent.SCREEN
 
135
    self.myscreen = Screen.CaptureScreen( Y, X, Y + MenuHeight ,
 
136
      X + MenuWidth )
 
137
    MenuWin = Dialog(Parent, Y, X, Y + MenuHeight, X + MenuWidth )
 
138
    count = 1
 
139
    self.EXITFORM = 0
 
140
    for i in range(len(self.items)):
 
141
      text = ''
 
142
      if self.items[i][0] == -1:
 
143
        text = (self.maxLength - 4) * chr(tiHLINE)
 
144
      else:
 
145
        newTitle = self.items[i][1]
 
146
        text = self.__FixDisplay(newTitle)
 
147
      item = MenuItem(MenuWin,str(self.items[i][0]),count,2,text,
 
148
          self.items[i][2], self.STATUSBARLINK)
 
149
      item.ITEMID = self.items[i][0]
 
150
      count += 1
 
151
      item.SetMethod("CLICK",self.ItemSelected)
 
152
      MenuWin.AddDialogControl(item)
 
153
      item.DeActivate(self.items[i][2])
 
154
    MenuWin.SetColor(sio.C_MENUBAR)
 
155
    MenuWin.INSET = 1
 
156
    MenuWin.RunDialog()
 
157
    Parent.Paint()
 
158
    Parent.Screen().Refresh()
 
159
 
 
160
  def __FixDisplay(self, newTitle):
 
161
    erg = newTitle
 
162
    if self.maxLengthFixed :
 
163
      newLen = len(newTitle)
 
164
      oldLen = self.maxLength -  4
 
165
      if newLen >= oldLen:
 
166
        oldLen -= 3
 
167
        oldLen = oldLen / 2
 
168
        erg = newTitle[:oldLen] + '...' + newTitle[-oldLen:]
 
169
      else:
 
170
        erg = newTitle + (oldLen-newLen)*' '
 
171
    return erg
 
172
 
 
173
  def Finalize(self):
 
174
    self.PARENT.AddControl(self)
 
175
 
 
176
  def ItemSelected(self,control, arg2,arg3):
 
177
    MenuHeight = len(self.items) + 2
 
178
    MenuWidth  = self.maxLength
 
179
    X = self.X
 
180
    Y = self.Y+ 1
 
181
    Parent = self.PARENT
 
182
    Screen = Parent.SCREEN
 
183
    Screen.RestoreScreen(Y,X, Y + MenuHeight , X + MenuWidth ,
 
184
      self.myscreen )
 
185
    if(self.GetMethod("CHOSEN") <> None):
 
186
      apply(self.GetMethod("CHOSEN"),(self,control.ITEMID,control.TITLE))
 
187
 
 
188
  def DeActivateItem(self,itemId,state):
 
189
    for i in range(0,len(self.items)):
 
190
      if self.items[i][0] == itemId:
 
191
        self.items[i][2] = state
 
192
        return
 
193
 
 
194
  def AddItem(self, itemId, itemCaption, itemDescription = "", initialState = 1):
 
195
    self.items.append( [ itemId, itemCaption, itemDescription, initialState ] )
 
196
    if not self.maxLengthFixed and self.maxLength < len(itemCaption)+4:
 
197
      self.maxLength = len(itemCaption)+4
 
198
 
 
199
  def InsertSeperator(self):
 
200
    self.items.append( [ -1, '', 0 ])
 
201
 
 
202
  def ChangeTitle(self,newTitle):
 
203
    newLen = len(newTitle)
 
204
    oldLen = len(self.CAPTION)
 
205
    if newLen >= oldLen:
 
206
      newTitle = self.__FixDisplay(newTitle)
 
207
      self.CAPTION = newTitle[:oldLen]
 
208
    else:
 
209
      newTitle = newTitle + (oldLen-newLen)*' '
 
210
      self.CAPTION = newTitle
 
211
 
 
212
  def Clear(self):
 
213
    self.items = []
 
214
 
 
215
  def GetWidth(self):
 
216
    return self.maxLength