Changeset 650

Show
Ignore:
Timestamp:
07/23/05 10:17:25 (3 years ago)
Author:
tzanko
Message:

Removed some Get and Set methods and converted them into properties

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nbshell/trunk/IPythonLog.py

    r649 r650  
    1515 
    1616from lxml import etree 
    17 class IPythonLog
     17class IPythonLog(object)
    1818    def __init__(self, doc, notebook, logid, *args, **kwds): 
    1919        self.doc = doc 
     
    121121            return self.__run(notebook.Cell(self.log[-1])) 
    122122         
    123         cells = [Cell(x) for x in self.log.xpath('\\cell[@number>=%d'%(number,))] 
    124         cells.sort(key = lambda x:x.number) #That may not be necessary, since the cells are already sorted 
    125          
     123        cells = sorted((Cell(x) for x in self.log.xpath('\\cell[@number>=%d'%(number,))), key = lambda x:x.number) 
     124                 
    126125        for cell in cells: 
    127126            if not self.__run(cell): 
  • nbshell/trunk/Main.py

    r649 r650  
    3636                factory = dict["GetPluginFactory"]() 
    3737                #print factory.GetString() #dbg 
    38                 self.plugin_dict[factory.GetString()]=factory 
     38                self.plugin_dict[factory.string]=factory 
    3939 
    4040     
  • nbshell/trunk/PlainTextPlugin.py

    r649 r650  
    88    return PlainTextPluginFactory() 
    99 
    10 class PlainTextPluginFactory
     10class PlainTextPluginFactory(object)
    1111    """ This class is responsible for creating the document and view parts of  
    1212    a plugin. Also it has some functions giving information about the plugin. 
     
    1616    returned every time the document class wants to get a new one.""" 
    1717     
    18     def GetString(self): 
    19         """ Returns the type string of the plugin. This is used when a notebook 
    20         file is loaded. See notebookformat.txt for more info""" 
    21         return "plaintext" 
    22      
    23     def GetType(self): 
    24         """ Returns the way data should be passed to the plugin. Currently 
    25         supported types are "raw" and "encoded". See notebookformat.txt for  
    26         more info""" 
    27         return "encoded" #Probably only the python code plugin should be raw 
     18    string = "plaintext" 
     19    #def GetString(self): 
     20    #    """ Returns the type string of the plugin. This is used when a notebook 
     21    #    file is loaded. See notebookformat.txt for more info""" 
     22    #    return "plaintext" 
     23     
     24    type = "encoded" 
     25    #def GetType(self): 
     26    #    """ Returns the way data should be passed to the plugin. Currently 
     27    #    supported types are "raw" and "encoded". See notebookformat.txt for  
     28    #    more info""" 
     29    #    return "encoded" #Probably only the python code plugin should be raw 
    2830         
    2931    def CreateDocumentPlugin(self,document, element): 
     
    5254#end GenericPluginFactory 
    5355 
    54 class PlainTextDocumentPlugin
     56class PlainTextDocumentPlugin(object)
    5557    def __init__(self, document, element): 
    5658        """Initialization. If element is <sheet> then the text is 
     
    7779 
    7880    def SetText(self, text): 
     81        """Sets the text in the document""" 
    7982        if self.start: 
    8083            self.element.text = text 
     
    8891        if self.view is not None: 
    8992            self.view.Update() 
    90          
     93 
     94    text = property(GetText, SetText, Clear, doc = """The text contained in this instance""") 
    9195     
    9296    def LoadData(self, data=None): 
     
    136140        [encodefunc(self.data.GetLine(x)) for x in range(0, linecnt-1)] 
    137141     
    138     def SetView(self, view): 
    139         """Set the view for the plugin""" 
    140         self.view=view 
    141      
    142     def GetViewPlugin(self, view): 
    143         return self.view 
     142    #def SetView(self, view): 
     143    #    """Set the view for the plugin""" 
     144    #    self.view=view 
     145     
     146    #def GetViewPlugin(self, view): 
     147    #    return self.view 
    144148 
    145149    def GetFactory(self): 
    146150        return PlainTextPluginFactory() 
    147151 
    148 class PlainTextNotebookViewPlugin
     152class PlainTextNotebookViewPlugin(object)
    149153    def __init__(self, docplugin, view): 
    150154        """Initialization""" 
    151155        self.view = view 
    152156        self.doc = docplugin 
    153         self.doc.SetView(self) 
     157        self.doc.view = self 
    154158        self.window = None 
    155159        self.document = docplugin.document 
     
    177181            else: 
    178182                prevcell = self.document.GetCell(self.doc.index-1) 
    179                 viewplugin = prevcell.GetViewPlugin(self.view) 
     183                viewplugin = prevcell.view 
    180184                #print self.doc.index #dbg 
    181185                #print viewplugin #dbg 
     
    200204        if self.window is None: #then this is the first time Update is called 
    201205            self.createWindow() 
    202         self.window.SetText(self.doc.GetText()
     206        self.window.SetText(self.doc.text
    203207 
    204208    def UpdateDoc(self): 
    205209        """Update data in the document""" 
    206         self.doc.SetText(self.window.GetText()
     210        self.doc.text = self.window.GetText(
    207211         
    208212    def Close(self, update = True): 
  • nbshell/trunk/PythonPlugin.py

    r649 r650  
    3333    return PythonPluginFactory() 
    3434 
    35 class PythonPluginFactory
     35class PythonPluginFactory(object)
    3636    """ This class is responsible for creating the document and view parts of  
    3737    a plugin. Also it has some functions giving information about the plugin. 
     
    4141    returned every time the document class wants to get a new one.""" 
    4242     
    43     def GetString(self): 
    44         """ Returns the type string of the plugin. This is used when a notebook 
    45         file is loaded. See notebookformat.txt for more info""" 
    46         return "python" 
     43    string = "python" 
     44    #def GetString(self): 
     45    #    """ Returns the type string of the plugin. This is used when a notebook 
     46    #    file is loaded. See notebookformat.txt for more info""" 
     47    #    return "python" 
    4748     
    48     def GetType(self): 
    49         """ Returns the way data should be passed to the plugin. Currently 
    50         supported types are "raw" and "encoded". See notebookformat.txt for  
    51         more info""" 
    52         return "raw" #Probably only the python code plugin should be raw 
     49    type = "raw" 
     50    #def GetType(self): 
     51    #    """ Returns the way data should be passed to the plugin. Currently 
     52    #    supported types are "raw" and "encoded". See notebookformat.txt for  
     53    #    more info""" 
     54    #    return "raw" #Probably only the python code plugin should be raw 
    5355         
    5456    def CreateDocumentPlugin(self,document, ipython_block): 
     
    7880 
    7981 
    80 class PythonDocumentPlugin
     82class PythonDocumentPlugin(object)
    8183    def __init__(self, document, ipython_block): 
    8284        """Initialization. ipython-block is a Elemtent object holding a 
     
    153155        #[encodefunc(self.data.GetLine(x)) for x in range(0, linecnt-1)] 
    154156     
    155     def SetView(self, view): 
    156         """Set the view for the plugin""" 
    157         self.view=view 
     157    #def SetView(self, view): 
     158    #"    """Set the view for the plugin""" 
     159    #    self.view=view 
    158160     
    159     def GetViewPlugin(self, view): 
    160         return self.view 
     161    #def GetViewPlugin(self, view): 
     162    #    return self.view 
    161163 
    162164    def GetFactory(self): 
     
    169171# the code should be easier. Also the methods which should not be used outside the class start 
    170172# with a lowercaps letter. 
    171 class PythonNotebookViewPlugin
     173class PythonNotebookViewPlugin(object)
    172174    def __init__(self, docplugin, view): 
    173175        """Initialization""" 
    174176        self.view = view 
    175177        self.doc = docplugin 
    176         self.doc.SetView(self) 
     178        self.doc.view = self 
    177179        self.window = None 
    178180        self.document = docplugin.document 
     
    205207            #print "adding cell" #dbg 
    206208            prevcell = self.document.GetCell(self.doc.index-1) 
    207             viewplugin = prevcell.GetViewPlugin(self.view) 
     209            viewplugin = prevcell.view 
    208210            #print self.doc.index #dbg 
    209211            #print viewplugin #dbg 
     
    401403        self.view.DeleteCell(index, update) 
    402404 
    403 class ShellFacade
     405class ShellFacade(object)
    404406    """Simplified interface to all shell-related functionality. 
    405407 
  • nbshell/trunk/Sheet.py

    r649 r650  
    22from lxml import etree 
    33 
    4 class Sheet
     4class Sheet(object)
    55    def __init__(self, doc, notebook): 
    66        self.doc = doc 
  • nbshell/trunk/ipnDocument.py

    r649 r650  
    2424     
    2525     
    26 class ipnDocument
     26class ipnDocument(object)
    2727    def __init__(self, app, notebookview): 
    2828         
     
    8080        self.fileinfo["init"] = False 
    8181        for cell in self.celllist: 
    82             cell.GetViewPlugin(self.view).Close(update=False) 
     82            cell.view.Close(update=False) 
    8383            self.delCell(cell.index) 
    8484         
     
    120120                args = line[7:].lstrip().split() 
    121121                cell = self.InsertCell(args[0], update=False) 
    122                 t = self.app.plugin_dict[args[0]].GetType() 
     122                t = self.app.plugin_dict[args[0]].type 
    123123                if t == "raw": #pass raw data to the cell 
    124124                    cnt = cell.LoadRaw(f, args) 
     
    181181        for cell in self.celllist: 
    182182            factory = cell.GetFactory() 
    183             celltype = factory.GetType() 
     183            celltype = factory.type 
    184184            args = " ".join(cell.GetArgs()) #TODO: check if the argumens don't use bad symbols as EOL for example 
    185185            f.write("#@cell "+args + "\n")  
  • nbshell/trunk/ipnPluginTemplate.py

    r649 r650  
    99    return GenericPluginFactory() 
    1010 
    11 class GenericPluginFactory
     11class GenericPluginFactory(object)
    1212    """ This class is responsible for creating the document and view parts of  
    1313    a plugin. Also it has some functions giving information about the plugin. 
     
    1717    returned every time the document class wants to get a new one.""" 
    1818     
    19     def GetString(self): 
    20         """ Returns the type string of the plugin. This is used when a notebook 
    21         file is loaded. See notebookformat.txt for more info""" 
    22         return "generic" 
     19    string = "generic" 
     20    type = "encoded" 
     21    #def GetString(self): 
     22    #    """ Returns the type string of the plugin. This is used when a notebook 
     23    #    file is loaded. See notebookformat.txt for more info""" 
     24    #    return "generic" 
    2325     
    2426    #TODO: remove this 
     
    5557 
    5658#TODO: This class makes no sense with the xml file format. Remove it. 
    57 class GenericDocumentPlugin
     59class GenericDocumentPlugin(object)
    5860    """ objects of this class are responsible for storing data, serializing and 
    5961    loding data, and updating the view plugins""" 
     
    117119        pass 
    118120     
    119     def SetView(self, view): 
    120         """Set the view for the plugin""" 
    121         self.view=view 
     121    #def SetView(self, view): 
     122    #    """Set the view for the plugin""" 
     123    #    self.view=view 
    122124 
    123125    def GetFactory(self): 
     
    125127        return GenericPluginFactory() 
    126128 
    127 class GenericNotebookViewPlugin
     129class GenericNotebookViewPlugin(object)
    128130    """A generic view plugin. Used for handling data display.""" 
    129131    def __init__(self, docplugin, view):