2
# This file is part of GNU Enterprise.
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.
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.
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.
19
# Copyright 2002-2005 Free Software Foundation
30
from constants import *
32
from utility import _paintBorder
33
from Frame import Frame
35
class Notebook(Frame):
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.
41
def __init__(self, ParentContainer, r1=0, c1=0, r2=0, c2=0,
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
51
def SetPage(self, index):
52
self._CurrentFrame = self.Frames[index]
55
def _PaintBorder(self):
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)
61
def NewPage(self, title):
62
page = NotebookPage(self, r1=self.r1, c1=self.c1, r2=self.r2, c2=self.c2, title=title)
65
if self._CurrentFrame == self:
66
self._CurrentFrame = page
68
def _AddButton(self,page):
71
if len(self.Controls) > 0:
72
newX = self.Controls[-1:][0].X
73
newX += len(self.Controls[-1:][0].CAPTION) + 2
80
for page in self.Frames:
81
page.SetPageControls(self.Controls)
86
class NotebookButton(FocusedLabel):
87
def __init__(self,Parent,MenuName,Y,X,DisplayName = "",
89
self.maxLengthFixed = 0
90
DisplayName = self.__FixDisplay(DisplayName)
91
FocusedLabel.__init__(self,Parent,MenuName,Y,X,DisplayName, **properties)
93
self.SetMethod("CLICK",self.ShowOff)
97
def Run(self,v1,v2,v3):
99
self.ExecMethod("CLICK", self, None, None)
102
Container = self.SCREEN;
110
ch = Container.GetChar()
111
if self.PARENT.BreakOrder(ch) :
113
if ch in (Container.TokNextField, Container.TokRightArrow):
116
elif ch == Container.TokLeftArrow:
119
elif ch in (Container.TokDownArrow, Container.TokActivate):
120
self.ExecMethod("CLICK", self, None, None)
123
if self.PARENT.__class__ != Container:
124
self.PARENT.Refresh(None,None,None)
126
self.ExecMethod("SYSGOTFOCUS", None, None, None)
128
def ShowOff(self,arg1, arg2,arg3):
129
MenuHeight = len(self.items) + 2
130
MenuWidth = self.maxLength
134
Screen = Parent.SCREEN
135
self.myscreen = Screen.CaptureScreen( Y, X, Y + MenuHeight ,
137
MenuWin = Dialog(Parent, Y, X, Y + MenuHeight, X + MenuWidth )
140
for i in range(len(self.items)):
142
if self.items[i][0] == -1:
143
text = (self.maxLength - 4) * chr(tiHLINE)
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]
151
item.SetMethod("CLICK",self.ItemSelected)
152
MenuWin.AddDialogControl(item)
153
item.DeActivate(self.items[i][2])
154
MenuWin.SetColor(sio.C_MENUBAR)
158
Parent.Screen().Refresh()
160
def __FixDisplay(self, newTitle):
162
if self.maxLengthFixed :
163
newLen = len(newTitle)
164
oldLen = self.maxLength - 4
168
erg = newTitle[:oldLen] + '...' + newTitle[-oldLen:]
170
erg = newTitle + (oldLen-newLen)*' '
174
self.PARENT.AddControl(self)
176
def ItemSelected(self,control, arg2,arg3):
177
MenuHeight = len(self.items) + 2
178
MenuWidth = self.maxLength
182
Screen = Parent.SCREEN
183
Screen.RestoreScreen(Y,X, Y + MenuHeight , X + MenuWidth ,
185
if(self.GetMethod("CHOSEN") <> None):
186
apply(self.GetMethod("CHOSEN"),(self,control.ITEMID,control.TITLE))
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
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
199
def InsertSeperator(self):
200
self.items.append( [ -1, '', 0 ])
202
def ChangeTitle(self,newTitle):
203
newLen = len(newTitle)
204
oldLen = len(self.CAPTION)
206
newTitle = self.__FixDisplay(newTitle)
207
self.CAPTION = newTitle[:oldLen]
209
newTitle = newTitle + (oldLen-newLen)*' '
210
self.CAPTION = newTitle
216
return self.maxLength