File: note.py

package info (click to toggle)
taskcoach 1.4.1-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 32,496 kB
  • ctags: 17,810
  • sloc: python: 72,170; makefile: 254; ansic: 120; xml: 29; sh: 16
file content (209 lines) | stat: -rw-r--r-- 9,948 bytes parent folder | download
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# -*- coding: utf-8 -*-

'''
Task Coach - Your friendly task manager
Copyright (C) 2004-2014 Task Coach developers <developers@taskcoach.org>
Copyright (C) 2008 Rob McMullen <rob.mcmullen@gmail.com>
Copyright (C) 2008 Thomas Sonne Olesen <tpo@sonnet.dk>

Task Coach is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Task Coach is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
'''

from taskcoachlib import command, widgets, domain
from taskcoachlib.domain import note
from taskcoachlib.gui import uicommand, menu, dialog
from taskcoachlib.i18n import _
import base
import mixin
import inplace_editor
import wx


class BaseNoteViewer(mixin.AttachmentDropTargetMixin,  # pylint: disable=W0223
                     mixin.SearchableViewerMixin, 
                     mixin.SortableViewerForNotesMixin,
                     mixin.AttachmentColumnMixin, 
                     base.CategorizableViewerMixin,
                     base.WithAttachmentsViewerMixin,
                     base.SortableViewerWithColumns, base.TreeViewer):
    SorterClass = note.NoteSorter
    defaultTitle = _('Notes')
    defaultBitmap = 'note_icon'
    
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('settingsSection', 'noteviewer')
        self.notesToShow = kwargs.get('notesToShow', None)
        super(BaseNoteViewer, self).__init__(*args, **kwargs)
        for eventType in (note.Note.appearanceChangedEventType(), 
                          note.Note.subjectChangedEventType()):
            self.registerObserver(self.onAttributeChanged_Deprecated, 
                                  eventType)

    def domainObjectsToView(self):
        return self.taskFile.notes() if self.notesToShow is None else self.notesToShow

    def curselectionIsInstanceOf(self, class_):
        return class_ == note.Note

    def createWidget(self):
        imageList = self.createImageList()  # Has side-effects
        self._columns = self._createColumns()
        itemPopupMenu = menu.NotePopupMenu(self.parent, self.settings,
            self.taskFile.categories(), self)
        columnPopupMenu = menu.ColumnPopupMenu(self)
        self._popupMenus.extend([itemPopupMenu, columnPopupMenu])
        widget = widgets.TreeListCtrl(self, self.columns(), self.onSelect,
            uicommand.Edit(viewer=self),
            uicommand.NoteDragAndDrop(viewer=self, notes=self.presentation()),
            itemPopupMenu, columnPopupMenu,
            resizeableColumn=1 if self.hasOrderingColumn() else 0,
            validateDrag=self.validateDrag,
            **self.widgetCreationKeywordArguments())
        if self.hasOrderingColumn():
            widget.SetMainColumn(1)
        widget.AssignImageList(imageList)  # pylint: disable=E1101
        return widget
    
    def createFilter(self, notes):
        notes = super(BaseNoteViewer, self).createFilter(notes)
        return domain.base.DeletedFilter(notes)
    
    def createCreationToolBarUICommands(self):
        return (uicommand.NoteNew(notes=self.presentation(),
                                  settings=self.settings, viewer=self),
                uicommand.NewSubItem(viewer=self),) + \
            super(BaseNoteViewer, self).createCreationToolBarUICommands()
        
    def createColumnUICommands(self):
        return [\
            uicommand.ToggleAutoColumnResizing(viewer=self,
                                               settings=self.settings),
            None,
            uicommand.ViewColumn(menuText=_('&Manual ordering'),
                helpText=_('Show/hide the manual ordering column'),
                setting='ordering', viewer=self),
            uicommand.ViewColumn(menuText=_('&Description'),
                helpText=_('Show/hide description column'),
                setting='description', viewer=self),
            uicommand.ViewColumn(menuText=_('&Attachments'),
                helpText=_('Show/hide attachments column'),
                setting='attachments', viewer=self),
            uicommand.ViewColumn(menuText=_('&Categories'),
                helpText=_('Show/hide categories column'),
                setting='categories', viewer=self),
            uicommand.ViewColumn(menuText=_('&Creation date'),
                helpText=_('Show/hide creation date column'),
                setting='creationDateTime', viewer=self),
            uicommand.ViewColumn(menuText=_('&Modification date'),
                helpText=_('Show/hide last modification date column'),
                setting='modificationDateTime', viewer=self)]

    def _createColumns(self):
        orderingColumn = widgets.Column('ordering', u'',
            width=self.getColumnWidth('ordering'),
            resizeCallback=self.onResizeColumn,
            renderCallback=lambda note: '',
            imageIndicesCallback=self.orderingImageIndices,
            sortCallback=uicommand.ViewerSortByCommand(viewer=self,
                value='ordering', menuText=_('&Manual ordering'),
                helpText=_('Sort notes manually')))
        # XXXCHECK editCallback & co
        subjectColumn = widgets.Column('subject', _('Subject'), 
            width=self.getColumnWidth('subject'), 
            resizeCallback=self.onResizeColumn,
            renderCallback=lambda note: note.subject(),
            sortCallback=uicommand.ViewerSortByCommand(viewer=self, 
                value='subject', menuText=_('&Subject'), 
                helpText=_('Sort notes by subject')),
            imageIndicesCallback=self.subjectImageIndices,
            editCallback=self.onEditSubject,
            editControl=inplace_editor.SubjectCtrl)
        descriptionColumn = widgets.Column('description', _('Description'),
            note.Note.descriptionChangedEventType(),
            width=self.getColumnWidth('description'), 
            resizeCallback=self.onResizeColumn,
            renderCallback=lambda note: note.description(),
            sortCallback=uicommand.ViewerSortByCommand(viewer=self, 
                value='description', menuText=_('&Description'), 
                helpText=_('Sort notes by description')),
            editCallback=self.onEditDescription,
            editControl=inplace_editor.DescriptionCtrl)
        attachmentsColumn = widgets.Column('attachments', '', 
            note.Note.attachmentsChangedEventType(),  # pylint: disable=E1101
            width=self.getColumnWidth('attachments'),
            alignment=wx.LIST_FORMAT_LEFT,
            imageIndicesCallback=self.attachmentImageIndices,  # pylint: disable=E1101
            headerImageIndex=self.imageIndex['paperclip_icon'],
            renderCallback=lambda note: '')
        categoriesColumn = widgets.Column('categories', _('Categories'),
            note.Note.categoryAddedEventType(), 
            note.Note.categoryRemovedEventType(), 
            note.Note.categorySubjectChangedEventType(),
            note.Note.expansionChangedEventType(),
            width=self.getColumnWidth('categories'),
            resizeCallback=self.onResizeColumn,
            renderCallback=self.renderCategories,
            sortCallback=uicommand.ViewerSortByCommand(viewer=self, 
                value='categories', menuText=_('&Categories'), 
                helpText=_('Sort notes by categories')))
        creationDateTimeColumn = widgets.Column('creationDateTime', 
            _('Creation date'), width=self.getColumnWidth('creationDateTime'),
            resizeCallback=self.onResizeColumn,
            renderCallback=self.renderCreationDateTime,
            sortCallback=uicommand.ViewerSortByCommand(viewer=self,
                value='creationDateTime', menuText=_('&Creation date'),
                helpText=_('Sort notes by creation date')))
        modificationDateTimeColumn = widgets.Column('modificationDateTime', 
            _('Modification date'), 
            width=self.getColumnWidth('modificationDateTime'),
            resizeCallback=self.onResizeColumn,
            renderCallback=self.renderModificationDateTime,
            sortCallback=uicommand.ViewerSortByCommand(viewer=self,
                value='modificationDateTime', menuText=_('&Modification date'),
                helpText=_('Sort notes by last modification date')),
            *note.Note.modificationEventTypes())
        return [orderingColumn, subjectColumn, descriptionColumn, attachmentsColumn, 
                categoriesColumn, creationDateTimeColumn, 
                modificationDateTimeColumn]
                    
    def isShowingNotes(self):
        return True

    def statusMessages(self):
        status1 = _('Notes: %d selected, %d total') % \
            (len(self.curselection()), len(self.presentation()))
        status2 = _('Status: n/a')
        return status1, status2

    def newItemDialog(self, *args, **kwargs):
        kwargs['categories'] = self.taskFile.categories().filteredCategories()
        return super(BaseNoteViewer, self).newItemDialog(*args, **kwargs)
    
    def deleteItemCommand(self):
        return command.DeleteNoteCommand(self.presentation(), 
            self.curselection(), 
            shadow=self.settings.getboolean('feature', 'syncml'))
        
    def itemEditorClass(self):
        return dialog.editor.NoteEditor

    def newItemCommandClass(self):
        return command.NewNoteCommand
    
    def newSubItemCommandClass(self):
        return command.NewSubNoteCommand


class NoteViewer(mixin.FilterableViewerForCategorizablesMixin, BaseNoteViewer):  # pylint: disable=W0223
    pass