~toolpart/+junk/pythoncard

« back to all changes in this revision

Viewing changes to samples/testNotebook/doodle.py

  • Committer: Bazaar Package Importer
  • Author(s): Sandro Tosi
  • Date: 2010-03-04 23:55:10 UTC
  • mfrom: (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100304235510-3v6lbhzwrgm0pcca
Tags: 0.8.2-1
* QA upload.
* New upstream release
* debian/control
  - set maintainer to QA group
  - set Homepage field, removing the URL from packages description
  - bump versioned b-d-i on python-support, to properly support Python module
  - replace b-d on python-all-dev with python-all, since building only
    arch:all packages
  - replace Source-Version substvar with source:Version
  - add ${misc:Depends} to binary packages Depends
* debian/watch
  - updated to use the SourceForge redirector; thanks to Raphael Geissert for
    the report and to Dario Minnucci for the patch; Closes: #449904
* debian/{pythoncard-doc, python-pythoncard}.install
  - use wildcards instead of site-packages to fix build with python 2.6;
    thanks to Ilya Barygin for the report and patch; Closes: #572332
* debian/pythoncard-doc.doc-base
  - set section to Programmin/Python
* debian/pythoncard-tools.menu
  - set menu main section to Applications
* debian/pythoncard-tools.postinst
  - removed, needed only to update the menu, but it's now created by debhelper

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
"""
 
4
__version__ = "$Revision: 1.2 $"
 
5
__date__ = "$Date: 2005/09/18 03:59:22 $"
 
6
"""
 
7
 
 
8
from PythonCard import clipboard, dialog, graphic, model
 
9
import wx
 
10
import os
 
11
 
 
12
class Doodle(model.PageBackground):
 
13
 
 
14
    def on_initialize(self, event):
 
15
        self.x = 0
 
16
        self.y = 0
 
17
        self.filename = None
 
18
        
 
19
        sizer1 = wx.BoxSizer(wx.VERTICAL)
 
20
        comp = self.components
 
21
        flags = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.ALIGN_BOTTOM
 
22
        # Mac wxButton needs 7 pixels on bottom and right
 
23
        macPadding = 7
 
24
        sizer1.Add(comp.btnColor, 0, flags, macPadding)
 
25
        sizer1.Add(comp.bufOff, 1, wx.EXPAND)
 
26
        
 
27
        sizer1.Fit(self)
 
28
        sizer1.SetSizeHints(self)
 
29
        self.panel.SetSizer(sizer1)
 
30
        self.panel.SetAutoLayout(1)
 
31
        self.panel.Layout()
 
32
 
 
33
    def on_bufOff_mouseEnter(self, event):
 
34
        self.x, self.y = event.position
 
35
 
 
36
    def on_bufOff_mouseDown(self, event):
 
37
        self.x, self.y = event.position
 
38
        event.target.drawLine((self.x, self.y), (self.x + 1, self.y + 1))
 
39
 
 
40
    def on_bufOff_mouseDrag(self, event):
 
41
        x, y = event.position
 
42
        event.target.drawLine((self.x, self.y), (x, y))
 
43
        self.x = x
 
44
        self.y = y
 
45
 
 
46
    def on_btnColor_mouseClick(self, event):
 
47
        result = dialog.colorDialog(self)
 
48
        if result.accepted:
 
49
            self.components.bufOff.foregroundColor = result.color
 
50
            event.target.backgroundColor = result.color
 
51
 
 
52
    def openFile(self):
 
53
        result = dialog.openFileDialog(None, "Import which file?")
 
54
        if result.accepted:
 
55
            path = result.paths[0]
 
56
            os.chdir(os.path.dirname(path))
 
57
            self.filename = path
 
58
            bmp = graphic.Bitmap(self.filename)
 
59
            self.components.bufOff.drawBitmap(bmp, (0, 0))
 
60
 
 
61
    def on_menuFileOpen_select(self, event):
 
62
        self.openFile()
 
63
 
 
64
    def on_menuFileSaveAs_select(self, event):
 
65
        if self.filename is None:
 
66
            path = ''
 
67
            filename = ''
 
68
        else:
 
69
            path, filename = os.path.split(self.filename)
 
70
        result = dialog.saveFileDialog(None, "Save As", path, filename)
 
71
        if result.accepted:
 
72
            path = result.paths[0]
 
73
            fileType = graphic.bitmapType(path)
 
74
            print fileType, path
 
75
            try:
 
76
                bmp = self.components.bufOff.getBitmap()
 
77
                bmp.SaveFile(path, fileType)
 
78
                return 1
 
79
            except IOError, msg:
 
80
                return 0
 
81
        else:
 
82
            return 0
 
83
 
 
84
    def on_menuEditCopy_select(self, event):
 
85
        clipboard.setClipboard(self.components.bufOff.getBitmap())
 
86
 
 
87
    def on_menuEditPaste_select(self, event):
 
88
        bmp = clipboard.getClipboard()
 
89
        if isinstance(bmp, wx.Bitmap):
 
90
            self.components.bufOff.drawBitmap(bmp)
 
91
 
 
92
    def on_editClear_command(self, event):
 
93
        self.components.bufOff.clear()
 
94
 
 
95
 
 
96
if __name__ == '__main__':
 
97
    app = model.Application(Doodle)
 
98
    app.MainLoop()