Commit a3bd2801bd69be25c5e8c02e71f45fa6f3f44df3
1 parent
1069a8c1
Exists in
wx2.9_mac
create our own art provider to simplify the toolbar icons
Showing
1 changed file
with
83 additions
and
113 deletions
Show diff stats
invesalius/gui/frame.py
| ... | ... | @@ -46,6 +46,48 @@ VIEW_TOOLS = [ID_LAYOUT, ID_TEXT] =\ |
| 46 | 46 | [wx.NewId() for number in range(2)] |
| 47 | 47 | |
| 48 | 48 | |
| 49 | +def scale_bitmap(bitmap, width, height): | |
| 50 | + image = wx.ImageFromBitmap(bitmap) | |
| 51 | + image = image.Scale(width, height, wx.IMAGE_QUALITY_HIGH) | |
| 52 | + result = wx.BitmapFromImage(image) | |
| 53 | + return result | |
| 54 | + | |
| 55 | +d = const.ICON_DIR | |
| 56 | +ARTID_FNAME = {'tool_rotate': os.path.join(d, "tool_rotate_original.png"), | |
| 57 | + 'tool_translate': os.path.join(d, "tool_translate_original.png"), | |
| 58 | + 'tool_zoom': os.path.join(d, "tool_zoom_original.png"), | |
| 59 | + 'tool_zoom_select': os.path.join(d, "tool_zoom_select_original.png"), | |
| 60 | + 'tool_contraste' :os.path.join(d, "tool_contrast_original.png"), | |
| 61 | + 'measure_linear': os.path.join(d, "measure_line_original.png"), | |
| 62 | + 'measure_angle': os.path.join(d, "measure_angle_original.png"), | |
| 63 | + | |
| 64 | + 'slice': os.path.join(d, "slice_original.png"), | |
| 65 | + 'cross': os.path.join(d, "cross_original.png"), | |
| 66 | + | |
| 67 | + 'file_from_internet': os.path.join(d,"file_from_internet_original.png"), | |
| 68 | + 'file_import': os.path.join(d, "file_import_original.png"), | |
| 69 | + 'file_open': os.path.join(d, "file_open_original.png"), | |
| 70 | + 'file_save': os.path.join(d, "file_save_original.png"), | |
| 71 | + 'print': os.path.join(d, "print_original.png"), | |
| 72 | + 'tool_photo': os.path.join(d, "tool_photo_original.png"), | |
| 73 | + | |
| 74 | + 'layout_data_only': os.path.join(d, "layout_data_only_original.png"), | |
| 75 | + 'layout_full': os.path.join(d, "layout_full_original.png"), | |
| 76 | + 'text_inverted': os.path.join(d, "text_inverted_original.png"), | |
| 77 | + 'text': os.path.join(d, "text_original.png"), | |
| 78 | + } | |
| 79 | + | |
| 80 | + | |
| 81 | +class MyArtProvider(wx.ArtProvider): | |
| 82 | + def __init__(self): | |
| 83 | + wx.ArtProvider.__init__(self) | |
| 84 | + | |
| 85 | + def CreateBitmap(self, artid, client, size): | |
| 86 | + path = ARTID_FNAME[artid] | |
| 87 | + tmp_bmp = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 88 | + #bmp = scale_bitmap(tmp_bmp, size.width, size.height) | |
| 89 | + return tmp_bmp | |
| 90 | + | |
| 49 | 91 | |
| 50 | 92 | class MessageWatershed(wx.PopupWindow): |
| 51 | 93 | def __init__(self, prnt, msg): |
| ... | ... | @@ -862,42 +904,21 @@ class ProjectToolBar(wx.ToolBar): |
| 862 | 904 | """ |
| 863 | 905 | # Load bitmaps |
| 864 | 906 | d = const.ICON_DIR |
| 907 | + client = "wx.ART_TOOLBAR" | |
| 908 | + wx.ArtProvider.Push(MyArtProvider()) | |
| 865 | 909 | if sys.platform == 'darwin' and wx.VERSION < (2, 9): |
| 866 | - path = os.path.join(d,"file_from_internet_original.png") | |
| 867 | - BMP_NET = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 868 | - | |
| 869 | - path = os.path.join(d, "file_import_original.png") | |
| 870 | - BMP_IMPORT = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 871 | - | |
| 872 | - path = os.path.join(d, "file_open_original.png") | |
| 873 | - BMP_OPEN = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 874 | - | |
| 875 | - path = os.path.join(d, "file_save_original.png") | |
| 876 | - BMP_SAVE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 877 | - | |
| 878 | - path = os.path.join(d, "print_original.png") | |
| 879 | - BMP_PRINT = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 880 | - | |
| 881 | - path = os.path.join(d, "tool_photo_original.png") | |
| 882 | - BMP_PHOTO = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 910 | + size = 48, 48 | |
| 883 | 911 | else: |
| 884 | - path = os.path.join(d, "file_from_internet.png") | |
| 885 | - BMP_NET = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 886 | - | |
| 887 | - path = os.path.join(d, "file_import.png") | |
| 888 | - BMP_IMPORT = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 889 | - | |
| 890 | - path = os.path.join(d, "file_open.png") | |
| 891 | - BMP_OPEN = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 892 | - | |
| 893 | - path = os.path.join(d, "file_save.png") | |
| 894 | - BMP_SAVE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 912 | + size = 32, 32 | |
| 895 | 913 | |
| 896 | - path = os.path.join(d, "print.png") | |
| 897 | - BMP_PRINT = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 914 | + BMP_NET = wx.ArtProvider.GetBitmap('file_from_internet', client, size) | |
| 915 | + BMP_IMPORT = wx.ArtProvider.GetBitmap('file_import', client, size) | |
| 916 | + BMP_OPEN = wx.ArtProvider.GetBitmap('file_open', client, size) | |
| 917 | + BMP_SAVE = wx.ArtProvider.GetBitmap('file_save', client, size) | |
| 918 | + BMP_PRINT = wx.ArtProvider.GetBitmap('print', client, size) | |
| 919 | + BMP_PHOTO = wx.ArtProvider.GetBitmap('tool_photo', client, size) | |
| 898 | 920 | |
| 899 | - path = os.path.join(d, "tool_photo.png") | |
| 900 | - BMP_PHOTO = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 921 | + wx.ArtProvider.Pop() | |
| 901 | 922 | |
| 902 | 923 | # Create tool items based on bitmaps |
| 903 | 924 | self.AddLabelTool(const.ID_DICOM_IMPORT, |
| ... | ... | @@ -1002,55 +1023,22 @@ class ObjectToolBar(wx.ToolBar): |
| 1002 | 1023 | Add tools into toolbar. |
| 1003 | 1024 | """ |
| 1004 | 1025 | d = const.ICON_DIR |
| 1026 | + client = "wx.ART_TOOLBAR" | |
| 1027 | + wx.ArtProvider.Push(MyArtProvider()) | |
| 1005 | 1028 | if sys.platform == 'darwin' and wx.VERSION < (2, 9): |
| 1006 | - path = os.path.join(d, "tool_rotate_original.png") | |
| 1007 | - BMP_ROTATE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1008 | - | |
| 1009 | - path = os.path.join(d, "tool_translate_original.png") | |
| 1010 | - BMP_MOVE =wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1011 | - | |
| 1012 | - path = os.path.join(d, "tool_zoom_original.png") | |
| 1013 | - BMP_ZOOM = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1014 | - | |
| 1015 | - path = os.path.join(d, "tool_zoom_select_original.png") | |
| 1016 | - BMP_ZOOM_SELECT = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1017 | - | |
| 1018 | - path = os.path.join(d, "tool_contrast_original.png") | |
| 1019 | - BMP_CONTRAST = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1020 | - | |
| 1021 | - path = os.path.join(d, "measure_line_original.png") | |
| 1022 | - BMP_DISTANCE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1023 | - | |
| 1024 | - path = os.path.join(d, "measure_angle_original.png") | |
| 1025 | - BMP_ANGLE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1026 | - | |
| 1027 | - #path = os.path.join(d, "tool_annotation_original.png") | |
| 1028 | - #BMP_ANNOTATE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1029 | - | |
| 1029 | + size = 48, 48 | |
| 1030 | 1030 | else: |
| 1031 | - path = os.path.join(d, "tool_rotate.png") | |
| 1032 | - BMP_ROTATE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1031 | + size = 32, 32 | |
| 1033 | 1032 | |
| 1034 | - path = os.path.join(d, "tool_translate.png") | |
| 1035 | - BMP_MOVE =wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1033 | + BMP_ROTATE = wx.ArtProvider.GetBitmap('tool_rotate', client, size) | |
| 1034 | + BMP_MOVE = wx.ArtProvider.GetBitmap('tool_translate', client, size) | |
| 1035 | + BMP_ZOOM = wx.ArtProvider.GetBitmap('tool_zoom', client, size) | |
| 1036 | + BMP_ZOOM_SELECT = wx.ArtProvider.GetBitmap('tool_zoom_select', client, size) | |
| 1037 | + BMP_CONTRAST = wx.ArtProvider.GetBitmap('tool_contraste', client, size) | |
| 1038 | + BMP_DISTANCE = wx.ArtProvider.GetBitmap('measure_linear', client, size) | |
| 1039 | + BMP_ANGLE = wx.ArtProvider.GetBitmap('measure_angle', client, size) | |
| 1036 | 1040 | |
| 1037 | - path = os.path.join(d, "tool_zoom.png") | |
| 1038 | - BMP_ZOOM = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1039 | - | |
| 1040 | - path = os.path.join(d, "tool_zoom_select.png") | |
| 1041 | - BMP_ZOOM_SELECT = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1042 | - | |
| 1043 | - path = os.path.join(d, "tool_contrast.png") | |
| 1044 | - BMP_CONTRAST = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1045 | - | |
| 1046 | - path = os.path.join(d, "measure_line.png") | |
| 1047 | - BMP_DISTANCE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1048 | - | |
| 1049 | - path = os.path.join(d, "measure_angle.png") | |
| 1050 | - BMP_ANGLE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1051 | - | |
| 1052 | - #path = os.path.join(d, "tool_annotation.png") | |
| 1053 | - #BMP_ANNOTATE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1041 | + wx.ArtProvider.Pop() | |
| 1054 | 1042 | |
| 1055 | 1043 | # Create tool items based on bitmaps |
| 1056 | 1044 | self.AddLabelTool(const.STATE_ZOOM, |
| ... | ... | @@ -1212,19 +1200,18 @@ class SliceToolBar(wx.ToolBar): |
| 1212 | 1200 | """ |
| 1213 | 1201 | Add tools into toolbar. |
| 1214 | 1202 | """ |
| 1215 | - d = const.ICON_DIR | |
| 1216 | - if sys.platform == 'darwin' and wx.VERSION < (2, 9): | |
| 1217 | - path = os.path.join(d, "slice_original.png") | |
| 1218 | - BMP_SLICE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1203 | + client = "wx.ART_TOOLBAR" | |
| 1204 | + wx.ArtProvider.Push(MyArtProvider()) | |
| 1219 | 1205 | |
| 1220 | - path = os.path.join(d,"cross_original.png") | |
| 1221 | - BMP_CROSS = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1206 | + if sys.platform == 'darwin' and wx.VERSION < (2, 9): | |
| 1207 | + size = 48, 48 | |
| 1222 | 1208 | else: |
| 1223 | - path = os.path.join(d, "slice.png") | |
| 1224 | - BMP_SLICE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1209 | + size = 32, 32 | |
| 1210 | + | |
| 1211 | + BMP_SLICE = wx.ArtProvider.GetBitmap('slice', client, size) | |
| 1212 | + BMP_CROSS = wx.ArtProvider.GetBitmap('cross', client, size) | |
| 1225 | 1213 | |
| 1226 | - path = os.path.join(d,"cross.png") | |
| 1227 | - BMP_CROSS = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) | |
| 1214 | + wx.ArtProvider.Pop() | |
| 1228 | 1215 | |
| 1229 | 1216 | self.AddCheckTool(const.SLICE_STATE_SCROLL, |
| 1230 | 1217 | BMP_SLICE, |
| ... | ... | @@ -1356,36 +1343,19 @@ class LayoutToolBar(wx.ToolBar): |
| 1356 | 1343 | Add tools into toolbar. |
| 1357 | 1344 | """ |
| 1358 | 1345 | d = const.ICON_DIR |
| 1346 | + client = "wx.ART_TOOLBAR" | |
| 1347 | + wx.ArtProvider.Push(MyArtProvider()) | |
| 1359 | 1348 | if sys.platform == 'darwin' and wx.VERSION < (2, 9): |
| 1360 | - # Bitmaps for show/hide task panel item | |
| 1361 | - p = os.path.join(d, "layout_data_only_original.gif") | |
| 1362 | - self.BMP_WITH_MENU = wx.Bitmap(p, wx.BITMAP_TYPE_GIF) | |
| 1363 | - | |
| 1364 | - p = os.path.join(d, "layout_full_original.gif") | |
| 1365 | - self.BMP_WITHOUT_MENU = wx.Bitmap(p, wx.BITMAP_TYPE_GIF) | |
| 1366 | - | |
| 1367 | - # Bitmaps for show/hide task item | |
| 1368 | - p = os.path.join(d, "text_inverted_original.png") | |
| 1369 | - self.BMP_WITHOUT_TEXT = wx.Bitmap(p, wx.BITMAP_TYPE_PNG) | |
| 1370 | - | |
| 1371 | - p = os.path.join(d, "text_original.png") | |
| 1372 | - self.BMP_WITH_TEXT = wx.Bitmap(p, wx.BITMAP_TYPE_PNG) | |
| 1373 | - | |
| 1349 | + size = 48, 48 | |
| 1374 | 1350 | else: |
| 1375 | - # Bitmaps for show/hide task panel item | |
| 1376 | - p = os.path.join(d, "layout_data_only.gif") | |
| 1377 | - self.BMP_WITH_MENU = wx.Bitmap(p, wx.BITMAP_TYPE_GIF) | |
| 1378 | - | |
| 1379 | - p = os.path.join(d, "layout_full.gif") | |
| 1380 | - self.BMP_WITHOUT_MENU = wx.Bitmap(p, wx.BITMAP_TYPE_GIF) | |
| 1381 | - | |
| 1382 | - # Bitmaps for show/hide task item | |
| 1383 | - p = os.path.join(d, "text_inverted.png") | |
| 1384 | - self.BMP_WITHOUT_TEXT = wx.Bitmap(p, wx.BITMAP_TYPE_PNG) | |
| 1351 | + size = 32, 32 | |
| 1385 | 1352 | |
| 1386 | - p = os.path.join(d, "text.png") | |
| 1387 | - self.BMP_WITH_TEXT = wx.Bitmap(p, wx.BITMAP_TYPE_PNG) | |
| 1353 | + self.BMP_WITHOUT_MENU = wx.ArtProvider.GetBitmap('layout_data_only', client, size) | |
| 1354 | + self.BMP_WITH_MENU = wx.ArtProvider.GetBitmap('layout_full', client, size) | |
| 1355 | + self.BMP_WITH_TEXT = wx.ArtProvider.GetBitmap('text_inverted', client, size) | |
| 1356 | + self.BMP_WITHOUT_TEXT = wx.ArtProvider.GetBitmap('text', client, size) | |
| 1388 | 1357 | |
| 1358 | + wx.ArtProvider.Pop() | |
| 1389 | 1359 | self.AddLabelTool(ID_LAYOUT, |
| 1390 | 1360 | "", |
| 1391 | 1361 | bitmap=self.BMP_WITHOUT_MENU, | ... | ... |