Package Gnumed :: Package timelinelib :: Package wxgui :: Package frames :: Package mainframe :: Module controllerapi
[frames] | no frames]

Source Code for Module Gnumed.timelinelib.wxgui.frames.mainframe.controllerapi

  1  # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018  Rickard Lindberg, Roger Lindberg 
  2  # 
  3  # This file is part of Timeline. 
  4  # 
  5  # Timeline is free software: you can redistribute it and/or modify 
  6  # it under the terms of the GNU General Public License as published by 
  7  # the Free Software Foundation, either version 3 of the License, or 
  8  # (at your option) any later version. 
  9  # 
 10  # Timeline is distributed in the hope that it will be useful, 
 11  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13  # GNU General Public License for more details. 
 14  # 
 15  # You should have received a copy of the GNU General Public License 
 16  # along with Timeline.  If not, see <http://www.gnu.org/licenses/>. 
 17   
 18   
 19  import os.path 
 20   
 21  import wx 
 22   
 23  from timelinelib.meta.about import APPLICATION_NAME 
 24  import timelinelib.wxgui.frames.mainframe.guicreator as guic 
 25   
 26   
27 -class MainFrameApiUsedByController(object):
28
29 - def set_timeline_readonly(self):
30 self._set_readonly_text_in_status_bar() 31 self.enable_disable_menus()
32
34 self._clear_recent_menu_items() 35 self._create_recent_menu_items()
36
37 - def display_timeline(self, timeline):
38 self.timeline = timeline 39 self.menu_controller.on_timeline_change(timeline) 40 self.main_panel.display_timeline(timeline) 41 self._set_title() 42 self._set_readonly_text_in_status_bar()
43
45 self._clear_navigation_menu_items() 46 if self.timeline: 47 self._create_navigation_menu_items() 48 self.shortcut_controller.add_navigation_functions()
49 50 # Also used by TinmelineView
51 - def enable_disable_menus(self):
52 self.menu_controller.enable_disable_menus(self.main_panel.timeline_panel_visible()) 53 self._enable_disable_one_selected_event_menus() 54 self._enable_disable_measure_distance_between_two_events_menu() 55 self._enable_disable_searchbar() 56 self._enable_disable_undo()
57
58 - def _set_title(self):
59 if self.timeline is None: 60 self.SetTitle(APPLICATION_NAME) 61 else: 62 self.SetTitle("%s (%s) - %s" % ( 63 os.path.basename(self.timeline.path), 64 os.path.dirname(os.path.abspath(self.timeline.path)), 65 APPLICATION_NAME))
66
68 if self.controller.timeline_is_readonly(): 69 text = _("read-only") 70 else: 71 text = "" 72 self.status_bar_adapter.set_read_only_text(text)
73
75 while self._navigation_menu_items: 76 item = self._navigation_menu_items.pop() 77 if item in self._navigate_menu.MenuItems: 78 self._navigate_menu.Remove(item) 79 self._navigation_functions_by_menu_item_id.clear()
80
82 item_data = self.timeline.get_time_type().get_navigation_functions() 83 pos = 0 84 id_offset = self.get_navigation_id_offset() 85 for (itemstr, fn) in item_data: 86 if itemstr == "SEP": 87 item = self._navigate_menu.InsertSeparator(pos) 88 else: 89 wxid = guic.ID_NAVIGATE + id_offset 90 item = self._navigate_menu.Insert(pos, wxid, itemstr) 91 self._navigation_functions_by_menu_item_id[item.GetId()] = fn 92 self.Bind(wx.EVT_MENU, self._navigation_menu_item_on_click, item) 93 self.shortcut_items[wxid] = item 94 id_offset += 1 95 self._navigation_menu_items.append(item) 96 pos += 1
97
98 - def get_navigation_id_offset(self):
99 id_offset = 0 100 if self.timeline.get_time_type().get_name() == "numtime": 101 id_offset = 100 102 return id_offset
103
104 - def _navigation_menu_item_on_click(self, evt):
105 self.save_time_period() 106 fn = self._navigation_functions_by_menu_item_id[evt.GetId()] 107 time_period = self.main_panel.get_time_period() 108 fn(self, time_period, self.main_panel.Navigate)
109
110 - def _clear_recent_menu_items(self):
111 for item in self.mnu_file_open_recent_submenu.GetMenuItems(): 112 self.mnu_file_open_recent_submenu.Delete(item)
113
115 self.open_recent_map = {} 116 for path in self.config.get_recently_opened(): 117 self._map_path_to_recent_menu_item(path)
118
119 - def _map_path_to_recent_menu_item(self, path):
120 name = "%s (%s)" % ( 121 os.path.basename(path), 122 os.path.dirname(os.path.abspath(path))) 123 item = self.mnu_file_open_recent_submenu.Append(wx.ID_ANY, name) 124 self.open_recent_map[item.GetId()] = path 125 self.Bind(wx.EVT_MENU, self._mnu_file_open_recent_item_on_click, item)
126
127 - def _mnu_file_open_recent_item_on_click(self, event):
128 path = self.open_recent_map[event.GetId()] 129 self.controller.open_timeline_if_exists(path)
130
132 nbr_of_selected_events = self.main_panel.get_nbr_of_selected_events() 133 one_event_selected = nbr_of_selected_events == 1 134 some_event_selected = nbr_of_selected_events > 0 135 mnu_edit_event = self. _timeline_menu.FindItemById(guic.ID_EDIT_EVENT) 136 mnu_duplicate_event = self. _timeline_menu.FindItemById(guic.ID_DUPLICATE_EVENT) 137 mnu_set_category = self. _timeline_menu.FindItemById(guic.ID_SET_CATEGORY_ON_SELECTED) 138 mnu_edit_event.Enable(one_event_selected) 139 mnu_duplicate_event.Enable(one_event_selected) 140 mnu_set_category.Enable(some_event_selected) 141 self._timeline_menu.FindItemById(guic.ID_MOVE_EVENT_UP).Enable(one_event_selected) 142 self._timeline_menu.FindItemById(guic.ID_MOVE_EVENT_DOWN).Enable(one_event_selected)
143
145 two_events_selected = self.main_panel.get_nbr_of_selected_events() == 2 146 mnu_measure_distance = self._timeline_menu.FindItemById(guic.ID_MEASURE_DISTANCE) 147 mnu_measure_distance.Enable(two_events_selected)
148
150 if self.timeline is None: 151 self.main_panel.show_searchbar(False)
152
153 - def _enable_disable_undo(self):
154 mnu_undo = self._timeline_menu.FindItemById(guic.ID_UNDO) 155 mnu_redo = self._timeline_menu.FindItemById(guic.ID_REDO) 156 if self.timeline is not None: 157 mnu_undo.Enable(self.timeline.undo_enabled()) 158 mnu_redo.Enable(self.timeline.redo_enabled()) 159 else: 160 mnu_undo.Enable(False) 161 mnu_redo.Enable(False)
162