Skip to content

Commit

Permalink
fixes to statusbar messages and motion events
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias47n9e committed Jun 27, 2015
1 parent d21d34c commit e8f21d6
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 21 deletions.
27 changes: 22 additions & 5 deletions innstereo/gui_layout.glade
Original file line number Diff line number Diff line change
Expand Up @@ -3727,6 +3727,7 @@ customizable grid.</property>
<object class="GtkMenuBar" id="menubar1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="enter-notify-event" handler="eventbox_motion" swapped="no"/>
<child>
<object class="GtkMenuItem" id="menuitem_file">
<property name="visible">True</property>
Expand Down Expand Up @@ -3954,6 +3955,7 @@ customizable grid.</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="toolbar_style">icons</property>
<signal name="enter-notify-event" handler="eventbox_motion" swapped="no"/>
<child>
<object class="GtkToolButton" id="toolbutton_new_project">
<property name="visible">True</property>
Expand Down Expand Up @@ -4297,6 +4299,7 @@ customizable grid.</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="button-press-event" handler="on_eb_lbl_layerview_button_press_event" swapped="no"/>
<signal name="enter-notify-event" handler="eventbox_motion" swapped="no"/>
<child>
<object class="GtkLabel" id="label_layerview">
<property name="visible">True</property>
Expand Down Expand Up @@ -4329,6 +4332,7 @@ customizable grid.</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="toolbar_style">icons</property>
<signal name="enter-notify-event" handler="eventbox_motion" swapped="no"/>
<child>
<object class="GtkToolButton" id="toolbutton_create_group_layer">
<property name="visible">True</property>
Expand Down Expand Up @@ -4461,6 +4465,8 @@ customizable grid.</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<signal name="enter-notify-event" handler="eventbox_motion" swapped="no"/>
<signal name="motion-notify-event" handler="eventbox_motion" swapped="no"/>
<child>
<placeholder/>
</child>
Expand All @@ -4483,6 +4489,7 @@ customizable grid.</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="button-press-event" handler="on_eb_lbl_dataview_button_press_event" swapped="no"/>
<signal name="enter-notify-event" handler="eventbox_motion" swapped="no"/>
<child>
<object class="GtkLabel" id="lablel2">
<property name="visible">True</property>
Expand Down Expand Up @@ -4515,6 +4522,7 @@ customizable grid.</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="toolbar_style">icons</property>
<signal name="enter-notify-event" handler="eventbox_motion" swapped="no"/>
<child>
<object class="GtkToggleToolButton" id="toolbutton_draw_features">
<property name="visible">True</property>
Expand Down Expand Up @@ -4603,6 +4611,8 @@ customizable grid.</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<signal name="enter-notify-event" handler="eventbox_motion" swapped="no"/>
<signal name="motion-notify-event" handler="eventbox_motion" swapped="no"/>
<child>
<placeholder/>
</child>
Expand Down Expand Up @@ -4648,13 +4658,20 @@ customizable grid.</property>
</packing>
</child>
<child>
<object class="GtkStatusbar" id="statusbar1">
<object class="GtkEventBox" id="eventbox_statusbar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">6</property>
<property name="margin_bottom">6</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<signal name="enter-notify-event" handler="eventbox_motion" swapped="no"/>
<child>
<object class="GtkStatusbar" id="statusbar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">6</property>
<property name="margin_bottom">6</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
Expand Down
74 changes: 58 additions & 16 deletions innstereo/main_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self, builder):
self.sw_layer = builder.get_object("sw_layerview")
self.sw_data = builder.get_object("sw_dataview")
self.tb1 = builder.get_object("toolbar1")
self.statbar = builder.get_object("statusbar1")
self.statbar = builder.get_object("statusbar")
self.plot_menu = builder.get_object("menu_plot_views")

context = self.tb1.get_style_context()
Expand Down Expand Up @@ -106,7 +106,7 @@ def __init__(self, builder):

#Set up event-handlers
self.canvas.mpl_connect('motion_notify_event',
self.update_cursor_position)
self.mpl_motion_event)
self.canvas.mpl_connect('button_press_event',
self.mpl_canvas_clicked)
self.redraw_plot()
Expand Down Expand Up @@ -759,7 +759,7 @@ def on_toolbutton_draw_features_toggled(self, widget):
self.draw_features = True
else:
self.draw_features = False
self.update_cursor_position(None)
self.update_statusbar()

def on_toolbutton_best_plane_clicked(self, widget):
# pylint: disable=unused-argument
Expand Down Expand Up @@ -2298,18 +2298,66 @@ def mpl_canvas_clicked(self, event):
if self.draw_features == False:
selection.unselect_all()

def update_cursor_position(self, event):
def mpl_motion_event(self, mpl_event):
"""
Catches motion events on the mpl canvas and plots.
Updates the StatusBar.
"""
self.update_statusbar(mpl_event)

def eventbox_motion(self, widget, event):
"""
Catches motion events and calls the updating of the StatusBar.
Triggered by many areas of the UI. Receives a widget (EventBox,
ScrolledWindow, Toolbar) and the event itself (Gdk.EventMotion,
Gdk.EventCrossing, ...).
Calls the update_statusbar function to push helpful messages to the
StatusBar.
"""
self.update_statusbar()

def update_statusbar(self, mpl_event=None, *args, **kwargs):
"""
When the mouse cursor hovers inside the plot, the position of the
event is pushed to the statusbar at the bottom of the GUI. Also
mpl_event is pushed to the statusbar at the bottom of the GUI. Also
called by a few buttons, to push messages to the statusbar.
"""
selection = self.layer_view.get_selection()
model, row_list = selection.get_selected_rows()

def push_drawing_message():
self.statbar.push(1, "Left click inside the plot to draw a feature.")

if event is not None:
if event.inaxes is not None:
alpha_deg, gamma_deg = self.convert_xy_to_dirdip(event)
def push_select_layer_message():
self.statbar.push(1, "Select the layer that you want to edit.")

def push_one_layer_message():
self.statbar.push(1, "Select only one layer to edit it.")

def push_group_layer_message():
self.statbar.push(1, "Group layers cannot hold features. Select a data-layer for editing.")

def push_messages():
if self.draw_features == True:
if len(row_list) == 1:
row = row_list[0]
lyr_obj = model[row][3]
if lyr_obj == None:
push_group_layer_message()
else:
push_drawing_message()
elif len(row_list) > 1:
push_one_layer_message()
else:
push_select_layer_message()
else:
self.statbar.push(1, (""))

if mpl_event is not None:
if mpl_event.inaxes is not None:
alpha_deg, gamma_deg = self.convert_xy_to_dirdip(mpl_event)

alpha_deg = int(alpha_deg)
gamma_deg = int(gamma_deg)
Expand All @@ -2320,15 +2368,9 @@ def push_drawing_message():

self.statbar.push(1, ("{0} / {1}".format(alpha_deg, gamma_deg)))
else:
if self.draw_features == True:
push_drawing_message()
else:
self.statbar.push(1, (""))
push_messages()
else:
if self.draw_features == True:
push_drawing_message()
else:
self.statbar.push(1, (""))
push_messages()

def on_toolbutton_file_parse_clicked(self, toolbutton):
"""
Expand Down

0 comments on commit e8f21d6

Please sign in to comment.