author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Sat, 16 Sep 2017 21:04:34 +0300 | |
changeset 1815 | f0600fe03a89 |
parent 1782 | 5b6ad7a7fd9d |
child 1881 | 091005ec69c4 |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
815
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
815
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
814 | 6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
815
diff
changeset
|
7 |
# Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD |
814 | 8 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
815
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
814 | 10 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
815
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
815
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
815
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
815
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
814 | 15 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
815
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
815
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
815
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
815
diff
changeset
|
19 |
# GNU General Public License for more details. |
814 | 20 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
815
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
815
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
815
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 24 |
|
25 |
import os |
|
26 |
||
27 |
import wx |
|
28 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
29 |
# ------------------------------------------------------------------------------- |
814 | 30 |
# Library Structures |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
31 |
# ------------------------------------------------------------------------------- |
814 | 32 |
|
33 |
BitmapLibrary = {} |
|
34 |
BitmapFolders = [] |
|
35 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
36 |
# ------------------------------------------------------------------------------- |
814 | 37 |
# Library Helpers |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
38 |
# ------------------------------------------------------------------------------- |
814 | 39 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1735
diff
changeset
|
40 |
|
814 | 41 |
def AddBitmapFolder(path): |
815
e4f24593a758
Adding support for extending internationalization to extensions
laurent
parents:
814
diff
changeset
|
42 |
if os.path.exists(path) and os.path.isdir(path) and path not in BitmapFolders: |
814 | 43 |
BitmapFolders.append(path) |
44 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1735
diff
changeset
|
45 |
|
814 | 46 |
def SearchBitmap(bmp_name): |
47 |
for folder in BitmapFolders: |
|
48 |
bmp_path = os.path.join(folder, bmp_name + ".png") |
|
49 |
if os.path.isfile(bmp_path): |
|
50 |
return wx.Bitmap(bmp_path) |
|
51 |
return None |
|
1735
c02818d7e29f
clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
52 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1735
diff
changeset
|
53 |
|
814 | 54 |
def GetBitmap(bmp_name1, bmp_name2=None, size=None): |
55 |
bmp = BitmapLibrary.get((bmp_name1, bmp_name2, size)) |
|
56 |
if bmp is not None: |
|
57 |
return bmp |
|
1735
c02818d7e29f
clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
58 |
|
814 | 59 |
if bmp_name2 is None: |
60 |
bmp = SearchBitmap(bmp_name1) |
|
61 |
else: |
|
62 |
# Bitmap with two icon |
|
63 |
bmp1 = SearchBitmap(bmp_name1) |
|
64 |
bmp2 = SearchBitmap(bmp_name2) |
|
1735
c02818d7e29f
clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
65 |
|
814 | 66 |
if bmp1 is not None and bmp2 is not None: |
67 |
# Calculate bitmap size |
|
68 |
width = bmp1.GetWidth() + bmp2.GetWidth() - 1 |
|
69 |
height = max(bmp1.GetHeight(), bmp2.GetHeight()) |
|
1735
c02818d7e29f
clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
70 |
|
814 | 71 |
# Create bitmap with both icons |
72 |
bmp = wx.EmptyBitmap(width, height) |
|
73 |
dc = wx.MemoryDC() |
|
74 |
dc.SelectObject(bmp) |
|
75 |
dc.Clear() |
|
76 |
dc.DrawBitmap(bmp1, 0, 0) |
|
77 |
dc.DrawBitmap(bmp2, bmp1.GetWidth() - 1, 0) |
|
78 |
dc.Destroy() |
|
1735
c02818d7e29f
clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
79 |
|
814 | 80 |
elif bmp1 is not None: |
81 |
bmp = bmp1 |
|
82 |
elif bmp2 is not None: |
|
83 |
bmp = bmp2 |
|
1735
c02818d7e29f
clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
84 |
|
814 | 85 |
if bmp is not None: |
86 |
BitmapLibrary[(bmp_name1, bmp_name2, size)] = bmp |
|
1735
c02818d7e29f
clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
87 |
|
814 | 88 |
return bmp |