From 6295bf53ceebe5fcc4e781b7a83bdd9e427b0451 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Tue, 14 Oct 2003 16:23:32 +0000 Subject: [PATCH] Added line number display (also shows details of the current selection, if any). git-svn-id: https://rox.svn.sourceforge.net/svnroot/rox/trunk/Edit@3165 66de3db3-b00d-0410-b41b-f4738ad19bea --- AppRun | 2 +- EditWindow.py | 30 ++++++++++++++++++++++++++++-- Help/Changes | 1 + 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/AppRun b/AppRun index be3058e..fea5fee 100755 --- a/AppRun +++ b/AppRun @@ -1,6 +1,6 @@ #!/usr/bin/env python -import findrox; findrox.version(1, 9, 8) +import findrox; findrox.version(1, 9, 10) # XXX 11 import sys, os import rox diff --git a/EditWindow.py b/EditWindow.py index a2ec7b5..804a25e 100644 --- a/EditWindow.py +++ b/EditWindow.py @@ -7,6 +7,9 @@ from buffer import Buffer from rox.saving import Saveable import os import diff +import codecs + +to_utf8 = codecs.getencoder('utf-8') FALSE = g.FALSE TRUE = g.TRUE @@ -155,6 +158,8 @@ class EditWindow(rox.Window, XDSLoader, Saveable): vbox.pack_start(tools, FALSE, TRUE, 0) tools.show() + self.status_label = g.Label('') + tools.append_widget(self.status_label, None, None) tools.insert_stock(g.STOCK_HELP, _('Help'), None, self.help, None, 0) diff = tools.insert_stock('rox-diff', _('Show changes from saved copy.\n' 'Or, drop a backup file onto this button to see changes from that.'), @@ -167,6 +172,8 @@ class EditWindow(rox.Window, XDSLoader, Saveable): tools.insert_stock(g.STOCK_SAVE, _('Save'), None, self.save, None, 0) tools.insert_stock(g.STOCK_GO_UP, _('Up'), None, self.up, None, 0) tools.insert_stock(g.STOCK_CLOSE, _('Close'), None, self.close, None, 0) + # Set minimum size to ignore the label + tools.set_size_request(tools.size_request()[0], -1) swin = g.ScrolledWindow() swin.set_policy(g.POLICY_NEVER, g.POLICY_AUTOMATIC) @@ -201,6 +208,27 @@ class EditWindow(rox.Window, XDSLoader, Saveable): self.connect('delete-event', self.delete_event) self.text.grab_focus() self.text.connect('key-press-event', self.key_press) + + def update_current_line(*unused): + cursor = self.buffer.get_iter_at_mark(self.insert_mark) + bound = self.buffer.get_iter_at_mark(self.selection_bound_mark) + if cursor.compare(bound) == 0: + n_lines = self.buffer.get_line_count() + self.status_label.set_text(_('Line %s of %d') % (cursor.get_line() + 1, n_lines)) + else: + n_lines = abs(cursor.get_line() - bound.get_line()) + 1 + if n_lines == 1: + n_chars = abs(cursor.get_line_offset() - bound.get_line_offset()) + if n_chars == 1: + bytes = to_utf8(self.buffer.get_text(cursor, bound, False))[0] + self.status_label.set_text(_('One character selected (%s)') % + ' '.join(map(lambda x: '0x%2x' % ord(x), bytes))) + else: + self.status_label.set_text('%d characters selected' % n_chars) + else: + self.status_label.set_text('%d lines selected' % n_lines) + self.buffer.connect('mark-set', update_current_line) + self.buffer.connect('changed', update_current_line) if filename: import os.path @@ -308,8 +336,6 @@ class EditWindow(rox.Window, XDSLoader, Saveable): def get_encoding(self, message): "Returns (encoding, errors), or raises Abort to cancel." - import codecs - box = g.MessageDialog(self, 0, g.MESSAGE_QUESTION, g.BUTTONS_CANCEL, message) box.set_has_separator(FALSE) diff --git a/Help/Changes b/Help/Changes index 878862a..2a09fdb 100644 --- a/Help/Changes +++ b/Help/Changes @@ -7,6 +7,7 @@ Dnd loading: Loads to cursor, not indicated point. 14-Oct-2003 ~~~~~~~~~~~ Added toolbar icon for Show Changes. +Added line number display (also shows details of the current selection, if any). 13-Oct-2003 ~~~~~~~~~~~ -- 2.11.4.GIT