Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions src/odemis/gui/cont/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ def __init__(self, main_data: MainGUIData, main_frame: wx.Frame, data_collector:
menu_dev = main_frame.menu_item_edit_meteor_calibration.GetMenu()
menu_dev.Delete(main_frame.menu_item_edit_meteor_calibration)

# /Help/Share Data with Delmic
if main_data.role in ["meteor", "mimas"]:
self.consent_item = main_frame.menu_item_data_sharing
self.consent_item.Check(self._data_collector.get_consent() is True)
main_frame.Bind(wx.EVT_MENU, self._on_toggle_data_sharing, id=self.consent_item.GetId())
else:
menu = main_frame.menu_item_data_sharing.GetMenu()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This else block is a bit odd to me. Feels like we could have placed the instantiation of main_frame.menu_item_data_sharing in the if part and leave out the else part, unless there is a menu-specific constraint that I'm missing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's always instantiated, from the XRC file. That's how all the menu items are done.

menu.Remove(main_frame.menu_item_data_sharing)
main_frame.menu_item_data_sharing.Destroy()

# TODO: make it work on Windows too
# /Help/Report a problem...
if sys.platform.startswith('win32'):
Expand All @@ -158,9 +168,6 @@ def __init__(self, main_data: MainGUIData, main_frame: wx.Frame, data_collector:

# /Help/About
main_frame.Bind(wx.EVT_MENU, self._on_about, id=main_frame.menu_item_about.GetId())
self._consent_menu_item = self._append_data_sharing_menu_item(main_frame)
if self._consent_menu_item is not None:
main_frame.Bind(wx.EVT_MENU, self._on_toggle_data_sharing, id=self._consent_menu_item.GetId())

# add a toggle for correlation tab in viewer mode
if main_data.is_viewer:
Expand All @@ -171,20 +178,6 @@ def __init__(self, main_data: MainGUIData, main_frame: wx.Frame, data_collector:
menu.Remove(main_frame.menu_item_show_correlation)
main_frame.menu_item_show_correlation.Destroy()

def _append_data_sharing_menu_item(self, main_frame: wx.Frame) -> wx.MenuItem:
"""
Append and initialize Help menu checkbox for data sharing consent.
:param main_frame: The main application frame.
:return: The created menu item, or None if the Help menu is not available.
"""
help_menu = main_frame.menu_item_about.GetMenu()
if help_menu is None:
return None
help_menu.AppendSeparator()
item = help_menu.AppendCheckItem(wx.ID_ANY, "Share data with Delmic")
item.Check(self._data_collector.get_consent() is True)
return item

@call_in_wx_main
def _on_toggle_data_sharing(self, evt):
"""Show consent dialog when the data-sharing menu item is clicked."""
Expand Down Expand Up @@ -216,8 +209,7 @@ def _on_toggle_data_sharing(self, evt):
elif response == wx.ID_CANCEL:
self._data_collector.set_temporary_consent(days=1)
# Sync the Help menu checkbox to reflect the persisted choice.
if self._consent_menu_item is not None:
self._consent_menu_item.Check(self._data_collector.get_consent() is True)
self.consent_item.Check(self._data_collector.get_consent() is True)
except Exception:
logging.exception("Failed to run data-collection consent prompt.")

Expand Down
8 changes: 8 additions & 0 deletions src/odemis/gui/main_xrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ def __init__(self, parent):
self.menu_item_debug = self.GetMenuBar().FindItemById(xrc.XRCID("menu_item_debug"))
self.menu_item_edit_meteor_calibration = self.GetMenuBar().FindItemById(xrc.XRCID("menu_item_edit_meteor_calibration"))
self.menu_item_bugreport = self.GetMenuBar().FindItemById(xrc.XRCID("menu_item_bugreport"))
self.menu_item_data_sharing = self.GetMenuBar().FindItemById(xrc.XRCID("menu_item_data_sharing"))
self.menu_item_update = self.GetMenuBar().FindItemById(xrc.XRCID("menu_item_update"))
self.menu_item_about = self.GetMenuBar().FindItemById(xrc.XRCID("menu_item_about"))
self.pnl_tabbuttons = xrc.XRCCTRL(self, "pnl_tabbuttons")
Expand Down Expand Up @@ -3147,6 +3148,13 @@ def __init_resources():
<assign_var>1</assign_var>
</XRCED>
</object>
<object class="wxMenuItem" name="menu_item_data_sharing">
<label>Share Data with Delmic</label>
<checkable>1</checkable>
Comment on lines +3151 to +3153
<XRCED>
<assign_var>1</assign_var>
</XRCED>
</object>
<object class="separator"/>
<object class="wxMenuItem" name="menu_item_update">
<label>Check for update</label>
Expand Down
7 changes: 7 additions & 0 deletions src/odemis/gui/xmlh/resources/frame_main.xrc
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@
<assign_var>1</assign_var>
</XRCED>
</object>
<object class="wxMenuItem" name="menu_item_data_sharing">
<label>Share Data with Delmic</label>
<checkable>1</checkable>
Comment on lines +200 to +202
<XRCED>
<assign_var>1</assign_var>
</XRCED>
</object>
<object class="separator"/>
<object class="wxMenuItem" name="menu_item_update">
<label>Check for update</label>
Expand Down
Loading