Skip to content

Commit

Permalink
Fix macro button and submenu
Browse files Browse the repository at this point in the history
  • Loading branch information
astroDimitrios committed Aug 27, 2024
1 parent c9f1774 commit f7bd1d0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 35 deletions.
27 changes: 14 additions & 13 deletions metomi/rose/config_editor/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,20 +306,22 @@ def add_macro(self, config_name, modulename, classname, methodname,
if config_item.get_submenu() is None:
config_item.set_submenu(Gtk.Menu())
macro_fullname = ".".join([modulename, classname, methodname])
macro_fullname = macro_fullname.replace("_", "__")
macro_fullname = macro_fullname.replace("__", "_")
if methodname == metomi.rose.macro.VALIDATE_METHOD:
stock_id = Gtk.STOCK_DIALOG_QUESTION
stock_id = "dialog-question"
else:
stock_id = Gtk.STOCK_CONVERT
macro_item_box = Gtk.Box()
macro_item_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
macro_item_icon = Gtk.Image.new_from_icon_name(stock_id, Gtk.IconSize.MENU)
macro_item_label = Gtk.Label(label=macro_fullname)
macro_item = Gtk.MenuItem()
macro_item_box.pack_start(macro_item_icon, False, False, 0)
macro_item_box.pack_start(macro_item_label, False, False, 0)
Gtk.Container.add(macro_item_box, macro_item_icon)
Gtk.Container.add(macro_item_box, macro_item_label)
Gtk.Container.add(macro_item, macro_item_box)
macro_item.set_tooltip_text(help_)
macro_item.show()
context = Gtk.Widget.get_style_context(macro_item)
Gtk.StyleContext.add_class(context, "macro-item")
macro_item.show_all()
macro_item._run_data = [config_name, modulename, classname,
methodname]
macro_item.connect("activate",
Expand All @@ -329,17 +331,17 @@ def add_macro(self, config_name, modulename, classname, methodname,
for item in config_item.get_submenu().get_children():
if hasattr(item, "_rose_all_validators"):
return False
all_item_box = Gtk.Box()
all_item_icon = Gtk.Image.new_from_icon_name(Gtk.STOCK_DIALOG_QUESTION, Gtk.IconSize.MENU)
all_item_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
all_item_icon = Gtk.Image.new_from_icon_name("dialog-question", Gtk.IconSize.MENU)
all_item_label = Gtk.Label(label=metomi.rose.config_editor.MACRO_MENU_ALL_VALIDATORS)
all_item = Gtk.MenuItem()
all_item_box.pack_start(all_item_icon, False, False, 0)
all_item_box.pack_start(all_item_label, False, False, 0)
Gtk.Container.add(macro_item, macro_item_box)
Gtk.Container.add(all_item_box, all_item_icon)
Gtk.Container.add(all_item_box, all_item_label)
Gtk.Container.add(all_item, all_item_box)
all_item._rose_all_validators = True
all_item.set_tooltip_text(
metomi.rose.config_editor.MACRO_MENU_ALL_VALIDATORS_TIP)
all_item.show()
all_item.show_all()
all_item._run_data = [config_name, None, None, methodname]
all_item.connect("activate",
lambda i: run_macro(*i._run_data))
Expand Down Expand Up @@ -591,7 +593,6 @@ def override_macro_defaults(self, optionals, methname):
response = dialog.run()
if response == Gtk.ResponseType.CANCEL or response == Gtk.ResponseType.CLOSE:
res = optionals
dialog.destroy()
else:
res = {}
for key, box in list(entries.items()):
Expand Down
51 changes: 29 additions & 22 deletions metomi/rose/config_editor/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Gtk, Gdk
from gi.repository import Pango

import metomi.rose.config_editor.panelwidget
Expand Down Expand Up @@ -377,11 +377,11 @@ def launch_url(self, *args):

def update_info(self):
"""Driver routine to update non-variable information."""
button_list, label_list, _ = self._get_page_info_widgets()
button_list, label_list, info = self._get_page_info_widgets()
if [l.get_text() for l in label_list] == self._last_info_labels:
# No change - do not redraw.
return False
self.generate_page_info(button_list, label_list)
self.generate_page_info(button_list, label_list, info)
has_content = (self.info_panel.get_children() and
self.info_panel.get_children()[0].get_children())
if self.info_panel in self.main_vpaned.get_children():
Expand Down Expand Up @@ -1048,9 +1048,10 @@ def sort_data(self, column_index=0, ascending=True, ghost=False):
datavars[i] = datum[4] # variable
return True

def _macro_menu_launch(self, widget, event):
# Create a menu below the widget for macro actions.
menu = Gtk.Menu()
def _macro_menu_launch(self):
# Create the popover menu below the widget for macro actions.
self.popover = Gtk.Popover()
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
for macro_name, info in sorted(self.custom_macros.items()):
method, description = info
if method == metomi.rose.macro.TRANSFORM_METHOD:
Expand All @@ -1060,20 +1061,23 @@ def _macro_menu_launch(self, widget, event):
macro_menuitem_box = Gtk.Box()
macro_menuitem_icon = Gtk.Image.new_from_icon_name(stock_id, Gtk.IconSize.MENU)
macro_menuitem_label = Gtk.Label(label=macro_name)
macro_menuitem = Gtk.MenuItem()
macro_menuitem = Gtk.Button()
macro_menuitem_box.pack_start(macro_menuitem_icon, False, False, 0)
macro_menuitem_box.pack_start(macro_menuitem_label, False, False, 0)
Gtk.Container.add(macro_menuitem, macro_menuitem_box)
macro_menuitem.set_tooltip_text(description)
macro_menuitem.show()
macro_menuitem._macro = macro_name
macro_menuitem.connect(
"button-release-event",
lambda m, e: self.launch_macro(m._macro))
menu.append(macro_menuitem)
menu.popup(None, None, widget.position_menu, event.button,
event.time, widget)

"clicked",
lambda m: self.launch_macro(m._macro))
macro_menuitem.set_relief(Gtk.ReliefStyle.NONE)
macro_menuitem.connect("leave", lambda b: b.set_relief(Gtk.ReliefStyle.NONE))
vbox.pack_start(macro_menuitem, False, True, 10)
vbox.show_all()
self.popover.add(vbox)
self.popover.set_position(Gtk.PositionType.BOTTOM)

def launch_macro(self, macro_name_string):
"""Launch a macro, if possible."""
class_name = None
Expand Down Expand Up @@ -1181,16 +1185,19 @@ def _get_page_info_widgets(self):
button_list.append(error_button)
label_list.append(error_label)
if list(self.custom_macros.items()):
macro_button = metomi.rose.gtk.util.CustomButton(
self._macro_menu_launch()
macro_button_icon = Gtk.Image.new_from_icon_name("system-run", Gtk.IconSize.MENU)
macro_label = Gtk.Label(label=metomi.rose.config_editor.LABEL_PAGE_MACRO_BUTTON)
macro_button = Gtk.MenuButton(
image=macro_button_icon,
label=metomi.rose.config_editor.LABEL_PAGE_MACRO_BUTTON,
stock_id=Gtk.STOCK_EXECUTE,
tip_text=metomi.rose.config_editor.TIP_MACRO_RUN_PAGE,
as_tool=True, icon_at_start=True,
has_menu=True)
macro_button.connect("button-press-event",
self._macro_menu_launch)
macro_label = Gtk.Label()
macro_label.show()
popover=self.popover,
)
macro_button.set_relief(Gtk.ReliefStyle.NONE)
macro_button.connect("leave", lambda b: b.set_relief(Gtk.ReliefStyle.NONE))
macro_button.show()
Gtk.Widget.set_name(macro_button, "macro-button")

button_list.append(macro_button)
label_list.append(macro_label)
return button_list, label_list, info
6 changes: 6 additions & 0 deletions metomi/rose/etc/rose-config-edit/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ entry {
background-image: None;
box-shadow: None;
}

#macro-button {
padding: 5px;
margin-top: 10px;
margin-left: 10px;
}

0 comments on commit f7bd1d0

Please sign in to comment.