[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r9181 - in trunk/gnue-forms/src/uidrivers/curses: . widgets
From: |
johannes |
Subject: |
[gnue] r9181 - in trunk/gnue-forms/src/uidrivers/curses: . widgets |
Date: |
Wed, 20 Dec 2006 03:16:18 -0600 (CST) |
Author: johannes
Date: 2006-12-20 03:16:17 -0600 (Wed, 20 Dec 2006)
New Revision: 9181
Modified:
trunk/gnue-forms/src/uidrivers/curses/UIdriver.py
trunk/gnue-forms/src/uidrivers/curses/widgets/form.py
trunk/gnue-forms/src/uidrivers/curses/widgets/page.py
Log:
Added Resize-support, so a form can change it's size when it's window
get's resized
Modified: trunk/gnue-forms/src/uidrivers/curses/UIdriver.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/UIdriver.py 2006-12-20 08:09:40 UTC
(rev 9180)
+++ trunk/gnue-forms/src/uidrivers/curses/UIdriver.py 2006-12-20 09:16:17 UTC
(rev 9181)
@@ -212,7 +212,10 @@
try:
key = self.__current_form.wait()
- if isinstance(key, basestring):
+ if key == curses.KEY_RESIZE:
+ self.__current_form.set_size_and_fit()
+
+ elif isinstance(key, basestring):
self._focus_widget._keypress(key)
else:
if self.__shiftkeys.has_key(key): # translate shifted f-key
@@ -332,7 +335,10 @@
return dialog.run()
finally:
- self.__current_form.refresh()
+ if self.__current_form:
+ self.__current_form.refresh()
+ else:
+ self.__screen.refresh()
# -------------------------------------------------------------------------
Modified: trunk/gnue-forms/src/uidrivers/curses/widgets/form.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/widgets/form.py 2006-12-20
08:09:40 UTC (rev 9180)
+++ trunk/gnue-forms/src/uidrivers/curses/widgets/form.py 2006-12-20
09:16:17 UTC (rev 9181)
@@ -224,6 +224,7 @@
(y, x) = self.__window.getmaxyx()
self.__window.refresh(1, 0, 1, 0, 1, x)
+
# -------------------------------------------------------------------------
# Update status bar
# -------------------------------------------------------------------------
@@ -233,32 +234,36 @@
if not self.ready():
return
- (y, x) = self.__window.getmaxyx()
- self.__window.bkgdset(' ', self._uiDriver.attr ['status'])
+ try:
+ (y, x) = self.__window.getmaxyx()
+ self.__window.bkgdset(' ', self._uiDriver.attr ['status'])
- tip = ('%-' + str(x - 25) + 's') % self.__tip
+ tip = ('%-' + str(x - 25) + 's') % self.__tip
- recstr = '%d/%d' % (self.__cur_rec, self.__max_rec)
- pagestr = '%d/%d' % (self.__cur_page, self.__max_page)
+ recstr = '%d/%d' % (self.__cur_rec, self.__max_rec)
+ pagestr = '%d/%d' % (self.__cur_page, self.__max_page)
- self.__window.addstr(y - 2, 0, '%s' % o(tip))
- self.__window.addstr(y - 2, x - 24, '%-4s' % o(self.__status))
- self.__window.addstr(y - 2, x - 19, '%-3s' % o(self.__insert))
- self.__window.addstr(y - 2, x - 15, '%-9s' % recstr)
- self.__window.addstr(y - 2, x - 5, '%-5s' % pagestr)
+ self.__window.addstr(y - 2, 0, '%s' % o(tip))
+ self.__window.addstr(y - 2, x - 24, '%-4s' % o(self.__status))
+ self.__window.addstr(y - 2, x - 19, '%-3s' % o(self.__insert))
+ self.__window.addstr(y - 2, x - 15, '%-9s' % recstr)
+ self.__window.addstr(y - 2, x - 5, '%-5s' % pagestr)
- self.__window.addch(y - 2, x - 25, curses.ACS_VLINE)
- self.__window.addch(y - 2, x - 20, curses.ACS_VLINE)
- self.__window.addch(y - 2, x - 16, curses.ACS_VLINE)
- self.__window.addch(y - 2, x - 6, curses.ACS_VLINE)
+ self.__window.addch(y - 2, x - 25, curses.ACS_VLINE)
+ self.__window.addch(y - 2, x - 20, curses.ACS_VLINE)
+ self.__window.addch(y - 2, x - 16, curses.ACS_VLINE)
+ self.__window.addch(y - 2, x - 6, curses.ACS_VLINE)
- self.__window.bkgdset(' ', self._uiDriver.attr['fkeys'])
+ self.__window.bkgdset(' ', self._uiDriver.attr['fkeys'])
- self.__window.addstr(y-1, 0, o(self._uiDriver.getFunctionKeyLine()))
- self.__window.clrtoeol()
+ self.__window.addstr(y-1, 0,
o(self._uiDriver.getFunctionKeyLine()))
+ self.__window.clrtoeol()
- self.__window.refresh(y - 2, 0, y - 2, 0, y, x)
+ self.__window.refresh(y - 2, 0, y - 2, 0, y, x)
+ except curses.error:
+ pass
+
# -------------------------------------------------------------------------
# Close the form
# -------------------------------------------------------------------------
@@ -281,22 +286,32 @@
(x, y) = self._uiDriver.screen_size()
self.__window = curses.newpad(y, x)
self.__window.keypad(1)
+
self._ui_set_title_(self._gfObject.title)
# The children of a form are pages which can have all the available
# space
+ pages_ok = True
(left, top, right, bottom) = self.get_canvas()
for child in self._children:
child.left = left
child.top = top
child.set_size_and_fit(right-left, bottom-top)
+ pages_ok &= child.enough_space
- self.__update_page_list()
- self.__update_status_bar()
+ gDebug(2, "Pages OK: %s" % pages_ok)
- self._uiDriver._focus_widget._ui_set_focus_(0)
+ try:
+ self.__update_page_list()
+ self.__update_status_bar()
+ except curses.error:
+ pass
+ if pages_ok:
+ self._uiDriver._focus_widget._ui_set_focus_(0)
+
+
# -------------------------------------------------------------------------
# Refresh the current form
# -------------------------------------------------------------------------
@@ -305,10 +320,14 @@
"""
Repaint the current form
"""
- (y, x) = self.__window.getmaxyx()
- self.__window.refresh(0, 0, 0, 0, y, x)
+ try:
+ (y, x) = self.__window.getmaxyx()
+ self.__window.refresh(0, 0, 0, 0, y, x)
+ except curses.error:
+ pass
+
# =============================================================================
# Configuration data
# =============================================================================
Modified: trunk/gnue-forms/src/uidrivers/curses/widgets/page.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/widgets/page.py 2006-12-20
08:09:40 UTC (rev 9180)
+++ trunk/gnue-forms/src/uidrivers/curses/widgets/page.py 2006-12-20
09:16:17 UTC (rev 9181)
@@ -33,7 +33,9 @@
class UIPage(ManagedBox):
vertical = True
+ enough_space = False
+
# -------------------------------------------------------------------------
# Initialize page
# -------------------------------------------------------------------------
@@ -62,6 +64,24 @@
# -------------------------------------------------------------------------
+ # Get the minimum space required by a page
+ # -------------------------------------------------------------------------
+
+ def get_size_hints(self, vertical=True):
+ """
+ The space requirements of a page in a managed form is made up of the
+ space needed by all it's children. In a positioned layout the space
+ available to (or needed by) a page is defined by the <layout> tag.
+ """
+
+ if self.managed:
+ return ManagedBox.get_size_hints(self, vertical)
+ else:
+ return (self._gfObject._layout.Char__width,
+ self._gfObject._layout.Char__height, 0, 0)
+
+
+ # -------------------------------------------------------------------------
# Set the page sizes and fit their children
# -------------------------------------------------------------------------
@@ -70,19 +90,27 @@
self.width = width
self.height = height
- if not self.managed:
- self._add_decoration_()
+ (minw, minh, label, prop) = self.get_size_hints(True)
- for child in self._children:
- child.left = child.chr_x
- child.top = child._gfObject.Char__y
+ if minw > width or minh > height:
+ self.__not_enough_space()
+ self.enough_space = False
- child.set_size_and_fit(child.chr_w, child.chr_h)
else:
- self.get_size_hints(True)
- ManagedBox.set_size_and_fit(self, width, height)
+ self.enough_space = True
+ if not self.managed:
+ self._add_decoration_()
+ for child in self._children:
+ child.left = child.chr_x
+ child.top = child._gfObject.Char__y
+
+ child.set_size_and_fit(child.chr_w, child.chr_h)
+ else:
+ ManagedBox.set_size_and_fit(self, width, height)
+
+
# -------------------------------------------------------------------------
# Write a text to a given position
# -------------------------------------------------------------------------
@@ -123,11 +151,13 @@
def wait(self):
- self.__window.move(self.__cursor[1], self.__cursor[0])
- gDebug(2, "Refresh of page: %s/%s %s/%s" % (self.top, self.left,
- self.bottom, self.right))
- self.__window.refresh(0, 0, self.top, self.left, self.bottom,
+ try:
+ self.__window.move(self.__cursor[1], self.__cursor[0])
+ self.__window.refresh(0, 0, self.top, self.left, self.bottom,
self.right)
+ except curses.error:
+ pass
+
return self.__get_key()
# -------------------------------------------------------------------------
@@ -210,6 +240,18 @@
return (0, cheight)
+ # -------------------------------------------------------------------------
+ # There is not enough space left to show the entire page
+ # -------------------------------------------------------------------------
+
+ def __not_enough_space(self):
+
+ text = u_("Not enough space available to display the page.")
+ self._add_decoration_()
+ self.write(0, 0, text, self._uiDriver.attr['background'])
+
+
+
# =============================================================================
# Configuration data
# =============================================================================
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r9181 - in trunk/gnue-forms/src/uidrivers/curses: . widgets,
johannes <=