Changeset 1987:1667a5143bec


Ignore:
Timestamp:
11/30/06 07:22:55 (6 years ago)
Author:
William Stein <wstein@…>
Branch:
default
Children:
1988:ddf9c7f711c3, 2008:60f08a540628
Message:

Turned on edit mode (work of Stein, Alex C., Dorian, and Tom B.)

Location:
sage/server/notebook
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sage/server/notebook/cell.py

    r1985 r1987  
    112112                        s += pr + v + '\n' 
    113113        else: 
    114             s += self.__in.strip() + '\n///\n' 
     114            s += self.__in.strip()  
    115115 
    116116        if prompts: 
     
    127127                out = self.output_text(ncols, html=False) 
    128128        else: 
    129             out = self.output_text(ncols, html=False).split('\n') 
    130             if len(out) > 0: 
    131                 if wiki_out: 
    132                   out = '///\n' + '\n'.join(out) 
    133                 else: 
    134                   out = '#out: ' + '\n'.join(out) 
    135             else: 
    136                 out = '' 
    137129            out = self.output_text(ncols, html=False) 
     130            if wiki_out and len(out) > 0: 
     131                out = '///\n' + out 
    138132 
    139133        if not max_out is None and len(out) > max_out: 
     
    149143        return s 
    150144     
    151     def wiki_text(self, ncols=0, prompts=False, max_out=None): 
     145    def edit_text(self, ncols=0, prompts=False, max_out=None): 
    152146        s = self.plain_text(ncols,prompts,max_out,wiki_out=True) 
    153         #return '{{{#!sage[%s]\n'%self.id() + s + '\n}}}' 
    154         #return '{{{[%s]\n'%self.id() + s + '\n}}}' 
    155147        return '{{{\n%s\n}}}'%s 
    156148 
     
    284276                s = s[j+7:] 
    285277            s = t 
    286             if not self.is_html() and len(s.strip()) > 0: 
    287                 s = '<pre class="shrunk">' + s.strip('\n') + '</pre>' 
    288  
    289278            # if there is an error in the output, 
    290279            # specially format it. 
    291280            s = format_exception(s, ncols) 
     281            if not self.is_html() and len(s.strip()) > 0: 
     282                s = '<pre class="shrunk">' + s.strip('\n') + '</pre>' 
     283 
    292284 
    293285        return s.strip('\n') 
     
    500492 
    501493def format_exception(s, ncols): 
    502     if not ('Traceback (most recent call last):' in s): 
     494    m = 'Traceback (most recent call last):' 
     495    s = s.lstrip() 
     496    if s[:len(m)] != m: 
    503497        return s 
    504498    if ncols > 0: 
  • sage/server/notebook/css.py

    r1986 r1987  
    10471047  margin:0px; 
    10481048  padding-left:0px;   
    1049   color:#0000cc; 
     1049  color:#0000aa; 
    10501050} 
    10511051 
     
    10541054  margin:0px; 
    10551055  padding:0px;   
    1056   color:#0000cc; 
     1056  color:#0000aa; 
    10571057} 
    10581058span.cell_output_nowrap { 
     
    10711071  margin:0px; 
    10721072  padding:0px; 
    1073   color:#0000cc; 
     1073  color:#0000aa; 
    10741074} 
    10751075span.cell_output_nowrap_hidden { 
  • sage/server/notebook/notebook.py

    r1986 r1987  
    835835        #body += '    <a class="plain_text" onClick="worksheet_text_window(\'%s\')">Text</a>'%worksheet.filename() + vbar 
    836836        body += '    <a class="doctest_text" onClick="doctest_window(\'%s\')">Text</a>'%worksheet.filename() + vbar 
    837         body += '    <a class="plain_text" href="%s__edit__.html">Edit</a>'%worksheet.filename() + vbar 
     837        body += '    <a class="plain_text" href="%s?edit">Edit</a>'%worksheet.filename() + vbar 
    838838        #body += '    <a class="plain_text" onClick="show_wiki_window(\'%s\')">Wiki-form</a>'%worksheet.filename() + vbar 
    839839        body += '    <a class="doctest_text" onClick="print_window(\'%s\')">Print</a>'%worksheet.filename() + vbar 
     
    935935        body_html = '' 
    936936        body_html += '<h1 class="edit">SAGE Notebook: Editing Worksheet "%s"</h1>\n'%worksheet.name() 
    937         body_html += '<form method="post" action="/%s/edit" enctype="multipart/form-data">\n'%worksheet.name() 
     937        body_html += "<b>Warnings:</b> You cannot undo after you save changes (yet).  All graphics will be deleted when you save -- preserving images not yet implemented.  No markup not in {{{}}}'s is preserved.<br><br>" 
     938        body_html += '<form method="post" action="%s?edit" enctype="multipart/form-data">\n'%worksheet.filename() 
    938939        body_html += '<input type="submit" value="Save Changes" name="button_save"/>\n' 
    939         body_html += '<input type="submit" value="Preview" name="button_preview"/>\n' 
     940        #body_html += '<input type="submit" value="Preview" name="button_preview"/>\n' 
    940941        body_html += '<input type="submit" value="Cancel" name="button_cancel"/>\n' 
    941942        body_html += '<textarea class="edit" id="cell_intext" rows="30" name="textfield">'+t+'</textarea>' 
  • sage/server/notebook/server.py

    r1985 r1987  
    459459    def edit_save(self, filename, newtext): 
    460460        W = notebook.get_worksheet_with_filename(filename) 
     461        W.edit_save(newtext) 
     462        return self.show_page(worksheet_id=W.id()) 
     463 
     464    def edit_preview(self): 
    461465        raise NotImplementedError 
    462  
    463     def edit_preview(self): 
    464         print "edit_preview"         
    465466     
    466     def edit_cancel(self): 
    467         print "edit_ancel"                 
    468  
     467    def edit_cancel(self, filename): 
     468        W = notebook.get_worksheet_with_filename(filename) 
     469        return self.show_page(worksheet_id=W.id()) 
    469470 
    470471 
     
    534535        self.wfile.write(notebook.upload_window()) 
    535536 
    536     def insert_wiki_cells(self): 
    537         C = self.get_postvars() 
    538         W = notebook.get_worksheet_with_id(int(C['worksheet_id'][0])) 
    539         W.insert_wiki_cells(C['text'][0]) 
    540         response = C['eval'][0] + SEP 
    541         response+= "%r"%W.cell_id_list() + SEP 
    542         response+= SEP.join([c.html(div_wrap=False) for c in W[:-1]]) 
    543         self.wfile.write(response)  
     537##     def insert_wiki_cells(self): 
     538##         C = self.get_postvars() 
     539##         W = notebook.get_worksheet_with_id(int(C['worksheet_id'][0])) 
     540##         W.insert_wiki_cells(C['text'][0]) 
     541##         response = C['eval'][0] + SEP 
     542##         response+= "%r"%W.cell_id_list() + SEP 
     543##         response+= SEP.join([c.html(div_wrap=False) for c in W[:-1]]) 
     544##         self.wfile.write(response)  
    544545 
    545546    def download_worksheet(self, filename): 
     
    590591            elif worksheet_filename == '__license__': 
    591592                self.license_window() 
    592             elif worksheet_filename[-8:] == '__edit__': 
    593                 self.edit_text(worksheet_filename[:-8],prompts=False) 
    594593            elif worksheet_filename[-7:] == '__doc__': 
    595594                self.plain_text_worksheet(worksheet_filename[:-7], prompts=True) 
     
    603602                self.html_worksheet(worksheet_filename, do_print=False) 
    604603            return 
    605          
     604 
    606605        elif path[-4:] == '.sws': 
    607606             
     
    703702        i = self.path.rfind('?') 
    704703        if i != -1: 
    705             if 'debug' in self.path[i:]: 
     704            if self.path[i+1:i+6] == 'debug': 
    706705                show_debug = True 
     706            elif self.path[i+1:i+5] == 'edit': 
     707                j = self.path.rfind('/') 
     708                worksheet_filename = self.path[j+1:i] 
     709                self.edit_text(worksheet_filename,prompts=False) 
     710                return 
    707711            self.path = self.path[:i] 
    708712 
    709713        #verbose(self.path) 
    710  
    711714        if self.path[-4:] in ['.eps', '.pdf', '.png', '.bmp', '.svg', '.tex', \ 
    712715                              '.dvi', '.log', '.css',\ 
     
    785788            M = cgi.parse_multipart(self.rfile, post_dict); 
    786789 
    787             if self.path[-5:] == '/edit' and self.path != '/edit': 
    788                 # i.e., this "/edit" after a longer name, not a worksheet named /edit 
    789                 filename = self.path[:-5].strip('/') 
     790            if self.path[-5:] == '?edit' and self.path != '?edit': 
     791                filename = self.path[1:-5] 
    790792                if M.has_key('button_save'): 
    791793                    self.edit_save(filename, M['textfield'][0]) 
     794                elif M.has_key('button_cancel'): 
     795                    self.edit_cancel(filename) 
    792796                return 
    793797             
  • sage/server/notebook/worksheet.py

    r1986 r1987  
    162162        suitable for hand editing. 
    163163        """ 
    164         s = '#'*80 + '\n' 
    165         s += '# Wiki form for worksheet: %s'%self.name() + '\n' 
    166         s += '#'*80+'\n\n' 
     164        #s = '#'*80 + '\n' 
     165        #s += '# Worksheet: %s'%self.name() + '\n' 
     166        #s += '#'*80+'\n\n' 
     167        s = ' == %s =='%self.name() + '\n\n' 
    167168        for C in self.__cells: 
    168             t = C.wiki_text(prompts=prompts).strip() 
     169            t = C.edit_text(prompts=prompts).strip() 
    169170            if t != '': 
    170171                s += '\n\n' + t 
    171172        return s 
    172173 
    173     def insert_wiki_cells(self,text): 
     174    def edit_save(self,text): 
    174175        text.replace('\r\n','\n') 
    175         lines = text.split('\n') 
    176         input = "" 
    177         output = "" 
    178         in_cell = False 
    179         in_output = False 
    180         old_first = self.__cells[0].id() 
    181         for line in lines: 
    182             if not in_cell:  
    183                 if line[:3] == '{{{': 
    184                     in_cell = True 
    185             elif line != '}}}': 
    186                 if not in_output: 
    187                     if line == '///': 
    188                         in_output = True 
    189                     else: 
    190                         input += line+'\n' 
    191                 else: 
    192                     output += line+'\n' 
    193             else: 
    194                 C = self.new_cell_before(old_first) 
    195                 C.set_input_text(input) 
    196                 C.set_output_text(output,output) 
    197                 C.set_cell_output_type() 
    198                 input = "" 
    199                 output = "" 
    200                 in_cell = False 
    201                 in_output = False 
     176        # This is where we would save the last version in a history. 
     177        cells = [] 
     178        while True: 
     179            try: 
     180                input, output, graphics, i = extract_first_text_cell(text) 
     181            except EOFError: 
     182                break 
     183            text = text[i:] 
     184            C = self._new_cell() 
     185            C.set_input_text(input) 
     186            C.set_output_text(output, '') 
     187            cells.append(C) 
     188        self.__cells = cells 
     189             
     190##         lines = text.split('\n') 
     191##         input = "" 
     192##         output = "" 
     193##         in_cell = False 
     194##         in_output = False 
     195##         old_first = self.__cells[0].id() 
     196##         for line in lines: 
     197##             if not in_cell:  
     198##                 if line[:3] == '{{{': 
     199##                     in_cell = True 
     200##             elif line != '}}}': 
     201##                 if not in_output: 
     202##                     if line == '///': 
     203##                         in_output = True 
     204##                     else: 
     205##                         input += line+'\n' 
     206##                 else: 
     207##                     output += line+'\n' 
     208##             else: 
     209##                 C = self.new_cell_before(old_first) 
     210##                 C.set_input_text(input) 
     211##                 C.set_output_text(output,output) 
     212##                 C.set_cell_output_type() 
     213##                 input = "" 
     214##                 output = "" 
     215##                 in_cell = False 
     216##                 in_output = False 
    202217 
    203218    def input_text(self): 
     
    369384 
    370385    def _new_cell(self, id=None): 
    371         D = self.__notebook.defaults() 
    372386        if id is None: 
    373387            id = self.__next_id 
     
    12291243    return s 
    12301244             
     1245 
     1246 
     1247def extract_first_text_cell(text): 
     1248    """ 
     1249    INPUT: 
     1250        a block of wiki-like marked up text 
     1251    OUTPUT: 
     1252        input -- string, the input text 
     1253        output -- string, the output text 
     1254        graphics -- string, text that describes any embedded graphics 
     1255        end -- integer, first position after }}} in text. 
     1256    """ 
     1257    # Find the input block 
     1258    i = text.find('{{{') 
     1259    if i == -1: 
     1260        raise EOFError 
     1261    j = text.find('}}}') 
     1262    if j <= i: 
     1263        j = len(text) 
     1264    k = text.find('///') 
     1265    if k == -1 or k > j: 
     1266        input = text[i+3:j] 
     1267        output = '' 
     1268        graphics = '' 
     1269    else: 
     1270        input = text[i+3:k].strip() 
     1271        # Find the graphics block, if there is one. 
     1272        l = text[k+3:].find('///') 
     1273        if l != -1 and l+k+3 < j: 
     1274            graphics = text[l+k+3+3:j] 
     1275        else: 
     1276            graphics = '' 
     1277            l = j 
     1278        output = text[k+3:l].strip() 
     1279    return input, output, graphics, j+3 
     1280     
Note: See TracChangeset for help on using the changeset viewer.