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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
|
"""Incremental demo for wx support of tasks.
Multiple tasks
Note that naively subclassing SecondTask from ExampleTask, it initially used
the same menu_bar and tool_bars traits from ExampleTask. This caused the
incorrect tying of the controls to SecondTask because the class attributes
were shared between both classes.
"""
from pyface.action.schema.api import SMenu, SMenuBar, SToolBar
from pyface.api import (
GUI,
ConfirmationDialog,
FileDialog,
ImageResource,
YES,
OK,
CANCEL,
)
from pyface.tasks.api import (
Task,
TaskWindow,
TaskLayout,
PaneItem,
IEditor,
IEditorAreaPane,
EditorAreaPane,
Editor,
DockPane,
HSplitter,
VSplitter,
)
from pyface.tasks.action.api import (
DockPaneToggleGroup,
TaskAction,
TaskToggleGroup,
)
from traits.api import Property, Instance
class Pane1(DockPane):
# TaskPane interface ---------------------------------------------------
id = "steps.pane1"
name = "Pane 1"
class Pane2(DockPane):
# TaskPane interface ---------------------------------------------------
id = "steps.pane2"
name = "Pane 2"
class Pane3(DockPane):
# TaskPane interface ---------------------------------------------------
id = "steps.pane3"
name = "Pane 3"
class Pane4(DockPane):
# TaskPane interface ---------------------------------------------------
id = "steps.pane4"
name = "Pane 4"
class Pane5(DockPane):
# TaskPane interface ---------------------------------------------------
id = "steps.pane5"
name = "Pane 5"
class Pane6(DockPane):
# TaskPane interface ---------------------------------------------------
id = "steps.pane6"
name = "Pane 6"
class Pane7(DockPane):
# TaskPane interface ---------------------------------------------------
id = "steps.pane7"
name = "Pane 7"
class ExampleTask(Task):
""" A simple task for opening a blank editor.
"""
# Task interface -------------------------------------------------------
id = "example.example_task"
name = "Multi-Tab Editor"
active_editor = Property(
Instance(IEditor), observe="editor_area.active_editor"
)
editor_area = Instance(IEditorAreaPane)
menu_bar = SMenuBar(
SMenu(
TaskAction(name="New", method="new", accelerator="Ctrl+N"),
id="File",
name="&File",
),
SMenu(
DockPaneToggleGroup(), TaskToggleGroup(), id="View", name="&View"
),
)
tool_bars = [
SToolBar(
TaskAction(
method="new",
tooltip="New file",
image=ImageResource("document_new"),
),
image_size=(32, 32),
)
]
# ------------------------------------------------------------------------
# 'Task' interface.
# ------------------------------------------------------------------------
def _default_layout_default(self):
return TaskLayout(
top=HSplitter(
PaneItem("steps.pane1"),
PaneItem("steps.pane2"),
PaneItem("steps.pane3"),
)
)
def create_central_pane(self):
""" Create the central pane: the script editor.
"""
self.editor_area = EditorAreaPane()
return self.editor_area
def create_dock_panes(self):
""" Create the file browser and connect to its double click event.
"""
return [Pane1(), Pane2(), Pane3()]
# ------------------------------------------------------------------------
# 'ExampleTask' interface.
# ------------------------------------------------------------------------
def new(self):
""" Opens a new empty window
"""
editor = Editor()
self.editor_area.add_editor(editor)
self.editor_area.activate_editor(editor)
self.activated()
# Trait property getter/setters ----------------------------------------
def _get_active_editor(self):
if self.editor_area is not None:
return self.editor_area.active_editor
return None
class SecondTask(ExampleTask):
""" A simple task for opening a blank editor.
"""
# Task interface -------------------------------------------------------
id = "example.second_task"
name = "Second Multi-Tab Editor"
menu_bar = SMenuBar(
SMenu(
TaskAction(name="New", method="new", accelerator="Ctrl+N"),
id="File",
name="&File",
),
SMenu(
DockPaneToggleGroup(), TaskToggleGroup(), id="View", name="&View"
),
)
tool_bars = [
SToolBar(
TaskAction(
method="new",
tooltip="New file",
image=ImageResource("document_new"),
),
image_size=(32, 32),
)
]
# ------------------------------------------------------------------------
# 'Task' interface.
# ------------------------------------------------------------------------
def _default_layout_default(self):
return TaskLayout(
left=VSplitter(
PaneItem("steps.pane1"),
PaneItem("steps.pane2"),
PaneItem("steps.pane3"),
)
)
def main(argv):
""" A simple example of using Tasks.
"""
# Create the GUI (this does NOT start the GUI event loop).
gui = GUI()
# Create a Task and add it to a TaskWindow.
task1 = ExampleTask()
task2 = SecondTask()
window = TaskWindow(size=(800, 600))
window.add_task(task1)
window.add_task(task2)
# Show the window.
window.open()
# Start the GUI event loop.
gui.start_event_loop()
if __name__ == "__main__":
import sys
main(sys.argv)
|