Skip to content

Commit

Permalink
Fix Missing About Menu on OSX (#52)
Browse files Browse the repository at this point in the history
* Fix missing About... menu item

* Update info in about.py

* Update CHANGELOG
  • Loading branch information
tvhong authored Dec 30, 2024
1 parent 862ee73 commit bbc9eba
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Don't switch to deck browser after import (#38)
- Properly handle importing a page when title is missing (#34)
- Missing About menu on OSX (#47)

### Changed
- Use `poetry` to manage the project (#43)
Expand Down
29 changes: 12 additions & 17 deletions ir/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,27 @@

from ._version import __version__

IR_GITHUB_URL = "https://github.com/luoliyan/incremental-reading"
IR_GITHUB_URL = "https://github.com/tvhong/incremental-reading"


def showAbout():
dialog = QDialog(mw)

label = QLabel()
label.setStyleSheet("QLabel { font-size: 14px; }")
names = [
"Tiago Barroso",
"Frank Kmiec",
"Aleksej",
contributors = [
"Joseph Lorimer <[email protected]>" "Timothée Chauvin",
"Christian Weiß",
"Timothée Chauvin",
"Aleksej",
"Frank Kmiec",
"Tiago Barroso",
]
text = """
<div style="font-weight: bold">Incremental Reading v%s</div>
<div>Joseph Lorimer &lt;[email protected]&gt;</div>
<div>Contributors: %s</div>
<div>Website: <a href="%s">%s</a></div>
""" % (
__version__,
", ".join(names),
IR_GITHUB_URL,
IR_GITHUB_URL,
)
text = f"""
<div style="font-weight: bold">Incremental Reading v{__version__}</div>
<div>Vy Hong &lt;[email protected]&gt;</div>
<div>Contributors: {", ".join(contributors)}</div>
<div>Website: <a href="{IR_GITHUB_URL}">{IR_GITHUB_URL}</a></div>
"""
label.setText(text)

buttonBox = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok)
Expand Down
31 changes: 26 additions & 5 deletions ir/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# PERFORMANCE OF THIS SOFTWARE.

import os
import re
import stat
import time
from urllib.parse import unquote
Expand Down Expand Up @@ -83,19 +84,39 @@ def addMenuItem(path, text, function, keys=None):
if keys:
action.setShortcut(QKeySequence(keys))

# Override surprising behavior in OSX
# https://doc.qt.io/qt-6/qmenubar.html#qmenubar-as-a-global-menu-bar
if _hasSpecialOsxMenuKeywords(text):
action.setMenuRole(QAction.MenuRole.NoRole)

action.triggered.connect(function)

menu = None
if path == "File":
mw.form.menuCol.addAction(action)
menu = mw.form.menuCol
elif path == "Edit":
mw.form.menuEdit.addAction(action)
menu = mw.form.menuEdit
elif path == "Tools":
mw.form.menuTools.addAction(action)
menu = mw.form.menuTools
elif path == "Help":
mw.form.menuHelp.addAction(action)
menu = mw.form.menuHelp
else:
addMenu(path)
mw.customMenus[path].addAction(action)
menu = mw.customMenus[path]

menu.addAction(action)


def _hasSpecialOsxMenuKeywords(text: str):
"""Checks if a string contains any of the specified keywords.
Args:
text: The string to check.
Returns:
True if any keyword is found, False otherwise.
"""
keywords = r"about|config|options|setup|settings|preferences|quit|exit"
return bool(re.search(keywords, text, re.IGNORECASE))


def getField(note, fieldName):
Expand Down

0 comments on commit bbc9eba

Please sign in to comment.