Skip to content

Commit

Permalink
Refactored WxPython view structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Futsch1 committed Aug 20, 2023
1 parent 3e6fd1b commit 73f3ffb
Show file tree
Hide file tree
Showing 17 changed files with 607 additions and 553 deletions.
12 changes: 6 additions & 6 deletions asn1editor/ASN1SpecHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def get_types(self, ) -> List[str]:
"""
types = []
compiled = self.get_compiled('oer')
# TODO: Only include those types that are in the originally loaded file

for module_name, module in compiled.modules.items():
for type_name, compiled_type in module.items():
types.append(module_name + '.' + type_name)
Expand All @@ -98,10 +98,10 @@ def get_compiled(self, codec: str) -> asn1tools.compiler.Specification:
self.__compiled[codec] = asn1tools.compile_files(self.__file_names, codec)
return self.__compiled[codec]

def create_mvc_for_type(self, load_type: str, view_factory: AbstractViewFactory,
type_augmenter: typing.Optional[TypeAugmenter]) -> Tuple[AbstractView, Controller]:
def create_view_controller_for_type(self, load_type: str, view_factory: AbstractViewFactory,
type_augmenter: typing.Optional[TypeAugmenter]) -> Tuple[AbstractView, Controller]:
"""
Creates a model-view-controller for a given type name.
Creates a view and a controller for a given type name.
The type name must be a full type name, e.g. 'my_module.my_type', including the module name of the loaded ASN.1 spec.
If the type name is not found in the loaded ASN.1 spec, a ValueError is raised.
Expand All @@ -115,9 +115,9 @@ def create_mvc_for_type(self, load_type: str, view_factory: AbstractViewFactory,
for type_name, compiled_type in module.items():

if module_name + '.' + type_name == load_type:
mvc_factory = ViewControllerFactory(view_factory, type_augmenter)
vc_factory = ViewControllerFactory(view_factory, type_augmenter)
self._type_name = type_name
return mvc_factory.create(compiled_type)
return vc_factory.create(compiled_type)

raise ValueError(f'Requested type {load_type} not found in ASN.1 spec')

Expand Down
6 changes: 3 additions & 3 deletions asn1editor/wxPython/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from asn1editor.wxPython.SingleFileDropTarget import SingleFileDropTarget
from asn1editor.wxPython.TreeView import TreeView
from asn1editor.wxPython.ViewSelect import ViewType, TagInfo
from asn1editor.wxPython.WxPythonViews import WxPythonView
from asn1editor.wxPython.views.WxPythonView import WxPythonView


class MainWindow(wx.Frame, PluginInterface):
Expand All @@ -41,8 +41,8 @@ def __init__(self, plugins: typing.Optional[typing.List[Plugin]] = None, type_au
self._status_bar = self.CreateStatusBar()

self._menu_handler = MenuHandler(self, plugins, self.__about_box_content(title, plugins))

self._menu_handler.build(self.load_spec, self.load_data_from_file, self.save_data_to_file, self._structure_changed)

self.Bind(wx.EVT_CLOSE, self.close)

self.__restore_size()
Expand Down Expand Up @@ -158,7 +158,7 @@ def __load_spec(self, file_name):

self.Freeze()

self.__view, self.__controller = self.__asn1_handler.create_mvc_for_type(self.__type_name, view_factory, self._type_augmenter)
self.__view, self.__controller = self.__asn1_handler.create_view_controller_for_type(self.__type_name, view_factory, self._type_augmenter)
self.__tree_view = TreeView(self, self.__content_panel, self.__type_name, labels)

self.Thaw()
Expand Down
5 changes: 3 additions & 2 deletions asn1editor/wxPython/TreeView.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

from asn1editor.wxPython import Resources
from asn1editor.wxPython.Labels import Labels
from asn1editor.wxPython.WxPythonComplexViews import WxPythonContainerView, WxPythonChoiceView
from asn1editor.wxPython.WxPythonViews import WxPythonView
from asn1editor.wxPython.views.WxPythonChoiceView import WxPythonChoiceView
from asn1editor.wxPython.views.WxPythonContainerView import WxPythonContainerView
from asn1editor.wxPython.views.WxPythonView import WxPythonView


class TreeView:
Expand Down
183 changes: 0 additions & 183 deletions asn1editor/wxPython/WxPythonComplexViews.py

This file was deleted.

13 changes: 9 additions & 4 deletions asn1editor/wxPython/WxPythonViewFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@
from asn1editor.view.AbstractViewFactory import AbstractViewFactory, TypeInfo, Styles
from asn1editor.wxPython import Resources
from asn1editor.wxPython.Labels import Labels
from asn1editor.wxPython.WxPythonComplexViews import WxPythonContainerView, WxPythonListView, WxPythonChoiceView
from asn1editor.wxPython.WxPythonDateTimeViews import WxPythonDateView, WxPythonTimeView, WxPythonDateTimeView
from asn1editor.wxPython.WxPythonViews import WxPythonValueView, WxPythonBooleanView, \
WxPythonBitstringView, WxPythonHexStringView, WxPythonValueSelectionView, ControlList
from asn1editor.wxPython.views.WxPythonBitstringView import WxPythonBitstringView
from asn1editor.wxPython.views.WxPythonBooleanView import WxPythonBooleanView
from asn1editor.wxPython.views.WxPythonChoiceView import WxPythonChoiceView
from asn1editor.wxPython.views.WxPythonContainerView import WxPythonContainerView
from asn1editor.wxPython.views.WxPythonDateTimeViews import WxPythonDateView, WxPythonTimeView, WxPythonDateTimeView
from asn1editor.wxPython.views.WxPythonHexStringView import WxPythonHexStringView
from asn1editor.wxPython.views.WxPythonListView import WxPythonListView
from asn1editor.wxPython.views.WxPythonValueView import WxPythonValueView, WxPythonValueSelectionView
from asn1editor.wxPython.views.WxPythonView import ControlList


class WxPythonViewFactory(AbstractViewFactory):
Expand Down
Loading

0 comments on commit 73f3ffb

Please sign in to comment.