File: wb_subversion_annotate.py

package info (click to toggle)
svn-workbench 1.5.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,400 kB
  • ctags: 1,585
  • sloc: python: 12,163; sh: 74; makefile: 46; ansic: 9
file content (122 lines) | stat: -rw-r--r-- 4,368 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
'''
 ====================================================================
 Copyright (c) 2003-2006 Barry A Scott.  All rights reserved.

 This software is licensed as described in the file LICENSE.txt,
 which you should have received as part of this distribution.

 ====================================================================

    wb_subversion_annotate.py

'''
import wx
import wb_images
import wb_read_file
import time

class AnnotateFrame(wx.Frame):
    def __init__( self, app, project_info, filename, annotation ):
        wx.Frame.__init__( self, None, -1, "Annotation of %s" % filename )

        self.panel = AnnotatePanel( self, app, project_info, filename, annotation )

        # Set the application icon
        self.SetIcon( wb_images.getIcon( 'wb.png' ) )

        wx.EVT_CLOSE( self, self.OnCloseWindow )

    def OnCloseWindow( self, event ):
        self.Destroy()


class AnnotatePanel(wx.Panel):
    col_line = 0
    col_revision = 1
    col_author = 2
    col_date = 3
    col_text = 4

    def __init__( self, parent, app, project_info, filename, annotation ):
        wx.Panel.__init__( self, parent, -1 )

        self.app = app
        self.project_info = project_info
        self.filename = filename
        self.annotation = annotation

        self.id_list = wx.NewId()

        self.v_sizer = wx.BoxSizer( wx.VERTICAL )

        self.list_ctrl = wx.ListCtrl( self, self.id_list, wx.DefaultPosition, wx.DefaultSize, wx.LC_REPORT|wx.NO_BORDER)

        self.list_ctrl.InsertColumn( self.col_line, "Line")
        self.list_ctrl.InsertColumn( self.col_revision, "Revision")
        self.list_ctrl.InsertColumn( self.col_author, "Author")
        self.list_ctrl.InsertColumn( self.col_date, "Date")
        self.list_ctrl.InsertColumn( self.col_text, "Text")

        char_width = 9
        self.list_ctrl.SetColumnWidth( self.col_line, 6*char_width )
        self.list_ctrl.SetColumnWidth( self.col_revision, 7*char_width )
        self.list_ctrl.SetColumnWidth( self.col_author, 14*char_width )
        self.list_ctrl.SetColumnWidth( self.col_date, 20*char_width )
        self.list_ctrl.SetColumnWidth( self.col_text, 250*char_width )

        self.v_sizer.Add( self.list_ctrl, 2, wx.EXPAND|wx.ALL, 5 )

        wx.EVT_SIZE( self, self.OnSize )

        self.initList()

        self.SetAutoLayout( True )
        self.SetSizer( self.v_sizer )
        self.v_sizer.Fit( self )
        self.Layout()

    #---------- Comment handlers ------------------------------------------------------------
    def OnSize( self, event):
        w,h = self.GetClientSizeTuple()
        self.v_sizer.SetDimension( 0, 0, w, h )

    def initList( self ):
        if len( self.annotation ) == 0:
            return

        encoding = wb_read_file.encodingFromContents( self.annotation[0]['line'] )

        for index, entry in enumerate( self.annotation ):
            raw_line = entry['line']
            try:
                line = raw_line.decode( encoding )
            except UnicodeDecodeError:
                # fall back to latin-1
                try:
                    line = raw_line.decode( 'iso8859-1' )
                except UnicodeDecodeError:
                    # sigh this is hard. use the choosen encoding and replace chars in error
                    line = raw_line.decode( encoding, 'replace' )

            if '\t' in line:
                column = 1
                char_list = []
                for c in line:
                    if c == '\t':
                        char_list.append( ' ' )
                        column += 1
                        while (column%8) != 0:
                            column += 1
                            char_list.append( ' ' )
                    else:
                        char_list.append( c )
                        column += 1
                tab_expanded_line = ''.join( char_list )
            else:
                tab_expanded_line = line

            self.list_ctrl.InsertStringItem( index, str(entry['number']+1) )
            self.list_ctrl.SetStringItem( index, self.col_revision, str(entry['revision'].number) )
            self.list_ctrl.SetStringItem( index, self.col_author, entry['author'] )
            self.list_ctrl.SetStringItem( index, self.col_date, entry['date'] )
            self.list_ctrl.SetStringItem( index, self.col_text, tab_expanded_line )