Laurent@714: #!/usr/bin/env python Laurent@714: # -*- coding: utf-8 -*- Laurent@714: Laurent@714: #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor Laurent@714: #based on the plcopen standard. Laurent@714: # Laurent@714: #Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD Laurent@714: # Laurent@714: #See COPYING file for copyrights details. Laurent@714: # Laurent@714: #This library is free software; you can redistribute it and/or Laurent@714: #modify it under the terms of the GNU General Public Laurent@714: #License as published by the Free Software Foundation; either Laurent@714: #version 2.1 of the License, or (at your option) any later version. Laurent@714: # Laurent@714: #This library is distributed in the hope that it will be useful, Laurent@714: #but WITHOUT ANY WARRANTY; without even the implied warranty of Laurent@714: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Laurent@714: #General Public License for more details. Laurent@714: # Laurent@714: #You should have received a copy of the GNU General Public Laurent@714: #License along with this library; if not, write to the Free Software Laurent@714: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Laurent@714: Laurent@714: import os Laurent@714: Laurent@714: import wx Laurent@714: Laurent@714: #------------------------------------------------------------------------------- Laurent@714: # Library Structures Laurent@714: #------------------------------------------------------------------------------- Laurent@714: Laurent@714: BitmapLibrary = {} Laurent@714: BitmapFolders = [] Laurent@714: Laurent@714: #------------------------------------------------------------------------------- Laurent@714: # Library Helpers Laurent@714: #------------------------------------------------------------------------------- Laurent@714: Laurent@714: def AddBitmapFolder(path): Laurent@714: if path not in BitmapFolders: Laurent@714: BitmapFolders.append(path) Laurent@714: Laurent@714: def SearchBitmap(bmp_name): Laurent@714: for folder in BitmapFolders: Laurent@714: bmp_path = os.path.join(folder, bmp_name + ".png") Laurent@714: if os.path.isfile(bmp_path): Laurent@714: return wx.Bitmap(bmp_path) Laurent@714: return None Laurent@714: Laurent@714: def GetBitmap(bmp_name1, bmp_name2=None, size=None): Laurent@714: bmp = BitmapLibrary.get((bmp_name1, bmp_name2, size)) Laurent@714: if bmp is not None: Laurent@714: return bmp Laurent@714: Laurent@714: if bmp_name2 is None: Laurent@714: bmp = SearchBitmap(bmp_name1) Laurent@714: else: Laurent@714: # Bitmap with two icon Laurent@714: bmp1 = SearchBitmap(bmp_name1) Laurent@714: bmp2 = SearchBitmap(bmp_name2) Laurent@714: Laurent@714: if bmp1 is not None and bmp2 is not None: Laurent@714: # Calculate bitmap size Laurent@714: width = bmp1.GetWidth() + bmp2.GetWidth() - 1 Laurent@714: height = max(bmp1.GetHeight(), bmp2.GetHeight()) Laurent@714: Laurent@714: # Create bitmap with both icons Laurent@714: bmp = wx.EmptyBitmap(width, height) Laurent@714: dc = wx.MemoryDC() Laurent@714: dc.SelectObject(bmp) Laurent@714: dc.Clear() Laurent@714: dc.DrawBitmap(bmp1, 0, 0) Laurent@714: dc.DrawBitmap(bmp2, bmp1.GetWidth() - 1, 0) Laurent@714: dc.Destroy() Laurent@714: Laurent@714: elif bmp1 is not None: Laurent@714: bmp = bmp1 Laurent@714: elif bmp2 is not None: Laurent@714: bmp = bmp2 Laurent@714: Laurent@714: if bmp is not None: Laurent@714: BitmapLibrary[(bmp_name1, bmp_name2, size)] = bmp Laurent@714: Laurent@714: return bmp