def LoadIconList(self):
isz = (16, 16)
self.tree_fs.icon_list = wx.ImageList(*isz)
folder = wx.Icon(
'icons/ic_folder_black_18dp.png',
wx.BITMAP_TYPE_PNG,
isz[0],
isz[1],
)
folder_open = wx.Icon(
'icons/ic_folder_open_black_18dp.png',
wx.BITMAP_TYPE_PNG,
isz[0],
isz[1],
)
self.tree_fs.icon_fldridx = self.tree_fs.icon_list.AddIcon(folder)
self.tree_fs.icon_fldropenidx = self.tree_fs.icon_list.AddIcon(folder_open)
self.tree_fs.icon_fileidx = self.tree_fs.icon_list.AddIcon(wx.ArtProvider.GetIcon(wx.ART_NORMAL_FILE, wx.ART_OTHER, isz))
self.tree_fs.SetImageList(self.tree_fs.icon_list)
python类BITMAP_TYPE_PNG的实例源码
def __init__(self, parent):
"""Constructor"""
self.notUseDetaul = None
wx.Panel.__init__(self, parent=parent, size = (500,800))
B = wx.StaticBox(self, -1)
BSizer = wx.StaticBoxSizer(B, wx.VERTICAL)
self.imagesDir = os.path.join(".", "images")
self.screenShotDir = os.path.join(".", "screenShot")
self.defaultScreenShotImage = wx.Image(os.path.join(self.imagesDir, "default.png"), wx.BITMAP_TYPE_PNG).ConvertToBitmap()
self.screenShot = wx.StaticBitmap(self,-1, self.defaultScreenShotImage)
self.screenShot.Bind(wx.EVT_LEFT_DOWN, self.DrawOrReloadAll)
self.statusBar = wx.StaticText(self, -1, "")
BSizer.Add(self.statusBar)
BSizer.Add(self.screenShot,5,wx.EXPAND, 5)
self.SetSizer(BSizer)
pub.subscribe(self.updateStatus, "update")
pub.subscribe(self.DrawFromSelectedNode, "DrawFromSelectedNode")
pub.subscribe(self.DoSwipeOrInput, "DoSwipeOrInput")
self.hasDrew = False
def OnAboutBox(self):
description = """StopGo helps you create stop motion animation."""
licence = """StopGo 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.
StopGo 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 File Hunter;
if not, write to the Free Software Foundation, Inc., 59 Temple Place,
Suite 330, Boston, MA VERSION_STRIVERSION_STRIVERSION_STRINVERSION_STRING307 USA"""
info = wx.AboutDialogInfo()
info.SetIcon(wx.Icon(os.path.join(os.path.dirname(__file__),'..','..','stopgo','images','makerbox.png'), wx.BITMAP_TYPE_PNG))
info.SetName('StopGo')
info.SetVersion('0.8.18')
info.SetDescription(description)
info.SetCopyright('(C) 2016 - ' + str(date.today().year) + ' Seth Kenlon')
info.SetWebSite('http://makerbox.org.nz')
info.SetLicence(licence)
info.AddDeveloper('Klaatu, Seth Kenlon, Jess Weichler')
wx.AboutBox(info)
def __init__(self, parent):
logo = wx.Image(os.path.dirname(__file__) + '/images/CEBL3_splash.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap()
#wx.adv.SplashScreen.__init__(self, # wxpython3
wx.SplashScreen.__init__(self,
parent=parent, milliseconds=2000, bitmap=logo,
#splashStyle=wx.adv.SPLASH_CENTER_ON_SCREEN | wx.adv.SPLASH_TIMEOUT) # wxpython3
splashStyle=wx.SPLASH_CENTER_ON_SCREEN | wx.SPLASH_TIMEOUT)
def saveFile(self):
self.refresh()
saveDialog = wx.FileDialog(self, message='Save Image',
wildcard='Portable Network Graphics (*.png)|*.png|All Files|*',
style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
try:
if saveDialog.ShowModal() != wx.ID_CANCEL:
img = self.drawingBuffer.ConvertToImage()
img.SaveFile(saveDialog.GetPath(), wx.BITMAP_TYPE_PNG)
except Exception as e:
wx.LogError('Save failed!')
raise
finally:
saveDialog.Destroy()
def saveImageGL(mvcanvas, filename):
view = glGetIntegerv(GL_VIEWPORT)
img = wx.EmptyImage(view[2], view[3] )
pixels = glReadPixels(0, 0, view[2], view[3], GL_RGB,
GL_UNSIGNED_BYTE)
img.SetData( pixels )
img = img.Mirror(False)
img.SaveFile(filename, wx.BITMAP_TYPE_PNG)
def saveImage(canvas, filename):
s = wx.ScreenDC()
w, h = canvas.size.Get()
b = wx.EmptyBitmap(w, h)
m = wx.MemoryDCFromDC(s)
m.SelectObject(b)
m.Blit(0, 0, w, h, s, 70, 0)
m.SelectObject(wx.NullBitmap)
b.SaveFile(filename, wx.BITMAP_TYPE_PNG)
def get(self, iconname):
try:
image = 'img\\' + self.img_dict[iconname]
except KeyError:
print 'Image: "{}" not found!'.format(iconname)
image = 'img\\' + self.img_dict['toilet']
wximage = wx.Image(self.path + image, wx.BITMAP_TYPE_PNG).ConvertToBitmap()
return wximage
def OnAboutMenu(self, event):
info = version.GetAboutDialogInfo()
info.Name = "PLCOpenEditor"
info.Description = _("PLCOpenEditor is part of Beremiz project.\n\n"
"Beremiz is an ") + info.Description
info.Icon = wx.Icon(os.path.join(beremiz_dir, "images", "aboutlogo.png"), wx.BITMAP_TYPE_PNG)
ShowAboutDialog(self, info)
def save_bitmap(self, path):
context = wx.ClientDC( self )
memory = wx.MemoryDC( )
x, y = self.ClientSize
bitmap = wx.Bitmap( x, y, -1 )
memory.SelectObject( bitmap )
memory.Blit( 0, 0, x, y, context, 0, 0)
memory.SelectObject( wx.NullBitmap)
bitmap.SaveFile( path, wx.BITMAP_TYPE_PNG )
def save_buffer(self, path):
self.buffer.SaveFile(path, wx.BITMAP_TYPE_PNG)
def save(self, path):
self.buffer.SaveFile(path, wx.BITMAP_TYPE_PNG)
def saveImageGL(mvcanvas, filename):
view = glGetIntegerv(GL_VIEWPORT)
img = wx.EmptyImage(view[2], view[3] )
pixels = glReadPixels(0, 0, view[2], view[3], GL_RGB,
GL_UNSIGNED_BYTE)
img.SetData( pixels )
img = img.Mirror(False)
img.SaveFile(filename, wx.BITMAP_TYPE_PNG)
def saveImage(canvas, filename):
s = wx.ScreenDC()
w, h = canvas.size.Get()
b = wx.EmptyBitmap(w, h)
m = wx.MemoryDCFromDC(s)
m.SelectObject(b)
m.Blit(0, 0, w, h, s, 70, 0)
m.SelectObject(wx.NullBitmap)
b.SaveFile(filename, wx.BITMAP_TYPE_PNG)
def __init__(self, *args, **kwds):
wx.Frame.__init__(self, *args, **kwds)
self.icon = wx.Icon("/usr/share/icons/hicolor/128x128/apps/switch-icon.png", wx.BITMAP_TYPE_PNG)
self.SetIcon(self.icon)
with open(CurrentHosts, "rb") as fp:
self.current = fp.read()
self.all_hosts = get_all_hosts()
self.combo_box_1 = wx.ComboBox(self, wx.ID_ANY, choices = self.all_hosts, style = wx.CB_DROPDOWN)
index = 0
try:
index = self.all_hosts.index(self.current)
except Exception:
pass
self.combo_box_1.Select(index)
self.button_add = wx.Button(self, wx.ID_ANY, "Add")
self.button_delete = wx.Button(self, wx.ID_ANY, "Delete")
self.button_edit = wx.Button(self, wx.ID_ANY, "Edit")
self.button_set = wx.Button(self, wx.ID_ANY, "Set")
self.Bind(wx.EVT_BUTTON, self.OnAdd, self.button_add)
self.Bind(wx.EVT_BUTTON, self.OnDelete, self.button_delete)
self.Bind(wx.EVT_BUTTON, self.OnEdit, self.button_edit)
self.Bind(wx.EVT_BUTTON, self.OnSet, self.button_set)
self.statusbar = self.CreateStatusBar(1)
self.__set_properties()
self.__do_layout()
def setup_icon(self):
icon_file = os.path.join(core.BASE_DIR, 'janet.png')
if os.path.exists(icon_file):
icon = wx.IconFromBitmap(wx.Bitmap(icon_file, wx.BITMAP_TYPE_PNG))
self.SetIcon(icon)
def get_icon(self, text):
"""
Return a wx icon from a file like object containing the image
with text.
TODO: transparency support
"""
background = self.conf.get_color('Look', 'background')
foreground = self.conf.get_color('Look', 'color')
font = ImageFont.truetype(
self.conf.get_font_path(),
self.conf.get_int('Look', 'size'),
)
if font is None:
logger.critical("Font could not be looked up. Try setting "
"font_path in the configuration file to the full "
"path to a truetype font.")
mask = Image.new('RGB', (WIDTH, HEIGHT), background)
draw = ImageDraw.Draw(mask)
draw.text(
background,
text,
font=font,
fill=foreground,
)
mask = self.trim(mask)
buf = io.StringIO()
mask.save(buf, 'png')
buf.seek(0)
icon = wx.IconFromBitmap(
wx.BitmapFromImage(
wx.ImageFromStream(
buf,
wx.BITMAP_TYPE_PNG
)
)
)
return icon
def save_data(self):
image_file = self.outputDir+'/'+'img_'+str(self.t)+'.png'
self.bmp.SaveFile(image_file, wx.BITMAP_TYPE_PNG)
# make / open outfile
outfile = open(self.outputDir+'/'+'data.csv', 'a')
# write line
outfile.write( image_file + ',' + ','.join(map(str, self.controller_data)) + '\n' )
outfile.close()
self.t += 1
def SaveFile(self, fileName=''):
"""Saves the file to the type specified in the extension. If no file
name is specified a dialog box is provided. Returns True if sucessful,
otherwise False.
.bmp Save a Windows bitmap file.
.xbm Save an X bitmap file.
.xpm Save an XPM bitmap file.
.png Save a Portable Network Graphics file.
.jpg Save a Joint Photographic Experts Group file.
"""
extensions = {
"bmp": wx.BITMAP_TYPE_BMP, # Save a Windows bitmap file.
"xbm": wx.BITMAP_TYPE_XBM, # Save an X bitmap file.
"xpm": wx.BITMAP_TYPE_XPM, # Save an XPM bitmap file.
"jpg": wx.BITMAP_TYPE_JPEG, # Save a JPG file.
"png": wx.BITMAP_TYPE_PNG, # Save a PNG file.
}
fType = _string.lower(fileName[-3:])
dlg1 = None
while fType not in extensions:
if dlg1: # FileDialog exists: Check for extension
dlg2 = wx.MessageDialog(self, 'File name extension\n'
'must be one of\nbmp, xbm, xpm, png, or jpg',
'File Name Error', wx.OK | wx.ICON_ERROR)
try:
dlg2.ShowModal()
finally:
dlg2.Destroy()
# FileDialog doesn't exist: just check one
else:
dlg1 = wx.FileDialog(
self,
"Choose a file with extension bmp, gif, xbm, xpm, png, or jpg", ".", "",
"BMP files (*.bmp)|*.bmp|XBM files (*.xbm)|*.xbm|XPM file (*.xpm)|*.xpm|PNG files (*.png)|*.png|JPG files (*.jpg)|*.jpg",
wx.SAVE | wx.OVERWRITE_PROMPT
)
if dlg1.ShowModal() == wx.ID_OK:
fileName = dlg1.GetPath()
fType = _string.lower(fileName[-3:])
else: # exit without saving
dlg1.Destroy()
return False
if dlg1:
dlg1.Destroy()
# Save Bitmap
res = self._Buffer.SaveFile(fileName, extensions[fType])
return res
def onTakeScreenShot(self, event):
"""
Takes a screenshot of the screen at give pos & size (rect).
Method based on a script by Andrea Gavana
"""
print('Taking screenshot...')
rect = self.GetRect()
# adjust widths for Linux (figured out by John Torres
# http://article.gmane.org/gmane.comp.python.wxpython/67327)
if sys.platform == 'linux2':
client_x, client_y = self.ClientToScreen((0, 0))
border_width = client_x - rect.x
title_bar_height = client_y - rect.y
rect.width += (border_width * 2)
rect.height += title_bar_height + border_width
# Create a DC for the whole screen area
dcScreen = wx.ScreenDC()
# Create a Bitmap that will hold the screenshot image later on
# Note that the Bitmap must have a size big enough to hold the screenshot
# -1 means using the current default colour depth
bmp = wx.EmptyBitmap(rect.width, rect.height)
#Create a memory DC that will be used for actually taking the screenshot
memDC = wx.MemoryDC()
# Tell the memory DC to use our Bitmap
# all drawing action on the memory DC will go to the Bitmap now
memDC.SelectObject(bmp)
# Blit (in this case copy) the actual screen on the memory DC
# and thus the Bitmap
memDC.Blit( 0, # Copy to this X coordinate
0, # Copy to this Y coordinate
rect.width, # Copy this width
rect.height, # Copy this height
dcScreen, # Where to copy from
rect.x, # What's the X offset in the original DC?
rect.y # What's the Y offset in the original DC?
)
# Select the Bitmap out of the memory DC by selecting a new
# uninitialized Bitmap
memDC.SelectObject(wx.NullBitmap)
img = bmp.ConvertToImage()
fileName = "myImage.png"
img.SaveFile(fileName, wx.BITMAP_TYPE_PNG)
print('...saving as png!')