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
|
#!/usr/bin/python
"""
__version__ = "$Revision: 1.17 $"
__date__ = "$Date: 2004/08/12 19:18:58 $"
"""
from PythonCard import clipboard, dialog, graphic, model
import wx
import os
rsrc = {'application':{'type':'Application',
'name':'saveClipboardBitmap',
'backgrounds': [
{'type':'Background',
'name':'bgMin',
'title':'saveClipboardBitmap PythonCard Application',
'size':(200, 100),
'menubar':
{
'type':'MenuBar',
'menus':
[
{ 'type':'Menu',
'name':'menuFile',
'label':'&File',
'items': [
{ 'type':'MenuItem',
'name':'menuFileSaveAs',
'label':'&Save As...\tCtrl+S' },
{ 'type':'MenuItem',
'name':'menuFileExit',
'label':'E&xit\tAlt+X',
'command':'exit' },
] }
]
},
'components': [
] # end components
} # end background
] # end backgrounds
} }
class Minimal(model.Background):
def on_initialize(self, event):
self.bmp = None
self.filename = None
# since there might already be an image in the clipboard
# go ahead and prompt to save it
self.on_menuFileSaveAs_select(None)
def on_menuFileSaveAs_select(self, event):
self.bmp = clipboard.getClipboard()
if not isinstance(self.bmp, wx.Bitmap):
return
if self.filename is None:
path = ''
filename = ''
else:
path, filename = os.path.split(self.filename)
# wxPython can't save GIF due to the license issues
# but we can save most other formats, so this list can be expanded
wildcard = "PNG files (*.png)|*.PNG;*.png" + \
"|JPG files (*.jpg;*.jpeg)|*.jpeg;*.JPG;*.JPEG;*.jpg" + \
"|BMP files (*.bmp)|*.BMP;*.bmp" + \
"|All Files (*.*)|*.*"
result = dialog.saveFileDialog(None, "Save As", path, filename, wildcard)
if result.accepted:
path = result.paths[0]
fileType = graphic.bitmapType(path)
#print fileType, path
self.filename = path
try:
self.bmp.SaveFile(path, fileType)
return True
except:
return False
else:
return False
if __name__ == '__main__':
app = model.Application(Minimal, None, rsrc)
app.MainLoop()
|