def testIsVariableSize1 (self): hLayout = HorizontalLayout () hLayout.add (LayoutTests.TestWindow ()) hLayout.add (LayoutTests.TestWindow ()) (variableWidth, variableHeight) = hLayout.isVariableSize() self.assertEqual (True, variableWidth) self.assertEqual (True, variableHeight)
def testSimpleHorizonalLayout (self): mainLayout = HorizontalLayout () test1 = LayoutTests.TestWindow () test2 = LayoutTests.TestWindow (2) test3 = LayoutTests.TestWindow (3) mainLayout.add (test1) mainLayout.add (test2) mainLayout.add (test3) mainLayout.move (0, 0) mainLayout.resize (100, 15) # Test widths self.assertEqual (100, mainLayout.width) self.assertEqual (100, test1.width) self.assertEqual (100, test2.width) self.assertEqual (100, test3.width) # Test heights self.assertEqual (10, test1.height) self.assertEqual (2, test2.height) self.assertEqual (3, test3.height) # Now test layout positions self.assertEqual (0, test1.x) self.assertEqual (0, test1.y) self.assertEqual (0, test2.x) self.assertEqual (10, test2.y) self.assertEqual (0, test3.x) self.assertEqual (12, test3.y)
def __init__(self): self.initializeScreen () # Buffer setups self.bufferLeftTop = Buffer () self.bufferLeftBottom = Buffer () self.bufferRight = Buffer () # Tab setup self.tabsWindow = TabTermWindow (['tab test1', 'tab test2'], 1) # Buffer windows setup self.bufferLayout = HorizontalLayout () self.layoutLeftTop = HorizontalLayout ([BufferTermWindow (self.bufferLeftTop), StatusBarTermWindow (self.bufferLeftTop.statusBar)]) self.layoutLeftBottom = HorizontalLayout ([BufferTermWindow (self.bufferLeftBottom), StatusBarTermWindow (self.bufferLeftBottom.statusBar)]) self.layoutRight = HorizontalLayout ([BufferTermWindow (self.bufferRight), StatusBarTermWindow (self.bufferRight.statusBar)]) self.horizontalLeft = HorizontalLayout ([self.layoutLeftTop, self.layoutLeftBottom]) self.verticalSplit = VerticalLayout ([self.horizontalLeft, self.layoutRight]) self.bufferLayout.add (self.verticalSplit) # Command window self.commandBar = CommandBar () self.commandBarWindow = CommandBarTermWindow (None, 1) self.layout = HorizontalLayout ([self.tabsWindow, self.bufferLayout, self.commandBarWindow]) self.layout.move (0, 0) self.layout.resize (self.screenWidth, self.screenHeight) self.bufferLeftTop.text.append ("Line 1") self.bufferLeftTop.text.append ("Line 2") self.bufferLeftTop.text.append ("Line 3") self.bufferLeftTop.text.append ("Line 4") self.bufferLeftTop.text.append ("") self.bufferLeftTop.text.append ('''And the Lord spake, saying, "First shalt thou take out the Holy Pin. Then, shalt thou count to three. No more. No less. Three shalt be the number thou shalt count, and the number of the counting shall be three. Four shalt thou not count, neither count thou two, excepting that thou then proceed to three. Five is right out. Once at the number three, being the third number to be reached, then, lobbest thou thy Holy Hand Grenade of Antioch towards thy foe, who, being naughty in My sight, shall snuff it."''') #self.resize () self.repaint()
def testIsVariableSize5 (self): hLayout = HorizontalLayout () # Both windows are fixed height -- variable height should be false hLayout2 = HorizontalLayout () hLayout2.add (LayoutTests.TestWindow (1)) hLayout2.add (LayoutTests.TestWindow (1)) hLayout.add (hLayout2) (variableWidth, variableHeight) = hLayout.isVariableSize() self.assertEqual (True, variableWidth) self.assertEqual (True, variableHeight)
def testIsVariableSize2 (self): hLayout = HorizontalLayout () # One or more fixed width -- this should be variable height hLayout.add (LayoutTests.TestWindow (1)) hLayout.add (LayoutTests.TestWindow ()) (variableWidth, variableHeight) = hLayout.isVariableSize() self.assertEqual (True, variableWidth) self.assertEqual (True, variableHeight)
class TerminalView(object): def __init__(self): self.initializeScreen () # Buffer setups self.bufferLeftTop = Buffer () self.bufferLeftBottom = Buffer () self.bufferRight = Buffer () # Tab setup self.tabsWindow = TabTermWindow (['tab test1', 'tab test2'], 1) # Buffer windows setup self.bufferLayout = HorizontalLayout () self.layoutLeftTop = HorizontalLayout ([BufferTermWindow (self.bufferLeftTop), StatusBarTermWindow (self.bufferLeftTop.statusBar)]) self.layoutLeftBottom = HorizontalLayout ([BufferTermWindow (self.bufferLeftBottom), StatusBarTermWindow (self.bufferLeftBottom.statusBar)]) self.layoutRight = HorizontalLayout ([BufferTermWindow (self.bufferRight), StatusBarTermWindow (self.bufferRight.statusBar)]) self.horizontalLeft = HorizontalLayout ([self.layoutLeftTop, self.layoutLeftBottom]) self.verticalSplit = VerticalLayout ([self.horizontalLeft, self.layoutRight]) self.bufferLayout.add (self.verticalSplit) # Command window self.commandBar = CommandBar () self.commandBarWindow = CommandBarTermWindow (None, 1) self.layout = HorizontalLayout ([self.tabsWindow, self.bufferLayout, self.commandBarWindow]) self.layout.move (0, 0) self.layout.resize (self.screenWidth, self.screenHeight) self.bufferLeftTop.text.append ("Line 1") self.bufferLeftTop.text.append ("Line 2") self.bufferLeftTop.text.append ("Line 3") self.bufferLeftTop.text.append ("Line 4") self.bufferLeftTop.text.append ("") self.bufferLeftTop.text.append ('''And the Lord spake, saying, "First shalt thou take out the Holy Pin. Then, shalt thou count to three. No more. No less. Three shalt be the number thou shalt count, and the number of the counting shall be three. Four shalt thou not count, neither count thou two, excepting that thou then proceed to three. Five is right out. Once at the number three, being the third number to be reached, then, lobbest thou thy Holy Hand Grenade of Antioch towards thy foe, who, being naughty in My sight, shall snuff it."''') #self.resize () self.repaint() def __del__ (self): curses.endwin () def initializeScreen (self): self.screen = curses.initscr () curses.start_color () curses.noecho () curses.cbreak () (self.screenHeight, self.screenWidth) = self.screen.getmaxyx () pass def repaint (self): self.screen.clear () self.screen.refresh () self.layout.repaint () def resize (self): (self.screenHeight, self.screenWidth) = self.screen.getmaxyx () self.layout.resize (self.screenWidth, self.screenHeight) self.repaint () def run (self): while True: ch = self.screen.getch () if ch == curses.KEY_RESIZE: self.resize () else: break
def testHorizontalAndVerticalLayout1 (self): ''' Essentially make a buffer layout with: 2 horizonal layouts on the left and one vertical layout on the right: ------------------------- | | | | | | | | | |-----------| | | | | | | | | | | |-----------|-----------| ''' mainLayout = HorizontalLayout () horizontalLeft = HorizontalLayout () bufferLeftTop = LayoutTests.TestWindow () bufferLeftBottom = LayoutTests.TestWindow () horizontalLeft.add (bufferLeftTop) horizontalLeft.add (bufferLeftBottom) verticalSplit = VerticalLayout () bufferRight = LayoutTests.TestWindow () verticalSplit.add (horizontalLeft) verticalSplit.add (bufferRight) tabWindow = LayoutTests.TestWindow (1) commandBar = LayoutTests.TestWindow (1) mainLayout.add (tabWindow) mainLayout.add (verticalSplit) mainLayout.add (commandBar) mainLayout.move (0, 0) mainLayout.resize (100, 16) self.assertEqual (1, tabWindow.height) self.assertEqual (1, commandBar.height) self.assertEqual (14, verticalSplit.height) self.assertEqual (14, bufferRight.height) self.assertEqual (14/2, bufferLeftTop.height) self.assertEqual (14/2, bufferLeftBottom.height) self.assertEqual (0, tabWindow.x) self.assertEqual (0, tabWindow.y) self.assertEqual (0, verticalSplit.x) self.assertEqual (1, verticalSplit.y) self.assertEqual (0, commandBar.x) self.assertEqual (15, commandBar.y) self.assertEqual (0, bufferLeftTop.x) self.assertEqual (1, bufferLeftTop.y) self.assertEqual (0, bufferLeftBottom.x) self.assertEqual (8, bufferLeftBottom.y) self.assertEqual (100/2, bufferRight.x) self.assertEqual (1, bufferRight.y)
def testSimpleHorizonalLayout3 (self): mainLayout = HorizontalLayout () bufferLayout = HorizontalLayout () buffer1 = LayoutTests.TestWindow (9) buffer2 = LayoutTests.TestWindow () bufferLayout.add (buffer1) bufferLayout.add (buffer2) tabWindow = LayoutTests.TestWindow (1) commandBar = LayoutTests.TestWindow (1) mainLayout.add (tabWindow) mainLayout.add (bufferLayout) mainLayout.add (commandBar) tabWindow.height = 10 commandBar.height = 10 mainLayout.move (0, 0) mainLayout.resize (100, 16) self.assertEqual (14, bufferLayout.height) self.assertEqual (9, buffer1.height) self.assertEqual (5, buffer2.height) self.assertEqual (1, tabWindow.height) self.assertEqual (1, commandBar.height) self.assertEqual (0, tabWindow.x) self.assertEqual (0, tabWindow.y) self.assertEqual (0, bufferLayout.x) self.assertEqual (1, bufferLayout.y) self.assertEqual (0, commandBar.x) self.assertEqual (15, commandBar.y) self.assertEqual (0, tabWindow.x) self.assertEqual (0, tabWindow.y) self.assertEqual (0, bufferLayout.x) self.assertEqual (1, bufferLayout.y) self.assertEqual (0, buffer1.x) self.assertEqual (1, buffer1.y) self.assertEqual (0, buffer2.x) self.assertEqual (10, buffer2.y) self.assertEqual (0, commandBar.x) self.assertEqual (15, commandBar.y)
def testSimpleHorizonalLayout2 (self): mainLayout = HorizontalLayout () bufferLayout = HorizontalLayout () buffer1 = LayoutTests.TestWindow () buffer2 = LayoutTests.TestWindow () bufferLayout.add (buffer1) bufferLayout.add (buffer2) tabWindow = LayoutTests.TestWindow (1) commandBar = LayoutTests.TestWindow (1) mainLayout.add (tabWindow) mainLayout.add (bufferLayout) mainLayout.add (commandBar) mainLayout.resize (100, 16) self.assertEqual (100, mainLayout.width) self.assertEqual (100, bufferLayout.width) self.assertEqual (100, buffer1.width) self.assertEqual (100, buffer2.width) self.assertEqual (100, tabWindow.width) self.assertEqual (100, commandBar.width) self.assertEqual (14, bufferLayout.height) self.assertEqual (7, buffer1.height) self.assertEqual (7, buffer2.height) self.assertEqual (1, tabWindow.height) self.assertEqual (1, commandBar.height) self.assertEqual (0, tabWindow.x) self.assertEqual (0, tabWindow.y) self.assertEqual (0, bufferLayout.x) self.assertEqual (1, bufferLayout.y) self.assertEqual (0, buffer1.x) self.assertEqual (1, buffer1.y) self.assertEqual (0, buffer2.x) self.assertEqual (8, buffer2.y) self.assertEqual (0, commandBar.x) self.assertEqual (15, commandBar.y)