Skip to content

Commit

Permalink
Resources are now taken from correct path
Browse files Browse the repository at this point in the history
  • Loading branch information
Futsch1 committed Aug 3, 2020
1 parent 0c6483f commit 5d57245
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
9 changes: 5 additions & 4 deletions asn1editor/wxPython/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from asn1editor.PluginInterface import PluginInterface
from asn1editor.wxPython import WxPythonViewFactory
from asn1editor.wxPython.FilePickerHandler import FilePickerHandler
from asn1editor.wxPython.Resources import resource_path


class MainWindow(wx.Frame, PluginInterface):
Expand Down Expand Up @@ -55,23 +56,23 @@ def __create_menu(self):
file_menu = wx.Menu()
self.__load_spec_item: wx.MenuItem = file_menu.Append(wx.ID_ANY, 'Open ASN.1 specification')
# noinspection PyArgumentList
image: wx.svg.SVGimage = wx.svg.SVGimage.CreateFromFile('asn1editor/wxPython/icons/open.svg')
image: wx.svg.SVGimage = wx.svg.SVGimage.CreateFromFile(resource_path('icons/open.svg'))
self.__load_spec_item.SetBitmap(image.ConvertToBitmap(width=16, height=16))
file_menu.AppendSeparator()
self.__load_data_item: wx.MenuItem = file_menu.Append(wx.ID_OPEN, 'Load encoded data')
# noinspection PyArgumentList
image: wx.svg.SVGimage = wx.svg.SVGimage.CreateFromFile('asn1editor/wxPython/icons/load_encoded.svg')
image: wx.svg.SVGimage = wx.svg.SVGimage.CreateFromFile(resource_path('icons/load_encoded.svg'))
self.__load_data_item.SetBitmap(image.ConvertToBitmap(width=16, height=16))
self.__load_data_item.Enable(False)
self.__save_data_item: wx.MenuItem = file_menu.Append(wx.ID_SAVE, 'Save encoded data')
# noinspection PyArgumentList
image: wx.svg.SVGimage = wx.svg.SVGimage.CreateFromFile('asn1editor/wxPython/icons/save_encoded.svg')
image: wx.svg.SVGimage = wx.svg.SVGimage.CreateFromFile(resource_path('icons/save_encoded.svg'))
self.__save_data_item.SetBitmap(image.ConvertToBitmap(width=16, height=16))
self.__save_data_item.Enable(False)
file_menu.AppendSeparator()
self.__exit_item = file_menu.Append(wx.ID_EXIT, 'Exit', 'Exit application')
# noinspection PyArgumentList
image: wx.svg.SVGimage = wx.svg.SVGimage.CreateFromFile('asn1editor/wxPython/icons/exit.svg')
image: wx.svg.SVGimage = wx.svg.SVGimage.CreateFromFile(resource_path('icons/exit.svg'))
self.__exit_item.SetBitmap(image.ConvertToBitmap(width=16, height=16))
menu_bar.Append(file_menu, '&File')

Expand Down
7 changes: 7 additions & 0 deletions asn1editor/wxPython/Resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os


def resource_path(relative_path: str) -> str:
""" Get absolute path to resource required for PyInstaller """
base_path = os.environ.get("_MEIPASS2", os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)
3 changes: 2 additions & 1 deletion asn1editor/wxPython/WxPythonViewFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from asn1editor.interfaces.ValueInterface import ValueInterface
from asn1editor.view.AbstractView import AbstractView, ContainerView, ListView, ChoiceView
from asn1editor.view.AbstractViewFactory import AbstractViewFactory
from asn1editor.wxPython.Resources import resource_path
from asn1editor.wxPython.WxPythonViews import WxPythonValueView, WxPythonView, WxPythonContainerView, WxPythonListView, WxPythonBooleanView, \
WxPythonChoiceView, WxPythonBitstringView

Expand Down Expand Up @@ -188,7 +189,7 @@ def _add_name_control(self, sizer: wx.Sizer, name: str, optional: bool, suffix:

def _add_svg(self, sizer: wx.Sizer, bitmap_name: str):
# noinspection PyArgumentList
image: wx.svg.SVGimage = wx.svg.SVGimage.CreateFromFile(f'asn1editor/wxPython/icons/{bitmap_name}.svg')
image: wx.svg.SVGimage = wx.svg.SVGimage.CreateFromFile(resource_path(f'icons/{bitmap_name}.svg'))
bitmap = wx.StaticBitmap(self._window, bitmap=image.ConvertToBitmap(width=16, height=16))
bitmap.SetToolTip(bitmap_name.upper().replace('_', ' '))
sizer.Add(bitmap)

0 comments on commit 5d57245

Please sign in to comment.