Added docstrings.
This commit is contained in:
parent
f7ededa451
commit
1f9a400057
|
@ -80,12 +80,17 @@ class ObjectTable:
|
||||||
|
|
||||||
class ViewFrame (gtk.Frame):
|
class ViewFrame (gtk.Frame):
|
||||||
"""
|
"""
|
||||||
A ViewFrame is a gtk bin that contains a view.
|
A ViewFrame is a gtk container widget that contains a View.
|
||||||
The ViewFrame is either active or inactive, and belongs to a group of
|
The ViewFrame is either active or inactive, and belongs to a group of
|
||||||
VeiwFrames of which only one can be active at any time.
|
VeiwFrames of which only one can be active at any time.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, view_frames):
|
def __init__(self, view_frames):
|
||||||
|
"""Initializes a new ViewFrame.
|
||||||
|
@param view_frames: A list of view frames to which the new view
|
||||||
|
frame shouls belong. Only one ViewFrame in this list can be
|
||||||
|
active at any time.
|
||||||
|
"""
|
||||||
gtk.Frame.__init__(self)
|
gtk.Frame.__init__(self)
|
||||||
self.focused = False
|
self.focused = False
|
||||||
self.view_frames = view_frames
|
self.view_frames = view_frames
|
||||||
|
@ -101,7 +106,7 @@ class ViewFrame (gtk.Frame):
|
||||||
vbox.pack_start(gtk.HSeparator(), expand=False)
|
vbox.pack_start(gtk.HSeparator(), expand=False)
|
||||||
|
|
||||||
self._ebox_button_event = ebox.connect("button-press-event",
|
self._ebox_button_event = ebox.connect("button-press-event",
|
||||||
self.on_button_press_event)
|
self._on_button_press_event)
|
||||||
## Keep the references for later use.
|
## Keep the references for later use.
|
||||||
self._vbox = vbox
|
self._vbox = vbox
|
||||||
self._ebox = ebox
|
self._ebox = ebox
|
||||||
|
@ -123,14 +128,16 @@ class ViewFrame (gtk.Frame):
|
||||||
|
|
||||||
# Set view
|
# Set view
|
||||||
self._view = self.empty_view
|
self._view = self.empty_view
|
||||||
self._view.connect("button-press-event", self.on_button_press_event)
|
self._view.connect("button-press-event", self._on_button_press_event)
|
||||||
self._vbox.add(self._view)
|
self._vbox.add(self._view)
|
||||||
self._view_title.set_text(self._view.title)
|
self._view_title.set_text(self._view.title)
|
||||||
self.show_all()
|
self.show_all()
|
||||||
self._view.show()
|
self._view.show()
|
||||||
|
|
||||||
def focus(self):
|
def focus(self):
|
||||||
"""Gets focus and ensures that no other window is in focus."""
|
"""Gets focus and ensures that no other ViewFrame in the same set
|
||||||
|
is in focus.
|
||||||
|
"""
|
||||||
if self.focused:
|
if self.focused:
|
||||||
self.emit('focus-changed', self, True)
|
self.emit('focus-changed', self, True)
|
||||||
return self
|
return self
|
||||||
|
@ -155,7 +162,9 @@ class ViewFrame (gtk.Frame):
|
||||||
self.emit('focus-changed', self, False)
|
self.emit('focus-changed', self, False)
|
||||||
|
|
||||||
def set_view(self, view):
|
def set_view(self, view):
|
||||||
"""Set view to view or to empty view if parameter is None"""
|
"""Set view to view or to empty view if parameter is None
|
||||||
|
@param view: An instance of View
|
||||||
|
"""
|
||||||
|
|
||||||
# if None is passed, use empty view
|
# if None is passed, use empty view
|
||||||
if view == None:
|
if view == None:
|
||||||
|
@ -174,7 +183,7 @@ class ViewFrame (gtk.Frame):
|
||||||
self._view.disconnect(self._button_event)
|
self._view.disconnect(self._button_event)
|
||||||
|
|
||||||
self._button_event = view.connect("button-press-event",
|
self._button_event = view.connect("button-press-event",
|
||||||
self.on_button_press_event)
|
self._on_button_press_event)
|
||||||
|
|
||||||
# remove old view, set new view
|
# remove old view, set new view
|
||||||
if self._view:
|
if self._view:
|
||||||
|
@ -190,12 +199,15 @@ class ViewFrame (gtk.Frame):
|
||||||
self._view = view
|
self._view = view
|
||||||
|
|
||||||
def get_view(self):
|
def get_view(self):
|
||||||
"""Returns current view, or None if the empty view is set."""
|
"""Returns current view, or None if the empty view is set.
|
||||||
|
@returns: None if the ViewFrame is currently displaying it's
|
||||||
|
EmptyView. Otherwise it returns the currently displeyd View.
|
||||||
|
"""
|
||||||
if self._view == self.empty_view:
|
if self._view == self.empty_view:
|
||||||
return None
|
return None
|
||||||
return self._view
|
return self._view
|
||||||
|
|
||||||
def on_button_press_event(self, widget, event):
|
def _on_button_press_event(self, widget, event):
|
||||||
if not self.focused:
|
if not self.focused:
|
||||||
self.focus()
|
self.focus()
|
||||||
|
|
||||||
|
@ -211,6 +223,12 @@ class ViewFrame (gtk.Frame):
|
||||||
|
|
||||||
|
|
||||||
class MainView (gtk.Notebook):
|
class MainView (gtk.Notebook):
|
||||||
|
"""The MainView class displays the Views in Fluents.
|
||||||
|
|
||||||
|
MainView, of which there is normally only one instance, contains a
|
||||||
|
gtk.Table that holds all the visible Views, and a single ViewFrame
|
||||||
|
that is used for maximizing plots.
|
||||||
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
gtk.Notebook.__init__(self)
|
gtk.Notebook.__init__(self)
|
||||||
self.set_show_tabs(False)
|
self.set_show_tabs(False)
|
||||||
|
@ -222,7 +240,7 @@ class MainView (gtk.Notebook):
|
||||||
self.update_small_views()
|
self.update_small_views()
|
||||||
|
|
||||||
for vf in self._view_frames:
|
for vf in self._view_frames:
|
||||||
vf.connect('focus-changed', self.on_view_focus_changed)
|
vf.connect('focus-changed', self._on_view_focus_changed)
|
||||||
|
|
||||||
self.append_page(self._small_views)
|
self.append_page(self._small_views)
|
||||||
self.append_page(self._large_view)
|
self.append_page(self._large_view)
|
||||||
|
@ -293,28 +311,39 @@ class MainView (gtk.Notebook):
|
||||||
self.set_current_page(0)
|
self.set_current_page(0)
|
||||||
|
|
||||||
def insert_view(self, view):
|
def insert_view(self, view):
|
||||||
"""Set a view in the currently active ViewFrame"""
|
"""Set a view in the currently active ViewFrame.
|
||||||
|
@param view: An instance of View.
|
||||||
|
"""
|
||||||
if self.get_current_page() == 0:
|
if self.get_current_page() == 0:
|
||||||
vf = self.get_active_small_view()
|
vf = self.get_active_small_view()
|
||||||
else:
|
else:
|
||||||
vf = self._large_view
|
vf = self._large_view
|
||||||
vf.set_view(view)
|
vf.set_view(view)
|
||||||
|
|
||||||
def set_all_plots(self, plots):
|
def set_all_plots(self, views):
|
||||||
"""Displays all the plots in the list plots, and hides all other plots"""
|
"""Displays all the views in the list, and hides all other views.
|
||||||
|
|
||||||
|
Loops through all ViewFrames from top left to bottom right, and sets
|
||||||
|
their currently active View to the next view in the list. After the
|
||||||
|
last view is placed in a ViewFrame, the remaining ViewFrames are
|
||||||
|
emptied.
|
||||||
|
|
||||||
|
@param views: A list of views to set.
|
||||||
|
"""
|
||||||
for y in range(self._views.ysize):
|
for y in range(self._views.ysize):
|
||||||
for x in range(self._views.xsize):
|
for x in range(self._views.xsize):
|
||||||
if plots:
|
if views:
|
||||||
self._views[x, y].set_view(plots.pop())
|
self._views[x, y].set_view(views.pop())
|
||||||
else:
|
else:
|
||||||
self._views[x, y].set_view(None)
|
self._views[x, y].set_view(None)
|
||||||
|
|
||||||
def on_view_focus_changed(self, widget, vf, focused):
|
def _on_view_focus_changed(self, widget, vf, focused):
|
||||||
if focused:
|
if focused:
|
||||||
self.emit('view-changed', vf)
|
self.emit('view-changed', vf)
|
||||||
|
|
||||||
def resize_table(self, width, height):
|
def resize_table(self, width, height):
|
||||||
|
"""Resizes the list of small views.
|
||||||
|
"""
|
||||||
## Hide all plots that will be removed from the screen.
|
## Hide all plots that will be removed from the screen.
|
||||||
for x in range(self._views.xsize):
|
for x in range(self._views.xsize):
|
||||||
for y in range(self._views.ysize):
|
for y in range(self._views.ysize):
|
||||||
|
@ -335,12 +364,14 @@ class MainView (gtk.Notebook):
|
||||||
|
|
||||||
|
|
||||||
class View (gtk.Frame):
|
class View (gtk.Frame):
|
||||||
"""The base class of everything that is shown in the center view of fluents.
|
"""The base class of everything that is shown in the center view of
|
||||||
|
fluents.
|
||||||
|
|
||||||
Most views should rather subclass Plot, which automatically handles freezing and
|
Most views should rather subclass Plot, which automatically handles
|
||||||
toolbars, and sets up matplotlib Figure and Canvas objects.
|
freezing, creates a toolbar, and sets up matplotlib Figure and Canvas
|
||||||
|
objects.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, title):
|
def __init__(self, title):
|
||||||
gtk.Frame.__init__(self)
|
gtk.Frame.__init__(self)
|
||||||
self.title = title
|
self.title = title
|
||||||
|
|
Reference in New Issue