forked from xenserver/xsconsole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XSConsoleLayout.py
168 lines (131 loc) · 5.4 KB
/
XSConsoleLayout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# Copyright (c) 2007-2009 Citrix Systems Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from XSConsoleBases import *
from XSConsoleCurses import *
from XSConsoleHotData import *
class Layout:
WIN_MAIN = 0
WIN_TOPLINE = 1
APP_XSIZE = 80
APP_YSIZE = 24
instance = None
def __init__(self, inParent = None):
self.parent = inParent
self.windows = []
self.exitCommand = None # Not layout, but keep with layout for convenience
self.exitBanner = None # Not layout, but keep with layout for convenience
self.exitCommandIsExec = True # Not layout, but keep with layout for convenience
def AssertScreenSize(self):
consoleXSize = self.parent.XSize()
consoleYSize = self.parent.YSize()
if consoleXSize < self.APP_XSIZE or consoleYSize < self.APP_YSIZE:
raise Exception('Console size ('+str(consoleXSize)+', '+str(consoleYSize) +
') too small for application size ('+str(self.APP_XSIZE)+', '+str(self.APP_YSIZE) +')')
@classmethod
def Inst(cls):
if cls.instance is None:
cls.instance = Layout()
return cls.instance
@classmethod
def NewInst(cls):
cls.instance = Layout()
return cls.instance
def ParentSet(self, inParent):
self.parent = inParent
def Parent(self):
return self.parent
def ExitBanner(self):
return self.exitBanner
def ExitBannerSet(self, inBanner):
self.exitBanner = inBanner
def ExitCommand(self):
return self.exitCommand
def ExitCommandSet(self, inCommand):
self.exitCommand = inCommand
self.exitCommandIsExec = True
def SubshellCommandSet(self, inCommand):
self.exitCommand = inCommand
self.exitCommandIsExec = False
def ExitCommandIsExec(self):
return self.exitCommandIsExec
def Window(self, inNum):
return self.windows[inNum]
def TopDialogue(self):
return self.dialogues[-1]
def PushDialogue(self, inDialogue):
self.dialogues.append(inDialogue)
def PopDialogue(self):
if len(self.dialogues) < 1:
raise Exception("Stack underflow in PopDialogue")
self.TopDialogue().Destroy()
self.dialogues.pop()
if len(self.dialogues) == 1:
# When the display returns to the root screen, it's possible that data has changed, so
# delete the HotData cache to force a refetch
HotData.Inst().DeleteCache()
self.TopDialogue().UpdateFields()
self.Refresh()
def UpdateRootFields(self):
if len(self.dialogues) > 0:
self.dialogues[0].UpdateFields()
def LiveUpdateFields(self):
needsRefresh = False
if len(self.dialogues) > 0:
topDialogue = self.dialogues[-1]
if hasattr(topDialogue, 'LiveUpdateFields'):
topDialogue.LiveUpdateFields()
needsRefresh = True
return needsRefresh
def TransientBannerHandlerSet(self, inHandler):
self.transientBannerHandler = inHandler
def TransientBanner(self, inMessage):
self.transientBannerHandler(inMessage)
def WriteParentOffset(self, inParent):
self.AssertScreenSize()
# Centralise subsequent windows
inParent.OffsetSet(
(inParent.XSize() - self.APP_XSIZE) / 2,
(inParent.YSize() - self.APP_YSIZE) / 2)
def Create(self):
self.windows.append(CursesWindow(0,1,self.APP_XSIZE, self.APP_YSIZE-1, self.parent)) # MainWindow
self.windows.append(CursesWindow(0,0,self.APP_XSIZE,1, self.parent)) # Top line window
self.windows[self.WIN_MAIN].DefaultColourSet('MAIN_BASE')
self.windows[self.WIN_TOPLINE].DefaultColourSet('TOPLINE_BASE')
self.Window(self.WIN_MAIN).AddBox()
self.Window(self.WIN_MAIN).TitleSet("Configuration")
def CreateRootDialogue(self, inRootDialogue):
self.dialogues = [ inRootDialogue ]
def Reset(self):
while len(self.dialogues) > 1:
self.PopDialogue()
self.TopDialogue().Reset()
def Refresh(self):
self.Window(self.WIN_MAIN).Erase() # Unknown why main won't redraw without this
for window in self.windows:
window.Refresh()
for dialogue in self.dialogues:
dialogue.Render()
if not self.TopDialogue().NeedsCursor():
self.TopDialogue().CursorOff()
def Redraw(self):
for window in self.windows:
window.Win().redrawwin()
window.Win().refresh()
def Clear(self):
for window in self.windows:
window.Clear()
self.Refresh()
def DoUpdate(self):
curses.doupdate()