1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#------------------------------------------------------------------------------
# Copyright (c) 2013-2025, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
from __future__ import print_function
import pickle
from atom.api import Str
from enaml.widgets.api import Container
from enaml.workbench.ui.api import Workspace
import enaml
with enaml.imports():
from persistent_view import PersistentManifest, create_new_area
print('Imported Persistent Workspace!')
#: Storage for the pickled dock area. This would be saved
#: to some persistent storage media in a real application.
PICKLED_DOCK_AREA = None
class PersistentWorkspace(Workspace):
""" A custom Workspace class for the crash course example.
"""
#: Storage for the plugin manifest's id.
_manifest_id = Str()
def start(self):
""" Start the workspace instance.
This method will create the container content and register the
provided plugin with the workbench.
"""
self.content = Container(padding=0)
self.load_area()
manifest = PersistentManifest()
self._manifest_id = manifest.id
self.workbench.register(manifest)
def stop(self):
""" Stop the workspace instance.
This method will unregister the workspace's plugin that was
registered on start.
"""
self.save_area()
self.workbench.unregister(self._manifest_id)
def save_area(self):
""" Save the dock area for the workspace.
"""
global PICKLED_DOCK_AREA
area = self.content.find('the_dock_area')
PICKLED_DOCK_AREA = pickle.dumps(area, -1)
def load_area(self):
""" Load the dock area into the workspace content.
"""
if PICKLED_DOCK_AREA is not None:
area = pickle.loads(PICKLED_DOCK_AREA)
else:
area = create_new_area()
area.set_parent(self.content)
|