Skip to content

Commit 4386523

Browse files
authored
fix #88 : added Report Issue, Users Discussion, New Releases And Announces Mailing List and About items in the Help menu
* added dependencies list in utils.py Also: * added get_package_version and get_versions function in utils.py * updated open_documentation, open_tutorial, open_api_documentation methods (all urls are centralized in a dictionary located in utils.py)
1 parent 6362a6f commit 4386523

File tree

2 files changed

+137
-6
lines changed

2 files changed

+137
-6
lines changed

larray_editor/editor.py

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import numpy as np
55

66
from larray import LArray, Session, zeros
7-
from larray_editor.utils import PYQT5, _, create_action, show_figure, ima, commonpath
7+
from larray_editor.utils import (PY2, PYQT5, _, create_action, show_figure, ima, commonpath, dependencies,
8+
get_versions, urls)
89
from larray_editor.arraywidget import ArrayEditorWidget
9-
1010
from qtpy.QtCore import Qt, QSettings, QUrl, Slot
1111
from qtpy.QtGui import QDesktopServices, QKeySequence
1212
from qtpy.QtWidgets import (QMainWindow, QWidget, QVBoxLayout, QListWidget, QListWidgetItem, QSplitter, QFileDialog,
@@ -250,6 +250,10 @@ def _reset(self):
250250
def setup_menu_bar(self):
251251
"""Setup menu bar"""
252252
menu_bar = self.menuBar()
253+
254+
###############
255+
# File Menu #
256+
###############
253257
file_menu = menu_bar.addMenu('&File')
254258

255259
file_menu.addAction(create_action(self, _('&New'), shortcut="Ctrl+N", triggered=self.new))
@@ -275,12 +279,23 @@ def setup_menu_bar(self):
275279
file_menu.addSeparator()
276280
file_menu.addAction(create_action(self, _('&Quit'), shortcut="Ctrl+Q", triggered=self.close))
277281

282+
###############
283+
# Help Menu #
284+
###############
278285
help_menu = menu_bar.addMenu('&Help')
279286
help_menu.addAction(create_action(self, _('Online &Documentation'), shortcut="Ctrl+H",
280287
triggered=self.open_documentation))
281288
help_menu.addAction(create_action(self, _('Online &Tutorial'), triggered=self.open_tutorial))
282289
help_menu.addAction(create_action(self, _('Online Objects and Functions (API) &Reference'),
283290
triggered=self.open_api_documentation))
291+
help_menu.addSeparator()
292+
help_menu.addAction(create_action(self, _('Report &Issue...'), triggered=self.report_issue))
293+
help_menu.addAction(create_action(self, _('&Users Discussion...'), triggered=self.open_users_group))
294+
help_menu.addAction(create_action(self, _('New Releases And &Announces Mailing List...'),
295+
triggered=self.open_announce_group))
296+
297+
help_menu.addSeparator()
298+
help_menu.addAction(create_action(self, _('&About'), triggered=self.about))
284299

285300
def data_changed(self):
286301
# We do not set self._unsaved_modifications to True because if users click on `Discard` button
@@ -657,13 +672,76 @@ def load_example(self):
657672
self._open_file(filepath)
658673

659674
def open_documentation(self):
660-
QDesktopServices.openUrl(QUrl("http://larray.readthedocs.io/en/stable/"))
675+
QDesktopServices.openUrl(QUrl(urls['doc_stable']))
661676

662677
def open_tutorial(self):
663-
QDesktopServices.openUrl(QUrl("http://larray.readthedocs.io/en/stable/tutorial.html"))
678+
QDesktopServices.openUrl(QUrl(urls['doc_tutorial']))
664679

665680
def open_api_documentation(self):
666-
QDesktopServices.openUrl(QUrl("http://larray.readthedocs.io/en/stable/api.html"))
681+
QDesktopServices.openUrl(QUrl(urls['doc_api']))
682+
683+
def report_issue(self):
684+
if PY2:
685+
from urllib import quote
686+
else:
687+
from urllib.parse import quote
688+
689+
versions = get_versions()
690+
issue_template = """\
691+
## Description
692+
**What steps will reproduce the problem?**
693+
1.
694+
2.
695+
3.
696+
697+
**What is the expected output? What do you see instead?**
698+
699+
700+
**Please provide any additional information below**
701+
702+
703+
## Version and main components
704+
* Python {python} on {system} {bitness:d}bits
705+
* Qt {qt}, {qt_api} {qt_api_ver}
706+
"""
707+
for dep in dependencies:
708+
issue_template += "* {dep} {{{dep}}}\n".format(dep=dep)
709+
issue_template = issue_template.format(**versions)
710+
711+
url = QUrl(urls['new_issue'])
712+
if PYQT5:
713+
from qtpy.QtCore import QUrlQuery
714+
query = QUrlQuery()
715+
query.addQueryItem("body", quote(issue_template))
716+
url.setQuery(query)
717+
else:
718+
url.addEncodedQueryItem("body", quote(issue_template))
719+
QDesktopServices.openUrl(url)
720+
721+
def open_users_group(self):
722+
QDesktopServices.openUrl(QUrl(urls['users_group']))
723+
724+
def open_announce_group(self):
725+
QDesktopServices.openUrl(QUrl(urls['announce_group']))
726+
727+
def about(self):
728+
"""About Editor"""
729+
kwargs = get_versions()
730+
kwargs.update(urls)
731+
message = """\
732+
<b>LArray Editor {editor}</b>: The Graphical User Interface for LArray.
733+
<br>Licensed under the terms of the <a href="{GPL3}">GNU GENERAL PUBLIC LICENSE Version 3</a>.
734+
<p>Developed and maintained by the <a href="{fpb}">Federal Planning Bureau</a> (Belgium).
735+
<p><b>Versions of underlying libraries</b>:
736+
<ul>
737+
<li>Python {python} on {system} {bitness:d}bits</li>
738+
<li>Qt {qt}, {qt_api} {qt_api_ver}</li>
739+
"""
740+
for dep in dependencies:
741+
if kwargs[dep] != 'N/A':
742+
message += "<li>{dep} {{{dep}}}</li>\n".format(dep=dep)
743+
message += "</ul>"
744+
QMessageBox.about(self, _("About Larray Editor"), message.format(**kwargs))
667745

668746
def set_current_file(self, filepath):
669747
self.update_recent_files([filepath])

larray_editor/utils.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,68 @@
1717
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
1818

1919

20-
PY2 = sys.version[0] == '2'
20+
dependencies = ['numpy', 'pandas', 'matplotlib', 'larray', 'larray_eurostat', 'pytables', 'xlwings', 'xlsxwriter',
21+
'xlrd', 'openpyxl']
22+
23+
urls = {"fpb": "http://www.plan.be/index.php?lang=en",
24+
"GPL3": "https://www.gnu.org/licenses/gpl-3.0.html",
25+
"doc_stable": "http://larray.readthedocs.io/en/stable/",
26+
"doc_tutorial": "http://larray.readthedocs.io/en/stable/tutorial.html",
27+
"doc_api": "http://larray.readthedocs.io/en/stable/api.html",
28+
"new_issue": "https://github.com/liam2/larray/issues/new",
29+
"announce_group": "https://groups.google.com/d/forum/larray-announce",
30+
"users_group": "https://groups.google.com/d/forum/larray-users"}
2131

32+
PY2 = sys.version[0] == '2'
2233
if PY2:
2334
def commonpath(paths):
2435
return os.path.dirname(os.path.commonprefix(paths))
2536
else:
2637
commonpath = os.path.commonpath
2738

2839

40+
def get_package_version(package_name):
41+
"""Return the version of a package if installed, N/A otherwise"""
42+
try:
43+
from importlib import import_module
44+
package = import_module(package_name)
45+
if '__version__' in dir(package):
46+
return package.__version__
47+
elif '__VERSION__' in dir(package):
48+
return package.__VERSION__
49+
else:
50+
return 'N/A'
51+
except ImportError:
52+
return 'N/A'
53+
54+
55+
def get_versions():
56+
"""Get version information for components used by the Editor"""
57+
import platform
58+
from qtpy import API_NAME, PYQT_VERSION
59+
from qtpy.QtCore import __version__ as qtpy_version
60+
from larray_editor import __version__ as editor_version
61+
62+
versions = {
63+
'editor': editor_version,
64+
'python': platform.python_version(),
65+
'bitness': 64 if sys.maxsize > 2**32 else 32,
66+
'qt': qtpy_version,
67+
'qt_api': API_NAME, # PyQt5 or PyQt4
68+
'qt_api_ver': PYQT_VERSION,
69+
}
70+
71+
if not sys.platform == 'darwin': # To avoid a crash with our Mac app
72+
versions['system'] = platform.system() # Linux, Windows, ...
73+
else:
74+
versions['system'] = 'Darwin'
75+
76+
for dep in dependencies:
77+
versions[dep] = get_package_version(dep)
78+
79+
return versions
80+
81+
2982
# Note: string and unicode data types will be formatted with '%s' (see below)
3083
SUPPORTED_FORMATS = {
3184
'object': '%s',

0 commit comments

Comments
 (0)