~tofarley/pyroom/py10

« back to all changes in this revision

Viewing changes to pyroom/PyRoom/basic_edit.py

  • Committer: Tim Farley
  • Date: 2009-12-03 02:16:39 UTC
  • Revision ID: tofarley@gmail.com-20091203021639-zsclx02wwvlmlsje
Added partial wordcounts ctrl+1 through ctrl+5 (similar to those found in Q10). Modified the status line to read using colons instead of commas for separation. I think it reads more cleanly this way. The original code is still there, and will at some point be user selectable. Added partial wordcount keymodifiers to help buffer

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
_('Control-W: Close buffer and exit if it was the last buffer'),
50
50
_('Control-Y: Redo last typing'),
51
51
_('Control-Z: Undo last typing'),
52
 
_('Control-1: Partial word count.'),
53
52
_('Control-Page Up: Switch to previous buffer'),
54
 
_('Control-Page Down: Switch to next buffer'), ])
 
53
_('Control-Page Down: Switch to next buffer'),
 
54
_('Control-1 through Control-5: Partial word counts.'), ])
55
55
 
56
56
HELP = \
57
57
    _("""PyRoom - distraction free writing
117
117
        'w': edit_instance.close_dialog,
118
118
        'y': edit_instance.redo,
119
119
        'z': edit_instance.undo,
120
 
        '1': edit_instance.partial,
 
120
        '1': edit_instance.one,
 
121
        '2': edit_instance.two,
 
122
        '3': edit_instance.three,
 
123
        '4': edit_instance.four,
 
124
        '5': edit_instance.five,
121
125
    }
122
126
    ag = gtk.AccelGroup()
123
127
    for key, value in keybindings.items():
196
200
        self.connect('insert-text', self.on_insert_text)
197
201
        self.connect('delete-range', self.on_delete_range)
198
202
        self.connect('begin_user_action', self.on_begin_user_action)
 
203
        self.partials = [0,0,0,0,0]
199
204
 
200
205
    @property
201
206
    def can_undo(self):
372
377
    def __init__(self):
373
378
        self.current = 0
374
379
        self.buffers = []
 
380
        
375
381
        self.config = config
376
382
        gui = GUI()
377
383
        state['gui'] = gui
450
456
            status = _(' (modified)')
451
457
        else:
452
458
            status = ''
453
 
        self.status.set_text(_('Buffer %(buffer_id)d: %(buffer_name)s\
 
459
            
 
460
        if True:
 
461
            self.status.set_text(_('%(buffer_id)s%(buffer_name)s%(status)s%(char_count)s%(word_count)s%(partial_one)s%(partial_two)s%(partial_three)s%(partial_four)s%(partial_five)s%(lines)s') % {
 
462
                'buffer_id': 'Buffer: ' + str(self.current + 1) + ' ',
 
463
                'buffer_name': buf.filename if int(config.get('visual', 'showpath')) else os.path.split(buf.filename)[1],
 
464
                'status': status  + '   ',
 
465
                'char_count': 'Characters: ' + str(buf.get_char_count()) + '   ',
 
466
                'word_count': 'Words: ' + str(self.word_count(buf)) + '   ',
 
467
                'partial_one': 'Partial 1: ' + str(self.get_partial(buf, 0)) + '   ' if self.buffers[self.current].partials[0] > 0 else "",
 
468
                'partial_two': 'Partial 2: ' + str(self.get_partial(buf, 1)) + '   ' if self.buffers[self.current].partials[1] > 0 else "",
 
469
                'partial_three': 'Partial 3: ' + str(self.get_partial(buf, 2)) + '   ' if self.buffers[self.current].partials[2] > 0 else "",
 
470
                'partial_four': 'Partial 4: ' + str(self.get_partial(buf, 3)) + '   ' if self.buffers[self.current].partials[3] > 0 else "",
 
471
                'partial_five': 'Partial 5: ' + str(self.get_partial(buf, 4)) + '   ' if self.buffers[self.current].partials[4] > 0 else "",
 
472
                'lines': 'Lines: ' + str(buf.get_line_count()),
 
473
            }, 5000)
 
474
        else:    
 
475
            self.status.set_text(_('Buffer %(buffer_id)d: %(buffer_name)s\
454
476
%(status)s, %(char_count)d character(s), %(word_count)d word(s)\
455
 
, %(partial_words)s %(lines)d line(s)') % {
456
 
            'buffer_id': self.current + 1,
457
 
            'buffer_name': buf.filename if int(config.get('visual', 'showpath')) else os.path.split(buf.filename)[1],
458
 
            'status': status,
459
 
            'char_count': buf.get_char_count(),
460
 
            'word_count': self.word_count(buf),
461
 
            'partial_words': str(self.get_partial(buf)) + " partial, " if state['partial_wordcount'] > 0 else "",
462
 
            'lines': buf.get_line_count(),
 
477
, %(partial_one)s%(partial_two)s%(partial_three)s%(partial_four)s\
 
478
%(partial_five)s %(lines)d line(s)') % {
 
479
                'buffer_id': self.current + 1,
 
480
                'buffer_name': buf.filename if int(config.get('visual', 'showpath')) else os.path.split(buf.filename)[1],
 
481
                'status': status,
 
482
                'char_count': buf.get_char_count(),
 
483
                'word_count': self.word_count(buf),
 
484
                'partial_one': str(self.get_partial(buf, 0)) + " partial 1, " if self.buffers[self.current].partials[0] > 0 else "",
 
485
                'partial_two': str(self.get_partial(buf, 1)) + " partial 2, " if self.buffers[self.current].partials[1] > 0 else "",
 
486
                'partial_three': str(self.get_partial(buf, 2)) + " partial 3, " if self.buffers[self.current].partials[2] > 0 else "",
 
487
                'partial_four': str(self.get_partial(buf, 3)) + " partial 4, " if self.buffers[self.current].partials[3] > 0 else "",
 
488
                'partial_five': str(self.get_partial(buf, 4)) + " partial 5, " if self.buffers[self.current].partials[4] > 0 else "",
 
489
                'lines': buf.get_line_count(),
463
490
            }, 5000)
464
491
 
465
492
    def undo(self):
480
507
        else:
481
508
            self.status.set_text(_('Nothing more to redo!'))
482
509
 
483
 
    def partial(self):
 
510
    def one(self):
 
511
        self.partial(0)
 
512
        
 
513
    def two(self):
 
514
        self.partial(1)
 
515
        
 
516
    def three(self):
 
517
        self.partial(2)
 
518
        
 
519
    def four(self):
 
520
        self.partial(3)
 
521
        
 
522
    def five(self):
 
523
        self.partial(4)
 
524
        
 
525
    def partial(self, count):
484
526
        """set or unset partial wordcount"""
485
 
        if state['partial_wordcount'] == 0:
486
 
            state['partial_wordcount'] = self.word_count(self.buffers[self.current])
 
527
        if self.buffers[self.current].partials[count] == 0:
 
528
            self.buffers[self.current].partials[count] = self.word_count(self.buffers[self.current])
487
529
        else:
488
 
            state['partial_wordcount'] = 0
 
530
            self.buffers[self.current].partials[count] = 0
489
531
        
490
 
    def get_partial(self, buf):
491
 
        return self.word_count(buf) - state['partial_wordcount']
 
532
    def get_partial(self, buf, count):
 
533
        return self.word_count(self.buffers[self.current]) - self.buffers[self.current].partials[count]
492
534
        
493
535
    def ask_restore(self):
494
536
        """ask if backups should be restored
683
725
        buf = UndoableBuffer()
684
726
        buf.filename = FILE_UNNAMED
685
727
        self.buffers.insert(self.current + 1, buf)
 
728
        
 
729
        
 
730
        
686
731
        buf.place_cursor(buf.get_end_iter())
687
732
        self.next_buffer()
688
733
        return buf