author | Laurent Bessard |
Tue, 10 Sep 2013 23:23:45 +0200 | |
changeset 1314 | 822d483197ad |
parent 815 | e4f24593a758 |
child 1571 | 486f94a8032c |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
7 |
#Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD |
|
8 |
# |
|
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
12 |
#modify it under the terms of the GNU General Public |
|
13 |
#License as published by the Free Software Foundation; either |
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 |
#General Public License for more details. |
|
20 |
# |
|
21 |
#You should have received a copy of the GNU General Public |
|
22 |
#License along with this library; if not, write to the Free Software |
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
25 |
import os |
|
26 |
||
27 |
import wx |
|
28 |
||
29 |
#------------------------------------------------------------------------------- |
|
30 |
# Library Structures |
|
31 |
#------------------------------------------------------------------------------- |
|
32 |
||
33 |
BitmapLibrary = {} |
|
34 |
BitmapFolders = [] |
|
35 |
||
36 |
#------------------------------------------------------------------------------- |
|
37 |
# Library Helpers |
|
38 |
#------------------------------------------------------------------------------- |
|
39 |
||
40 |
def AddBitmapFolder(path): |
|
815
e4f24593a758
Adding support for extending internationalization to extensions
laurent
parents:
814
diff
changeset
|
41 |
if os.path.exists(path) and os.path.isdir(path) and path not in BitmapFolders: |
814 | 42 |
BitmapFolders.append(path) |
43 |
||
44 |
def SearchBitmap(bmp_name): |
|
45 |
for folder in BitmapFolders: |
|
46 |
bmp_path = os.path.join(folder, bmp_name + ".png") |
|
47 |
if os.path.isfile(bmp_path): |
|
48 |
return wx.Bitmap(bmp_path) |
|
49 |
return None |
|
50 |
||
51 |
def GetBitmap(bmp_name1, bmp_name2=None, size=None): |
|
52 |
bmp = BitmapLibrary.get((bmp_name1, bmp_name2, size)) |
|
53 |
if bmp is not None: |
|
54 |
return bmp |
|
55 |
||
56 |
if bmp_name2 is None: |
|
57 |
bmp = SearchBitmap(bmp_name1) |
|
58 |
else: |
|
59 |
# Bitmap with two icon |
|
60 |
bmp1 = SearchBitmap(bmp_name1) |
|
61 |
bmp2 = SearchBitmap(bmp_name2) |
|
62 |
||
63 |
if bmp1 is not None and bmp2 is not None: |
|
64 |
# Calculate bitmap size |
|
65 |
width = bmp1.GetWidth() + bmp2.GetWidth() - 1 |
|
66 |
height = max(bmp1.GetHeight(), bmp2.GetHeight()) |
|
67 |
||
68 |
# Create bitmap with both icons |
|
69 |
bmp = wx.EmptyBitmap(width, height) |
|
70 |
dc = wx.MemoryDC() |
|
71 |
dc.SelectObject(bmp) |
|
72 |
dc.Clear() |
|
73 |
dc.DrawBitmap(bmp1, 0, 0) |
|
74 |
dc.DrawBitmap(bmp2, bmp1.GetWidth() - 1, 0) |
|
75 |
dc.Destroy() |
|
76 |
||
77 |
elif bmp1 is not None: |
|
78 |
bmp = bmp1 |
|
79 |
elif bmp2 is not None: |
|
80 |
bmp = bmp2 |
|
81 |
||
82 |
if bmp is not None: |
|
83 |
BitmapLibrary[(bmp_name1, bmp_name2, size)] = bmp |
|
84 |
||
85 |
return bmp |