Changeset 850
- Timestamp:
- 09/16/05 18:01:14 (3 years ago)
- Files:
-
- nbshell/trunk/ChangeLog (modified) (1 diff)
- nbshell/trunk/nbshell/FigurePlugin.py (modified) (1 diff)
- nbshell/trunk/nbshell/Main.py (modified) (1 diff)
- nbshell/trunk/nbshell/PlainTextPlugin.py (modified) (1 diff)
- nbshell/trunk/nbshell/PythonPlugin.py (modified) (2 diffs)
- nbshell/trunk/nbshell/Sheet.py (modified) (3 diffs)
- nbshell/trunk/nbshell/ipnNotebookWidget.py (modified) (1 diff)
- nbshell/trunk/nbshell/textplugin.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
nbshell/trunk/ChangeLog
r838 r850 1 2005-09-17 Tzanko Matev <tsanko@gmail.com> 2 3 * Sheet.py (Sheet._update_celllist): 4 * PythonPlugin.py (PythonPluginFactory.get_matchers): 5 * FigurePlugin.py (FigurePluginFactory.get_matchers): 6 * textplugin.py (TextPluginFactory.get_matchers): 7 * PlainTextPlugin.py (PlainTextPluginFactory.get_matchers): 8 Rewrote the algorithm for converting a ElementTree structure to a 9 list of nbshell blocks. Now each plugin must give a method which 10 decides if a given element must be handled by that plugin. As a 11 result this part of the sheet is now independant of the specific 12 plugins (except for the raw xml plugin). Also adding complex tests 13 for parts of the xml tree is much easier than before. The text 14 plugin now matches only <para> elements with no subelements which 15 fixes ticket #34 16 17 * ipnNotebookWidget.py (CellCtrlBase.OnKeyDown): Fixed an 18 indentation bug where the given method was considered a function 19 in another method 20 21 1 22 2005-09-13 Tzanko Matev <tsanko@gmail.com> 2 23 nbshell/trunk/nbshell/FigurePlugin.py
r828 r850 49 49 return None #Well here I should throw an exception, however I am 50 50 #not supposed to get to this line for a long long time 51 51 52 def get_matchers(self): 53 """A matcher for the <ipython-figure> element""" 54 return lambda element:element.tag == 'ipython-figure' 55 52 56 53 57 #end GenericPluginFactory nbshell/trunk/nbshell/Main.py
r828 r850 53 53 54 54 plugin_dir = "." #this should be configured somewhere 55 plugin_dict = { 0:0}55 plugin_dict = {} 56 56 57 57 def __init__(self, *args, **kwds): nbshell/trunk/nbshell/PlainTextPlugin.py
r829 r850 70 70 return None #Well here I should throw an exception, however I am 71 71 #not supposed to get to this line for a long long time 72 73 def get_matchers(self): 74 """No matchers""" 75 return None 72 76 #end GenericPluginFactory 73 77 nbshell/trunk/nbshell/PythonPlugin.py
r838 r850 56 56 # more info""" 57 57 # return "raw" #Probably only the python code plugin should be raw 58 58 59 59 def CreateDocumentPlugin(self,document, element): 60 60 """Creates the document part of the plugin. The returned object is … … 80 80 return None #Well here I should throw an exception, however I am 81 81 #not supposed to get to this line for a long long time 82 83 def get_matchers(self): 84 """Matches the <ipython-block> element""" 85 return lambda element:element.tag == 'ipython-block' 82 86 #end GenericPluginFactory 83 87 nbshell/trunk/nbshell/Sheet.py
r835 r850 22 22 from nbshell import PythonPlugin 23 23 from nbshell.utils import * 24 from nbshell import SimpleXMLWriter 24 25 25 26 … … 155 156 156 157 self.__clear_celllist(update = False) 157 self._ _update_celllist(update = False)158 self._update_celllist(update = False) 158 159 if dicts: 159 160 self.__update_dicts() … … 226 227 227 228 228 def __update_celllist(self, update = False): 229 def _update_celllist(self, update = False): 230 231 #Get the matchers from the plugin factories 232 matchers = {} 233 for plugin_string in self.factory.keys(): 234 result = self.factory[plugin_string].get_matchers() 235 #get_matchers must return either one matcher or a list of matchers 236 if callable(result): #one matcher 237 matchers[result] = plugin_string 238 elif result: #a list of matchers 239 for a in result: #there should be a more pythonic way to do this 240 matchers[a] = plugin_string 241 #else get_match can return None 242 243 buffer = StringIO.StringIO() 244 read_pos = [0] #possition in the buffer from which to start reading. It must be mutable 245 writer = SimpleXMLWriter.XMLWriter(buffer, encoding='utf-8') 246 247 def process_element(element): 248 """Processes one unhandled element""" 249 #write the start tag and any text after it 250 if element.tag != 'sheet': 251 writer.start(element.tag, element.attrib) 252 writer.data(element.text or '') 253 #Get a list of the children 254 children = iter(element[:]) 255 try: 256 child = children.next() 257 except StopIteration: 258 #The sheet is empty. Create one empty xml block 259 self.InsertCell('plaintext', update = False, text = '') 260 else: 261 while True: 262 result = False 263 #Test the child against the matchers until one returns non False 264 for matcher in matchers.keys(): 265 result = matcher(child) 266 if result: 267 break 268 if not result: 269 #None of the mathchers returned true, so process the 270 #element the standard way 271 process_element(child) 272 #append the tail to the buffer 273 writer.data(child.tail or '') 274 #get the next child 275 try: 276 child = children.next() 277 except: 278 break 279 else: #The element returned a match. 280 #Create a new xml block and empty the buffer if there is something in it 281 if buffer.tell() != read_pos[0]: 282 buffer.seek(read_pos[0]) 283 self.InsertCell('plaintext',update = False, text = buffer.read()) 284 read_pos[0] = buffer.tell() 285 286 plugin_string = matchers[matcher] 287 if callable(result): 288 #If the result is callable, this means that we want to 289 #match a list of consequtive elements to give to the 290 #plugin. To do that call the result on the next 291 #element and get the result and with it do the same, 292 #until there are no more elements or one of the 293 #matchers returned false. 294 elem_list = [] 295 while result: 296 elem_list.append(child) 297 try: 298 child = children.next() 299 except StopIteration: 300 break 301 result = result(child) 302 303 #Now create the corresponding block 304 self.InsertCell(plugin_string, update = False, 305 element_list = elem_list) 306 else: 307 #This is a simple match, create the block, giving the 308 #element as a parameter 309 self.InsertCell(plugin_string, update=False, element = child) 310 #get the next element 311 try: 312 child = children.next() 313 except StopIteration: 314 break 315 #The element is almost processed, write the end tag and exit 316 if element.tag != 'sheet': 317 writer.end(tag = element.tag) 318 #process_element end 319 320 #Run the function with the sheet element, and empty the buffer at the end 321 process_element(self.element) 322 if buffer.tell() != read_pos[0]: 323 buffer.seek(read_pos[0]) 324 self.InsertCell('plaintext', update = False, text = buffer.read()) 325 buffer.close() 326 if update: 327 self.Update(celllist = False) 328 329 330 331 def _old_update_celllist(self, update = False): 229 332 """Updates the celllist from self.element and updates the view if 230 333 update == True """ nbshell/trunk/nbshell/ipnNotebookWidget.py
r734 r850 86 86 self.OnKeyDown(evt) 87 87 88 def OnKeyDown(self,evt):89 evt.Skip()88 def OnKeyDown(self,evt): 89 evt.Skip() 90 90 91 91 class ipnNotebook (wx.ScrolledWindow): nbshell/trunk/nbshell/textplugin.py
r829 r850 72 72 return None #Well here I should throw an exception, however I am 73 73 #not supposed to get to this line for a long long time 74 75 def get_matchers(self): 76 """matches a sequence of para elements without inner subelements""" 77 def matcher(element): 78 if element.tag == 'para' and len(element) == 0: 79 return matcher 80 else: 81 return False 82 83 return matcher 84 74 85 #end GenericPluginFactory 75 86
