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