attachment.py :  » Project-Management » Task-Coach » TaskCoach-1.0.3 » taskcoachlib » gui » viewer » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Project Management » Task Coach 
Task Coach » TaskCoach 1.0.3 » taskcoachlib » gui » viewer » attachment.py
# -*- coding: utf-8 -*-

'''
Task Coach - Your friendly task manager
Copyright (C) 2004-2010 Frank Niessink <frank@niessink.com>
Copyright (C) 2007-2008 Jrme Laheurte <fraca7@free.fr>
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/>.
'''

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


class AttachmentViewer(mixin.AttachmentDropTargetMixin, base.ViewerWithColumns,
                       mixin.SortableViewerForAttachmentsMixin, 
                       mixin.SearchableViewerMixin, mixin.NoteColumnMixin,
                       base.ListViewer):
    SorterClass = attachment.AttachmentSorter
    viewerImages = base.ListViewer.viewerImages + ['fileopen', 'fileopen_red']

    def __init__(self, *args, **kwargs):
        self.attachments = kwargs.pop('attachmentsToShow')
        kwargs.setdefault('settingssection', 'attachmentviewer')
        super(AttachmentViewer, self).__init__(*args, **kwargs)
        
    def domainObjectsToView(self):
        return self.attachments

    def isShowingAttachments(self):
        return True
    
    def curselectionIsInstanceOf(self, class_):
        return class_ == attachment.Attachment

    def _addAttachments(self, attachments, index, **itemDialogKwargs):
        self.presentation().extend(attachments)

    def createWidget(self):
        imageList = self.createImageList()
        itemPopupMenu = menu.AttachmentPopupMenu(self.parent, self.settings,
            self.presentation(), self)
        columnPopupMenu = menu.ColumnPopupMenu(self)
        self._popupMenus.extend([itemPopupMenu, columnPopupMenu])
        self._columns = self._createColumns()
        widget = widgets.ListCtrl(self, self.columns(), self.onSelect,
            uicommand.AttachmentEdit(viewer=self, attachments=self.presentation()),
            itemPopupMenu, columnPopupMenu,
            resizeableColumn=1, **self.widgetCreationKeywordArguments())
        widget.SetColumnWidth(0, 150)
        widget.AssignImageList(imageList, wx.IMAGE_LIST_SMALL)
        return widget

    def _createColumns(self):
        return [widgets.Column('type', _('Type'), 
                               '',
                               width=self.getColumnWidth('type'),
                               imageIndexCallback=self.typeImageIndex,
                               renderCallback=lambda item: '',
                               resizeCallback=self.onResizeColumn),
                widgets.Column('subject', _('Subject'), 
                               attachment.Attachment.subjectChangedEventType(), 
                               sortCallback=uicommand.ViewerSortByCommand(viewer=self,
                                   value='subject',
                                   menuText=_('Sub&ject'), helpText=_('Sort by subject')),
                               width=self.getColumnWidth('subject'), 
                               renderCallback=lambda item: item.subject(),
                               resizeCallback=self.onResizeColumn),
                widgets.Column('description', _('Description'),
                               attachment.Attachment.subjectChangedEventType(),
                               sortCallback=uicommand.ViewerSortByCommand(viewer=self,
                                   value='description',
                                   menuText=_('&Description'), helpText=_('Sort by description')),
                               width=self.getColumnWidth('description'),
                               renderCallback=lambda item: item.description(),
                               resizeCallback=self.onResizeColumn),
                widgets.Column('notes', '', 
                               attachment.Attachment.notesChangedEventType(), # pylint: disable-msg=E1101
                               width=self.getColumnWidth('notes'),
                               alignment=wx.LIST_FORMAT_LEFT,
                               imageIndexCallback=self.noteImageIndex,
                               headerImageIndex=self.imageIndex['note_icon'],
                               renderCallback=lambda item: '',
                               resizeCallback=self.onResizeColumn),
                ]

    def createColumnUICommands(self):
        return [\
            uicommand.ToggleAutoColumnResizing(viewer=self,
                                               settings=self.settings),
            None,
            uicommand.ViewColumn(menuText=_('&Description'),
                helpText=_('Show/hide description column'),
                setting='description', viewer=self),
            uicommand.ViewColumn(menuText=_('&Notes'),
                helpText=_('Show/hide notes column'),
                setting='notes', viewer=self)]

    def createToolBarUICommands(self):
        commands = super(AttachmentViewer, self).createToolBarUICommands()
        commands[-2:-2] = [None,
                           uicommand.AttachmentNew(attachments=self.presentation(),
                                                   settings=self.settings),
                           uicommand.AttachmentEdit(attachments=self.presentation(),
                                                    viewer=self),
                           uicommand.AttachmentDelete(attachments=self.presentation(),
                                                      viewer=self),
                           None,
                           uicommand.AttachmentOpen(attachments=attachment.AttachmentList(),
                                                    viewer=self)]
        return commands

    def typeImageIndex(self, anAttachment, which): # pylint: disable-msg=W0613
        if anAttachment.type_ == 'file':
            if os.path.exists(anAttachment.normalizedLocation()):
                return self.imageIndex['fileopen']
            return self.imageIndex['fileopen_red']

        try:
            return self.imageIndex[{ 'uri': 'earth_blue_icon',
                                     'mail': 'email'}[anAttachment.type_]]
        except KeyError:
            return -1
    
    def deleteItemCommand(self):
        return command.DeleteAttachmentCommand(self.presentation(), self.curselection())
    
    def editorClass(self):
        return dialog.editor.AttachmentEditor
    
    def newItemCommandClass(self):
        return command.NewAttachmentCommand
    
    def editItemCommandClass(self):
        return command.EditAttachmentCommand

    def deleteItemCommandClass(self):
        return command.DeleteAttachmentCommand
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.