MANIFEST.in | 11 +-
__init__.py | 17 ----
configscreen.py | 182 ---------------------------------------------
menuscreen.py | 57 --------------
newt_syrup/__init__.py | 17 ++++
newt_syrup/configscreen.py | 182 +++++++++++++++++++++++++++++++++++++++++++++
newt_syrup/menuscreen.py | 57 ++++++++++++++
7 files changed, 264 insertions(+), 259 deletions(-)
New commits:
commit da48829f6a19f744058143afc2bc9266f197d0d9
Author: Darryl L. Pierce <dpierce(a)redhat.com>
Date: Wed Aug 4 11:02:17 2010 -0400
A few more packaging changes.
Moved the library files into a separate subdirectory and modified the
MANIFEST to reflect those changes.
diff --git a/MANIFEST.in b/MANIFEST.in
index 8567abc..3ea5aad 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,4 +1,9 @@
-include AUTHORS ChangeLog COPYING
+include AUTHORS
+include ChangeLog
+include COPYING
-include *.py
-recursive-include examples *
\ No newline at end of file
+include newt_syrup/__init__.py
+include newt_syrup/configscreen.py
+include newt_syrup/menuscreen.py
+
+include examples/selections.py
diff --git a/__init__.py b/__init__.py
deleted file mode 100644
index afda660..0000000
--- a/__init__.py
+++ /dev/null
@@ -1,17 +0,0 @@
-# __init__.py - Copyright (C) 2009 Red Hat, Inc.
-# Written by Darryl L. Pierce <dpierce(a)redhat.com>
-#
-# 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 of the License.
-#
-# 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. A copy of the GNU General Public License is
-# also available at
http://www.gnu.org/copyleft/gpl.html.
diff --git a/configscreen.py b/configscreen.py
deleted file mode 100644
index 4fd6525..0000000
--- a/configscreen.py
+++ /dev/null
@@ -1,182 +0,0 @@
-# configscreen.py - Copyright (C) 2009 Red Hat, Inc.
-# Written by Darryl L. Pierce <dpierce(a)redhat.com>
-#
-# 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 of the License.
-#
-# 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. A copy of the GNU General Public License is
-# also available at
http://www.gnu.org/copyleft/gpl.html.
-
-from snack import *
-import traceback
-
-BACK_BUTTON = "back"
-NEXT_BUTTON = "next"
-CANCEL_BUTTON = "cancel"
-FINISH_BUTTON = "finish"
-
-class ConfigScreen:
- '''Enables the creation of navigable, multi-paged configuration
screens.'''
-
- def __init__(self, title):
- self.__title = title
- self.__current_page = 1
- self.__finished = False
-
- def get_title(self):
- return self.__title
-
- def set_finished(self):
- self.__finished = True
-
- def get_elements_for_page(self, screen, page):
- return []
-
- def page_has_next(self, page):
- return False
-
- def page_has_finish(self, page):
- return False
-
- def get_back_page(self, page):
- if page > 1: return page - 1
- return page
-
- def go_back(self):
- self.__current_page = self.get_back_page(self.__current_page)
-
- def get_next_page(self, page):
- return page + 1
-
- def go_next(self):
- self.__current_page = self.get_next_page(self.__current_page)
-
- def validate_input(self, page, errors):
- return True
-
- def process_input(self, page):
- return
-
- def get_page_list(self):
- return []
-
- def get_current_page(self):
- 0
-
- def start(self):
- active = True
- while active and (self.__finished == False):
- screen = SnackScreen()
- elements = self.get_elements_for_page(screen, self.__current_page)
- # TODO: need to set the form height to the number of elements on the page
- gridform = GridForm(screen, self.get_title(), 2, 2)
-
- # Here you would put the list of elements
- # and programmatically set the indicator as
- # they're rendered
- pages = self.get_page_list()
- if len(pages) > 0:
- leftmenu = Grid(2, len(pages))
- current_element = 0
- for page in pages:
- leftmenu.setField(Label(page), 0, current_element, anchorLeft = 1)
- indicator = " "
- if current_element == self.__current_page - 1:
- indicator = "<-"
- leftmenu.setField(Label(indicator), 1, current_element)
- current_element += 1
- gridform.add(leftmenu, 0, 0, anchorTop = 1, padding = (3, 0, 3, 0))
-
- content = Grid(1, len(elements) + 1)
- current_element = 0
- for element in elements:
- content.setField(element, 0, current_element)
- current_element += 1
- # create the navigation buttons
- buttons = []
- if self.__current_page > 1: buttons.append(["Back", BACK_BUTTON,
"F11"])
- if self.page_has_next(self.__current_page): buttons.append(["Next",
NEXT_BUTTON, "F12"])
- if self.page_has_finish(self.__current_page):
buttons.append(["Finish", FINISH_BUTTON, "F10"])
- buttons.append(["Cancel", CANCEL_BUTTON, "ESC"])
- buttonbar = ButtonBar(screen, buttons)
- content.setField(buttonbar, 0, current_element, growx = 1)
- gridform.add(content, 1, 0, anchorTop = 1)
- current_element += 1
- try:
- result = gridform.runOnce()
- pressed = buttonbar.buttonPressed(result)
- if pressed == BACK_BUTTON:
- self.go_back()
- elif pressed == NEXT_BUTTON or pressed == FINISH_BUTTON:
- errors = []
- if self.validate_input(self.__current_page, errors):
- self.process_input(self.__current_page)
- self.go_next()
- else:
- error_text = ""
- for error in errors:
- error_text += "%s\n" % error
- ButtonChoiceWindow(screen,
- "There Were Errors",
- error_text,
- buttons = ["OK"])
- elif pressed == CANCEL_BUTTON:
- active = False
- except Exception, error:
- ButtonChoiceWindow(screen,
- "An Exception Has Occurred",
- str(error) + "\n" + traceback.format_exc(),
- buttons = ["OK"])
- screen.popWindow()
- screen.finish()
-
-class SelectionListConfigScreen(ConfigScreen):
- '''
- Provides a class that can be used to give the user an initial list.
- The system then branches based on the selection the user makes.
-
- The developer will still need to override the get_elements_for_page method
- in order to map the core selection to the appropriate page.
- '''
-
- def __init__(self, title):
- ConfigScreen.__init__(self, title)
-
- def get_screen_options(self):
- """
- Returns the list of elements to be displayed on the screen.
- """
- print "Called the parent instead."
- return []
-
- def get_list_page(self, screen):
- options = self.get_screen_options()
- result = None
-
- if len(options) > 0:
- self.__has_options = True
- self.__option_list = Listbox(0)
- for option in options:
- self.__option_list.append(option, option)
- result = [self.__option_list]
- else:
- self.__has_options = False
- grid = Grid(1, 1)
- grid.setField(Label("There are no options available."), 0, 0)
- result = [grid]
- return result
-
- def get_selected_option(self):
- return self.__option_list.current()
-
- def has_selectable_options(self):
- return self.__has_options
diff --git a/menuscreen.py b/menuscreen.py
deleted file mode 100644
index 1700e8c..0000000
--- a/menuscreen.py
+++ /dev/null
@@ -1,57 +0,0 @@
-# mainmenu.py - Copyright (C) 2009 Red Hat, Inc.
-# Written by Darryl L. Pierce <dpierce(a)redhat.com>
-#
-# 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 of the License.
-#
-# 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. A copy of the GNU General Public License is
-# also available at
http://www.gnu.org/copyleft/gpl.html.
-
-from snack import *
-import traceback
-
-import utils
-import logging
-
-EXIT_MENU = 99
-
-class MenuScreen:
- def __init__(self, title):
- self.__title = title
-
- def start(self):
- finished = False
- while finished == False:
- screen = SnackScreen()
- menu = Listbox(height = 0, width = 0, returnExit = 1)
- for menu_item in self.get_menu_items():
- menu.append(menu_item[0], menu_item[1])
- menu.append("Exit Menu", EXIT_MENU)
- gridform = GridForm(screen, self.__title, 1, 4)
- gridform.add(menu, 0, 0)
- result = gridform.run();
- screen.popWindow()
- screen.finish()
-
- try:
- if result.current() == EXIT_MENU: finished = True
- else: self.handle_selection(result.current())
- except Exception, error:
- screen = SnackScreen()
- logging.info("An exception occurred: %s" % str(error))
- ButtonChoiceWindow(screen,
- "An Exception Has Occurred",
- str(error) + "\n" + traceback.format_exc(),
- buttons = ["OK"])
- screen.popWindow()
- screen.finish()
- finished = True
diff --git a/newt_syrup/__init__.py b/newt_syrup/__init__.py
new file mode 100644
index 0000000..afda660
--- /dev/null
+++ b/newt_syrup/__init__.py
@@ -0,0 +1,17 @@
+# __init__.py - Copyright (C) 2009 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierce(a)redhat.com>
+#
+# 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 of the License.
+#
+# 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. A copy of the GNU General Public License is
+# also available at
http://www.gnu.org/copyleft/gpl.html.
diff --git a/newt_syrup/configscreen.py b/newt_syrup/configscreen.py
new file mode 100644
index 0000000..4fd6525
--- /dev/null
+++ b/newt_syrup/configscreen.py
@@ -0,0 +1,182 @@
+# configscreen.py - Copyright (C) 2009 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierce(a)redhat.com>
+#
+# 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 of the License.
+#
+# 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. A copy of the GNU General Public License is
+# also available at
http://www.gnu.org/copyleft/gpl.html.
+
+from snack import *
+import traceback
+
+BACK_BUTTON = "back"
+NEXT_BUTTON = "next"
+CANCEL_BUTTON = "cancel"
+FINISH_BUTTON = "finish"
+
+class ConfigScreen:
+ '''Enables the creation of navigable, multi-paged configuration
screens.'''
+
+ def __init__(self, title):
+ self.__title = title
+ self.__current_page = 1
+ self.__finished = False
+
+ def get_title(self):
+ return self.__title
+
+ def set_finished(self):
+ self.__finished = True
+
+ def get_elements_for_page(self, screen, page):
+ return []
+
+ def page_has_next(self, page):
+ return False
+
+ def page_has_finish(self, page):
+ return False
+
+ def get_back_page(self, page):
+ if page > 1: return page - 1
+ return page
+
+ def go_back(self):
+ self.__current_page = self.get_back_page(self.__current_page)
+
+ def get_next_page(self, page):
+ return page + 1
+
+ def go_next(self):
+ self.__current_page = self.get_next_page(self.__current_page)
+
+ def validate_input(self, page, errors):
+ return True
+
+ def process_input(self, page):
+ return
+
+ def get_page_list(self):
+ return []
+
+ def get_current_page(self):
+ 0
+
+ def start(self):
+ active = True
+ while active and (self.__finished == False):
+ screen = SnackScreen()
+ elements = self.get_elements_for_page(screen, self.__current_page)
+ # TODO: need to set the form height to the number of elements on the page
+ gridform = GridForm(screen, self.get_title(), 2, 2)
+
+ # Here you would put the list of elements
+ # and programmatically set the indicator as
+ # they're rendered
+ pages = self.get_page_list()
+ if len(pages) > 0:
+ leftmenu = Grid(2, len(pages))
+ current_element = 0
+ for page in pages:
+ leftmenu.setField(Label(page), 0, current_element, anchorLeft = 1)
+ indicator = " "
+ if current_element == self.__current_page - 1:
+ indicator = "<-"
+ leftmenu.setField(Label(indicator), 1, current_element)
+ current_element += 1
+ gridform.add(leftmenu, 0, 0, anchorTop = 1, padding = (3, 0, 3, 0))
+
+ content = Grid(1, len(elements) + 1)
+ current_element = 0
+ for element in elements:
+ content.setField(element, 0, current_element)
+ current_element += 1
+ # create the navigation buttons
+ buttons = []
+ if self.__current_page > 1: buttons.append(["Back", BACK_BUTTON,
"F11"])
+ if self.page_has_next(self.__current_page): buttons.append(["Next",
NEXT_BUTTON, "F12"])
+ if self.page_has_finish(self.__current_page):
buttons.append(["Finish", FINISH_BUTTON, "F10"])
+ buttons.append(["Cancel", CANCEL_BUTTON, "ESC"])
+ buttonbar = ButtonBar(screen, buttons)
+ content.setField(buttonbar, 0, current_element, growx = 1)
+ gridform.add(content, 1, 0, anchorTop = 1)
+ current_element += 1
+ try:
+ result = gridform.runOnce()
+ pressed = buttonbar.buttonPressed(result)
+ if pressed == BACK_BUTTON:
+ self.go_back()
+ elif pressed == NEXT_BUTTON or pressed == FINISH_BUTTON:
+ errors = []
+ if self.validate_input(self.__current_page, errors):
+ self.process_input(self.__current_page)
+ self.go_next()
+ else:
+ error_text = ""
+ for error in errors:
+ error_text += "%s\n" % error
+ ButtonChoiceWindow(screen,
+ "There Were Errors",
+ error_text,
+ buttons = ["OK"])
+ elif pressed == CANCEL_BUTTON:
+ active = False
+ except Exception, error:
+ ButtonChoiceWindow(screen,
+ "An Exception Has Occurred",
+ str(error) + "\n" + traceback.format_exc(),
+ buttons = ["OK"])
+ screen.popWindow()
+ screen.finish()
+
+class SelectionListConfigScreen(ConfigScreen):
+ '''
+ Provides a class that can be used to give the user an initial list.
+ The system then branches based on the selection the user makes.
+
+ The developer will still need to override the get_elements_for_page method
+ in order to map the core selection to the appropriate page.
+ '''
+
+ def __init__(self, title):
+ ConfigScreen.__init__(self, title)
+
+ def get_screen_options(self):
+ """
+ Returns the list of elements to be displayed on the screen.
+ """
+ print "Called the parent instead."
+ return []
+
+ def get_list_page(self, screen):
+ options = self.get_screen_options()
+ result = None
+
+ if len(options) > 0:
+ self.__has_options = True
+ self.__option_list = Listbox(0)
+ for option in options:
+ self.__option_list.append(option, option)
+ result = [self.__option_list]
+ else:
+ self.__has_options = False
+ grid = Grid(1, 1)
+ grid.setField(Label("There are no options available."), 0, 0)
+ result = [grid]
+ return result
+
+ def get_selected_option(self):
+ return self.__option_list.current()
+
+ def has_selectable_options(self):
+ return self.__has_options
diff --git a/newt_syrup/menuscreen.py b/newt_syrup/menuscreen.py
new file mode 100644
index 0000000..1700e8c
--- /dev/null
+++ b/newt_syrup/menuscreen.py
@@ -0,0 +1,57 @@
+# mainmenu.py - Copyright (C) 2009 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierce(a)redhat.com>
+#
+# 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 of the License.
+#
+# 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. A copy of the GNU General Public License is
+# also available at
http://www.gnu.org/copyleft/gpl.html.
+
+from snack import *
+import traceback
+
+import utils
+import logging
+
+EXIT_MENU = 99
+
+class MenuScreen:
+ def __init__(self, title):
+ self.__title = title
+
+ def start(self):
+ finished = False
+ while finished == False:
+ screen = SnackScreen()
+ menu = Listbox(height = 0, width = 0, returnExit = 1)
+ for menu_item in self.get_menu_items():
+ menu.append(menu_item[0], menu_item[1])
+ menu.append("Exit Menu", EXIT_MENU)
+ gridform = GridForm(screen, self.__title, 1, 4)
+ gridform.add(menu, 0, 0)
+ result = gridform.run();
+ screen.popWindow()
+ screen.finish()
+
+ try:
+ if result.current() == EXIT_MENU: finished = True
+ else: self.handle_selection(result.current())
+ except Exception, error:
+ screen = SnackScreen()
+ logging.info("An exception occurred: %s" % str(error))
+ ButtonChoiceWindow(screen,
+ "An Exception Has Occurred",
+ str(error) + "\n" + traceback.format_exc(),
+ buttons = ["OK"])
+ screen.popWindow()
+ screen.finish()
+ finished = True