Package Gnumed :: Package timelinelib :: Package wxgui :: Package components :: Module mainpanel
[frames] | no frames]

Source Code for Module Gnumed.timelinelib.wxgui.components.mainpanel

  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 wx 
 20   
 21  from timelinelib.canvas.data import TimePeriod 
 22  from timelinelib.wxgui.components.welcomepanel import WelcomePanel 
 23  from timelinelib.wxgui.components.timelinepanel import TimelinePanel 
 24  from timelinelib.wxgui.components.searchbar.view import SearchBar 
 25  from timelinelib.wxgui.components.propertyeditors.iconeditor import FileToBitmapConverter 
 26   
 27   
28 -class FileDropTarget(wx.FileDropTarget):
29
30 - def __init__(self, obj):
31 wx.FileDropTarget.__init__(self) 32 self.obj = obj
33
34 - def OnDropFiles(self, x, y, filenames):
35 try: 36 bitmap = FileToBitmapConverter().convert(filenames[0]) 37 self.obj.controller.event_at(x, y).set_icon(bitmap) 38 except: 39 pass
40
41 - def OnDragOver(self, x, y, defResult):
42 if self.obj.controller.event_at(x, y): 43 return defResult 44 else: 45 return wx.DragNone
46 47 48
49 -class MainPanel(wx.Panel):
50 """ 51 Panel that covers the whole client area of MainFrame. 52 53 Displays one of the following panels: 54 55 * The welcome panel (show_welcome_panel) 56 * The timeline panel (show_timeline_panel) 57 58 Also displays the search bar. 59 """ 60
61 - def __init__(self, parent, config, main_frame):
62 wx.Panel.__init__(self, parent) 63 self.config = config 64 self.main_frame = main_frame 65 self._create_gui() 66 # Install variables for backwards compatibility 67 self.category_tree = self.timeline_panel.sidebar.category_tree 68 self.show_sidebar = self.timeline_panel.show_sidebar 69 self.hide_sidebar = self.timeline_panel.hide_sidebar 70 self.get_sidebar_width = self.timeline_panel.get_sidebar_width
71
72 - def get_export_periods(self, first_time, last_time):
73 periods = [] 74 current_period = None 75 if self.main_frame.timeline: 76 time_type = self.main_frame.timeline.get_time_type() 77 current_period = self.get_view_properties().displayed_period 78 period_delta = current_period.end_time - current_period.start_time 79 periods.append(current_period) 80 start_time = current_period.start_time 81 period = current_period 82 while first_time < start_time: 83 start_time = period.start_time - period_delta 84 end_time = period.start_time 85 period = TimePeriod(start_time, end_time) 86 periods.insert(0, period) 87 end_time = current_period.end_time 88 period = current_period 89 while last_time > end_time: 90 start_time = period.end_time 91 end_time = period.end_time + period_delta 92 period = TimePeriod(start_time, end_time) 93 periods.append(period) 94 return periods, current_period
95
96 - def timeline_panel_visible(self):
97 return self.timeline_panel.IsShown()
98
99 - def show_welcome_panel(self):
100 self._show_panel(self.welcome_panel)
101
102 - def show_timeline_panel(self):
103 self._show_panel(self.timeline_panel)
104
105 - def show_searchbar(self, show=True):
106 self.searchbar.Show(show) 107 if show is True: 108 self.searchbar.Focus() 109 self.GetSizer().Layout()
110
112 self.category_tree.set_no_timeline_view() 113 self.set_searchbar_timeline_canvas(None) 114 self.timeline_panel.SetDb(None) 115 self.show_welcome_panel()
116
117 - def display_timeline(self, timeline):
118 if timeline is None: 119 # Do we ever end up here with the welcome panel displayed? 120 self._remove_timeline_and_show_welcome_panel() 121 else: 122 self._show_new_timeline(timeline)
123
124 - def _show_new_timeline(self, timeline):
125 self.timeline_panel.SetDb(timeline) 126 canvas = self.get_timeline_canvas() 127 self.category_tree.set_timeline_view(canvas.GetDb(), canvas.GetViewProperties()) 128 self.set_searchbar_timeline_canvas(canvas) 129 self.show_timeline_panel() 130 canvas.SetDropTarget(FileDropTarget(canvas))
131
132 - def get_timeline_canvas(self):
133 return self.timeline_panel.get_timeline_canvas()
134
135 - def save_view_properties(self, timeline):
137
139 return self.get_view_properties().displayed_period.delta()
140
141 - def get_time_period(self):
142 return self.timeline_panel.get_time_period()
143
145 view_properties = self.get_view_properties() 146 return (view_properties.selected_event_ids[0], 147 view_properties.selected_event_ids[1])
148
149 - def get_selected_event_ids(self):
151 154 157
158 - def open_event_editor(self, event):
159 self.timeline_panel.open_event_editor(event)
160
161 - def redraw_timeline(self):
162 self.timeline_panel.redraw_timeline()
163
164 - def Navigate(self, navigation_fn):
165 return self.timeline_panel.Navigate(navigation_fn)
166
167 - def get_visible_events(self, all_events):
168 view_properties = self.get_view_properties() 169 visible_events = view_properties.filter_events(all_events) 170 return visible_events
171
172 - def set_searchbar_timeline_canvas(self, timeline_canvas):
173 self.searchbar.SetTimelineCanvas(timeline_canvas)
174
175 - def get_view_properties(self):
176 return self.timeline_panel.get_view_properties()
177
178 - def _create_gui(self):
179 # Search bar 180 self.searchbar = SearchBar(self) 181 self.searchbar.Show(False) 182 # Panels 183 self.welcome_panel = WelcomePanel(self, self.main_frame) 184 self.timeline_panel = TimelinePanel( 185 self, self.config, self.main_frame.status_bar_adapter, 186 self.main_frame) 187 # Layout 188 self.sizerOuter = wx.BoxSizer(wx.VERTICAL) 189 self.sizer = wx.BoxSizer(wx.HORIZONTAL) 190 self.sizer.Add(self.welcome_panel, flag=wx.GROW, proportion=1) 191 self.sizer.Add(self.timeline_panel, flag=wx.GROW, proportion=1) 192 self.sizerOuter.Add(self.sizer, flag=wx.GROW, proportion=1) 193 self.sizerOuter.Add(self.searchbar, flag=wx.GROW, proportion=0) 194 self.SetSizer(self.sizerOuter)
195
196 - def _show_panel(self, panel):
197 self._hide_all_panels() 198 panel.Show(True) 199 self.sizerOuter.Layout() 200 panel.activated()
201
202 - def _hide_all_panels(self):
203 for panel_to_hide in [self.welcome_panel, self.timeline_panel]: 204 panel_to_hide.Show(False)
205