Skip to content

Commit

Permalink
Port the InfoBars to Python (#170)
Browse files Browse the repository at this point in the history
* Move infobars into a box

* Port the infobars to Python
  • Loading branch information
bluesabre authored Jul 29, 2023
1 parent 3cacc7c commit d21db0c
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 152 deletions.
113 changes: 8 additions & 105 deletions data/ui/MenulibreWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -256,58 +256,22 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkInfoBar" id="bad_desktop_files_infobar">
<object class="GtkBox" id="infobars">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="no-show-all">True</property>
<property name="message-type">warning</property>
<property name="show-close-button">True</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="spacing">6</property>
<property name="layout-style">end</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child internal-child="content_area">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="spacing">16</property>
<child>
<object class="GtkLabel" id="bad_desktop_files_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes" comments="Translators: This error is displayed in a notice at the top of the application when one or more desktop files fails processing.">Invalid desktop files detected! Please see details.</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="position">1</property>
</packing>
</child>
<child>
Expand All @@ -324,67 +288,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkInfoBar" id="menu_restart_required">
<property name="can-focus">False</property>
<property name="message-type">warning</property>
<property name="show-close-button">True</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="spacing">6</property>
<property name="layout-style">end</property>
<child>
<object class="GtkButton" id="menu_restart_button">
<property name="label" translatable="yes">Restart menu...</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child internal-child="content_area">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="spacing">16</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Your applications menu may need to be restarted.</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
<property name="position">2</property>
</packing>
</child>
</object>
Expand Down Expand Up @@ -568,5 +472,4 @@
</packing>
</child>
</object>
<object class="GtkListStore" id="liststore1"/>
</interface>
52 changes: 36 additions & 16 deletions menulibre/MenulibreApplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ def __init__(self, app, headerbar_pref=True):
# Set up the application browser
self.configure_application_treeview(builder)

self.configure_menu_restart_infobar(builder)

# Determining paths of bad desktop files GMenu can't load - if some are
# detected, alerting user via InfoBar
self.bad_desktop_files = util.determine_bad_desktop_files()
if self.bad_desktop_files:
self.configure_application_bad_desktop_files_infobar(builder)

self.configure_menu_restart_infobar(builder)

def root_lockout(self):
if root:
# Translators: This error is displayed when the application is run
Expand Down Expand Up @@ -481,35 +481,55 @@ def configure_application_actions(self, builder):

def configure_application_bad_desktop_files_infobar(self, builder):
"""Configure InfoBar to alert user to bad desktop files."""
container = builder.get_object('infobars')

# Fetching UI widgets
self.infobar = builder.get_object('bad_desktop_files_infobar')
self.infobar = Gtk.InfoBar.new()
self.infobar.set_message_type(Gtk.MessageType.WARNING)
container.add(self.infobar)

# Configuring buttons for the InfoBar - looks like you can't set a
# response ID via a button defined in glade?
# Can't get a stock button then change its icon, so leaving with no
# icon
self.infobar.add_button('Details', Gtk.ResponseType.YES)
content = self.infobar.get_content_area()

label = Gtk.Label.new(_("Invalid desktop files detected! Please see details."))
label.show()
content.add(label)

self.infobar.add_button(_('Details'), Gtk.ResponseType.YES)

self.infobar.show()

# Hook up events
self.infobar.set_show_close_button(True)
self.infobar.set_default_response(Gtk.ResponseType.CLOSE)

self.infobar.connect('response',
self.on_bad_desktop_files_infobar_response)

def configure_menu_restart_infobar(self, builder):
self.menu_restart_infobar = builder.get_object('menu_restart_required')
self.menu_restart_infobar.set_default_response(Gtk.ResponseType.CLOSE)
container = builder.get_object('infobars')

button = builder.get_object('menu_restart_button')
button.connect('clicked', self.on_menu_restart_button_activate)
self.menu_restart_infobar = Gtk.InfoBar.new()
self.menu_restart_infobar.set_message_type(Gtk.MessageType.WARNING)
container.add(self.menu_restart_infobar)

content = self.menu_restart_infobar.get_content_area()

label = Gtk.Label.new(_("Your applications menu may need to be restarted."))
label.show()
content.add(label)

self.menu_restart_infobar.add_button(_("Restart menu..."), Gtk.ResponseType.ACCEPT)

self.menu_restart_infobar.set_show_close_button(True)
self.menu_restart_infobar.set_default_response(Gtk.ResponseType.CLOSE)

self.menu_restart_infobar.connect('response',
self.on_bad_desktop_files_infobar_response)
self.on_menu_restart_infobar_response)

def on_menu_restart_infobar_response(self, infobar, response_id):
infobar.hide()
if response_id == Gtk.ResponseType.CLOSE:
infobar.hide()
elif response_id == Gtk.ResponseType.ACCEPT:
self.on_menu_restart_button_activate(infobar)

def configure_application_toolbar(self, builder):
"""Configure the application toolbar."""
Expand Down Expand Up @@ -729,7 +749,7 @@ def menu_restart_dialog(self, cmd):
response = dialog.run()
if response == Gtk.ResponseType.YES:
subprocess.Popen(cmd)
self.menu_restart_infobar.hide()
self.menu_restart_infobar.hide()
dialog.destroy()


Expand Down
65 changes: 34 additions & 31 deletions po/menulibre.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-28 07:04-0400\n"
"POT-Creation-Date: 2023-07-29 06:59-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -88,19 +88,6 @@ msgstr ""
msgid "Search"
msgstr ""

#. Translators: This error is displayed in a notice at the top of the application when one or more desktop files fails processing.
#: ../data/ui/MenulibreWindow.ui.h:23
msgid "Invalid desktop files detected! Please see details."
msgstr ""

#: ../data/ui/MenulibreWindow.ui.h:24
msgid "Restart menu..."
msgstr ""

#: ../data/ui/MenulibreWindow.ui.h:25
msgid "Your applications menu may need to be restarted."
msgstr ""

#. Translators: Command line option to display debug messages on stdout
#: ../menulibre/__init__.py:34
msgid "Show debug messages"
Expand Down Expand Up @@ -1096,7 +1083,7 @@ msgstr ""

#. Translators: Help action tooltip
#: ../menulibre/CommandEditor.py:90 ../menulibre/MenulibreApplication.py:450
#: ../menulibre/MenulibreApplication.py:1613
#: ../menulibre/MenulibreApplication.py:1633
msgid "Help"
msgstr ""

Expand Down Expand Up @@ -1351,8 +1338,8 @@ msgid "Select an icon"
msgstr ""

#. Translators: Separator menu item
#: ../menulibre/MenuEditor.py:126 ../menulibre/MenulibreApplication.py:794
#: ../menulibre/MenulibreApplication.py:1087
#: ../menulibre/MenuEditor.py:126 ../menulibre/MenulibreApplication.py:814
#: ../menulibre/MenulibreApplication.py:1107
msgid "Separator"
msgstr ""

Expand Down Expand Up @@ -1460,7 +1447,7 @@ msgstr ""

#. Translators: Quit action tooltip
#: ../menulibre/MenulibreApplication.py:441
#: ../menulibre/MenulibreApplication.py:1615
#: ../menulibre/MenulibreApplication.py:1635
msgid "Quit"
msgstr ""

Expand All @@ -1476,16 +1463,32 @@ msgstr ""

#. Translators: About action tooltip
#: ../menulibre/MenulibreApplication.py:459
#: ../menulibre/MenulibreApplication.py:1614
#: ../menulibre/MenulibreApplication.py:1634
msgid "About"
msgstr ""

#: ../menulibre/MenulibreApplication.py:722
#: ../menulibre/MenulibreApplication.py:737
#: ../menulibre/MenulibreApplication.py:492
msgid "Invalid desktop files detected! Please see details."
msgstr ""

#: ../menulibre/MenulibreApplication.py:496
msgid "Details"
msgstr ""

#: ../menulibre/MenulibreApplication.py:516
msgid "Your applications menu may need to be restarted."
msgstr ""

#: ../menulibre/MenulibreApplication.py:520
msgid "Restart menu..."
msgstr ""

#: ../menulibre/MenulibreApplication.py:742
#: ../menulibre/MenulibreApplication.py:757
msgid "Menu restart required"
msgstr ""

#: ../menulibre/MenulibreApplication.py:723
#: ../menulibre/MenulibreApplication.py:743
#, python-format
msgid ""
"MenuLibre can do this automatically. Do you want to run the following "
Expand All @@ -1494,7 +1497,7 @@ msgid ""
"%s"
msgstr ""

#: ../menulibre/MenulibreApplication.py:738
#: ../menulibre/MenulibreApplication.py:758
msgid ""
"However, MenuLibre cannot determine how to do this automatically on your "
"system. Please log out for you menu to update completely."
Expand All @@ -1503,46 +1506,46 @@ msgstr ""
#. Translators: This error is displayed when the user does not
#. have sufficient file system permissions to delete the
#. selected file.
#: ../menulibre/MenulibreApplication.py:942
#: ../menulibre/MenulibreApplication.py:962
msgid "You do not have permission to delete this file."
msgstr ""

#. Translators: Placeholder text for a newly created launcher.
#: ../menulibre/MenulibreApplication.py:1012
#: ../menulibre/MenulibreApplication.py:1032
msgid "New Launcher"
msgstr ""

#. Translators: Placeholder text for a newly created launcher's
#. description.
#: ../menulibre/MenulibreApplication.py:1015 ../menulibre/MenulibreXdg.py:50
#: ../menulibre/MenulibreApplication.py:1035 ../menulibre/MenulibreXdg.py:50
msgid "A small descriptive blurb about this application."
msgstr ""

#. Translators: Placeholder text for a newly created directory.
#: ../menulibre/MenulibreApplication.py:1065
#: ../menulibre/MenulibreApplication.py:1085
msgid "New Directory"
msgstr ""

#. Translators: Placeholder text for a newly created directory's
#. description.
#: ../menulibre/MenulibreApplication.py:1068
#: ../menulibre/MenulibreApplication.py:1088
msgid "A small descriptive blurb about this directory."
msgstr ""

#. Translators: Confirmation dialog to delete the selected
#. separator.
#: ../menulibre/MenulibreApplication.py:1489
#: ../menulibre/MenulibreApplication.py:1509
msgid "Are you sure you want to delete this separator?"
msgstr ""

#. Translators: Confirmation dialog to delete the selected launcher.
#: ../menulibre/MenulibreApplication.py:1493
#: ../menulibre/MenulibreApplication.py:1513
#, python-format
msgid "Are you sure you want to delete \"%s\"?"
msgstr ""

#. Translators: Menu item to open the Parsing Errors dialog.
#: ../menulibre/MenulibreApplication.py:1608
#: ../menulibre/MenulibreApplication.py:1628
msgid "Parsing Error Log"
msgstr ""

Expand Down

0 comments on commit d21db0c

Please sign in to comment.