Source code for timelinelib.wxgui.frames.mainframe.menus.timelinemenu

# Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018  Rickard Lindberg, Roger Lindberg
#
# This file is part of Timeline.
#
# Timeline is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Timeline is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Timeline.  If not, see <http://www.gnu.org/licenses/>.

import wx
import timelinelib.wxgui.frames.mainframe.menus as mid
from timelinelib.wxgui.frames.mainframe.menus.menubase import MenuBase
from timelinelib.wxgui.dialogs.editevent.view import open_create_event_editor
from timelinelib.wxgui.dialogs.milestone.view import open_milestone_editor_for
from timelinelib.db.utils import safe_locking
from timelinelib.wxgui.dialogs.eventduration.view import open_measure_duration_dialog
from timelinelib.wxgui.dialogs.eraseditor.view import oped_edit_eras_dialog
from timelinelib.wxgui.dialogs.duplicateevent.view import open_duplicate_event_dialog_for_event
from timelinelib.wxgui.dialogs.setcategory.view import open_set_category_dialog_for_selected_events
from timelinelib.wxgui.dialogs.setcategory.view import open_set_category_dialog


SHORTCUTS = list()
REQUIRING_TIMELINE = (mid.ID_MEASURE_DURATION,)
REQUIRING_WRITEABLE_TIMELINE = (mid.ID_CREATE_EVENT, mid.ID_EDIT_EVENT, mid.ID_CREATE_MILESTONE, mid.ID_DUPLICATE_EVENT,
                                mid.ID_SET_CATEGORY_ON_SELECTED, mid.ID_MOVE_EVENT_UP, mid.ID_MOVE_EVENT_DOWN,
                                mid.ID_MEASURE_DISTANCE, mid.ID_SET_CATEGORY_ON_WITHOUT,
                                mid.ID_SET_READONLY, mid.ID_EDIT_ERAS, mid.ID_COMPRESS, mid.ID_UNDO, mid.ID_REDO)


[docs]class TimelineMenu(MenuBase): """The Timeline menu (a wx.Menu)."""
[docs] def __init__(self, main_frame, timeline_panel): event_handlers = { mid.ID_CREATE_EVENT: lambda evt: open_create_event_editor(main_frame.controller, main_frame, main_frame.config, main_frame.timeline), mid.ID_EDIT_EVENT: lambda evt: main_frame.main_panel.open_event_editor(), mid.ID_DUPLICATE_EVENT: lambda evt: open_duplicate_event_dialog_for_event(main_frame), mid.ID_SET_CATEGORY_ON_SELECTED: lambda evt: safe_locking(main_frame.controller, lambda: open_set_category_dialog_for_selected_events(main_frame)), mid.ID_MOVE_EVENT_UP: lambda evt: timeline_panel.move_selected_event_up(), mid.ID_MOVE_EVENT_DOWN: lambda evt: timeline_panel.move_selected_event_down(), mid.ID_CREATE_MILESTONE: lambda evt: open_milestone_editor_for(main_frame, main_frame, main_frame.config, main_frame.timeline), mid.ID_COMPRESS: lambda evt: safe_locking(main_frame.controller, main_frame.timeline.compress), mid.ID_MEASURE_DISTANCE: lambda evt: main_frame.controller.measure_distance_between_two_events(), mid.ID_MEASURE_DURATION: lambda evt: open_measure_duration_dialog(main_frame), mid.ID_SET_CATEGORY_ON_WITHOUT: lambda evt: safe_locking(main_frame.controller, lambda: open_set_category_dialog(main_frame)), mid.ID_EDIT_ERAS: lambda evt: safe_locking(main_frame.controller, lambda: oped_edit_eras_dialog(main_frame)), mid.ID_SET_READONLY: lambda evt: main_frame.controller.set_timeline_in_readonly_mode(), mid.ID_UNDO: lambda evt: safe_locking(main_frame.controller, main_frame.timeline.undo), mid.ID_REDO: lambda evt: safe_locking(main_frame.controller, main_frame.timeline.redo), } MenuBase.__init__(self, main_frame, event_handlers, SHORTCUTS, REQUIRING_TIMELINE, requiring_writeable_timeline=REQUIRING_WRITEABLE_TIMELINE) self._create_menu() self._bind_event_handlers() self._register_shortcuts() self._register_menus_requiring_timeline()
def _create_menu(self): self.Append(mid.ID_CREATE_EVENT, _("Create &Event...")) self.Append(mid.ID_EDIT_EVENT, _("&Edit Selected Event...")) self.Append(mid.ID_DUPLICATE_EVENT, _("&Duplicate Selected Event...")) self.Append(mid.ID_SET_CATEGORY_ON_SELECTED, _("Set Category on Selected Events...")) self.Append(mid.ID_MOVE_EVENT_UP, _("Move event up") + "\tAlt+Up") self.Append(mid.ID_MOVE_EVENT_DOWN, _("Move event down") + "\tAlt+Down") self.AppendSeparator() self.Append(mid.ID_CREATE_MILESTONE, _("Create &Milestone...")) self.AppendSeparator() self.Append(mid.ID_COMPRESS, _("&Compress timeline Events")) self.AppendSeparator() self.Append(mid.ID_MEASURE_DISTANCE, _("&Measure Distance between two Events...")) self.Append(mid.ID_MEASURE_DURATION, _("Measure Duration of Events...")) self.AppendSeparator() self.Append(mid.ID_SET_CATEGORY_ON_WITHOUT, _("Set Category on events &without category...")) self.AppendSeparator() self.Append(mid.ID_EDIT_ERAS, _("Edit Era's...")) self.AppendSeparator() self.Append(mid.ID_SET_READONLY, _("&Read Only")) self.AppendSeparator() self.Append(mid.ID_UNDO, _("&Undo") + "\tCtrl+Z") self.Append(mid.ID_REDO, _("&Redo") + "\tAlt+Z")