00001 # -*- coding: utf-8 -*- 00002 00003 # Mathmaker creates automatically maths exercises sheets 00004 # with their answers 00005 # Copyright 2006-2009 Nicolas Hainaux <nico_h@users.sourceforge.net> 00006 00007 # This file is part of Mathmaker. 00008 00009 # Mathmaker is free software; you can redistribute it and/or modify 00010 # it under the terms of the GNU General Public License as published by 00011 # the Free Software Foundation; either version 3 of the License, or 00012 # any later version. 00013 00014 # Mathmaker is distributed in the hope that it will be useful, 00015 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 # GNU General Public License for more details. 00018 00019 # You should have received a copy of the GNU General Public License 00020 # along with Mathmaker; if not, write to the Free Software 00021 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 00023 import error 00024 # ----------------------------------------------------------------------------- 00025 # ------------------------------------------- CLASS: sheet.Structure ---------- 00026 # ----------------------------------------------------------------------------- 00027 ## 00028 # @class Structure 00029 # @brief Abstract mother class of all sheets ! 00030 # The constructor only has to be reimplemented, it is useless to reimplement 00031 # other methods 00032 class Structure(object): 00033 00034 00035 00036 00037 # -------------------------------------------------- CONSTRUCTOR ---------- 00038 ## 00039 # @brief /!\ Must be redefined. Constructor. 00040 # @warning Exception NotInstanciableObject. 00041 # @param embedded_machine The machine to be used 00042 # @param **options Any options 00043 def __init__(self, embedded_machine, **options): 00044 raise error.NotInstanciableObject(self) 00045 00046 00047 00048 00049 00050 # ----------------------------- OUTPUT WRITING : the whole sheet ---------- 00051 ## 00052 # @brief Writes the whole sheet's content to the output. 00053 # The whole sheet's content is : 00054 # - document's header 00055 # - sheet's title & possibly subtitle 00056 # - texts of the exercises 00057 # - page break 00058 # - answers' sheet title 00059 # - answers of the exercises 00060 # - the close document instruction 00061 def write_output(self): 00062 self.machine.write_header() 00063 self.machine.write_document_begins() 00064 self.write_sheet_header() 00065 self.write_sheet_title() 00066 self.write_sheet_text() 00067 self.write_texts() 00068 self.machine.write_jump_to_next_page() 00069 self.write_answers_title() 00070 self.write_answers() 00071 self.machine.write_end_document() 00072 00073 00074 00075 00076 00077 # ------------------------------- OUTPUT WRITING : sheet's header --------- 00078 ## 00079 # @brief Writes to the output the header of the sheet to be generated 00080 # This header is written in a large size. A new line follow it. 00081 # It's useful to write headers for test sheets, for example. 00082 def write_sheet_header(self): 00083 if self.header != "": 00084 self.machine.write_set_size_to('large') 00085 self.machine.write(self.header) 00086 self.machine.write_new_line() 00087 00088 00089 00090 00091 # -------------------------------- OUTPUT WRITING : sheet's title --------- 00092 ## 00093 # @brief Writes to the output the title of the sheet to be generated 00094 # This title is written in a LARGE size & bolded. Two new lines follow it 00095 def write_sheet_title(self): 00096 self.machine.write_set_size_to('LARGE') 00097 self.machine.write_bold(self.title) 00098 if self.subtitle != "": 00099 self.machine.write_new_line() 00100 self.machine.write_bold(self.subtitle) 00101 self.machine.write_new_line_twice() 00102 00103 00104 00105 00106 00107 # ------------------------------- OUTPUT WRITING : answers' title --------- 00108 ## 00109 # @brief Writes to the output title of the answers' sheet to be generated 00110 # This title is written in a LARGE size & bolded. Two new lines follow it 00111 def write_answers_title(self): 00112 self.machine.write_set_size_to('LARGE') 00113 self.machine.write_bold(self.answers_title) 00114 self.machine.write_new_line_twice() 00115 00116 00117 00118 00119 00120 # ---------------------------------------- OUTPUT WRITING : texts --------- 00121 ## 00122 # @brief Writes to the output all exercises' texts 00123 def write_texts(self): 00124 self.machine.write_counter_reset() 00125 self.machine.write_set_size_to('large') 00126 for e in self.exercises_list: 00127 self.machine.write_exercise_number() 00128 e.write_text() 00129 self.machine.write_new_line() 00130 00131 00132 00133 00134 00135 # ----------------------------------- OUTPUT WRITING : sheet text --------- 00136 ## 00137 # @brief Writes to the output the sheet's text 00138 def write_sheet_text(self): 00139 if self.text != "": 00140 self.machine.write(self.text) 00141 self.machine.write_new_line_twice() 00142 00143 00144 00145 00146 00147 00148 # -------------------------------------- OUTPUT WRITING : answers --------- 00149 ## 00150 # @brief Writes to the output all exercises' answers 00151 def write_answers(self): 00152 self.machine.write_counter_reset() 00153 self.machine.write_set_size_to('large') 00154 for e in self.exercises_list: 00155 self.machine.write_exercise_number() 00156 e.write_answer() 00157 self.machine.write_new_line() 00158 00159 00160 00161 00162