Skip to content

Commit

Permalink
enh: set R executable and display R version in preferences (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Feb 16, 2021
1 parent a2e2a1f commit f9a9cdf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 26 deletions.
28 changes: 19 additions & 9 deletions shapeout2/gui/preferences.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pathlib
import pkg_resources
import platform

Expand Down Expand Up @@ -47,8 +48,8 @@ def __init__(self, parent, *args, **kwargs):
QtWidgets.QDialogButtonBox.RestoreDefaults)
btn_restore.clicked.connect(self.on_restore)
# lme4 buttons
self.toolButton_lme4_install.clicked.connect(self.on_lme4_install)
self.toolButton_lme4_search.clicked.connect(self.on_lme4_search_r)
self.pushButton_lme4_install.clicked.connect(self.on_lme4_install)
self.pushButton_lme4_search.clicked.connect(self.on_lme4_search_r)

def reload(self):
"""Read configuration or set default parameters"""
Expand All @@ -74,23 +75,32 @@ def reload(self):
@show_wait_cursor
def reload_lme4(self, install=False):
"""Reload information about lme4, optionally installing it"""
# set the binary
binary = self.lme4_rpath.text()
if pathlib.Path(binary).is_file():
rsetup.set_r_path(binary)
# check lme4 package status
if not rsetup.has_r():
status = "unknown"
elif rsetup.has_lme4():
status = "installed"
r_version = "unknown"
lme4_st = "unknown"
else:
status = "not installed"
r_version = rsetup.get_r_version()
if rsetup.has_lme4():
lme4_st = "installed"
else:
lme4_st = "not installed"

if install and status == "not installed":
if install and lme4_st == "not installed":
self.setEnabled(False)
rsetup.install_lme4()
self.setEnabled(True)
# update interface with installed lme4
self.reload_lme4(install=False)
else:
# update user interface
self.toolButton_lme4_install.setVisible(status == "not installed")
self.label_lme4_installed.setText(status)
self.pushButton_lme4_install.setVisible(lme4_st == "not installed")
self.label_r_version.setText(r_version)
self.label_lme4_installed.setText(lme4_st)

@QtCore.pyqtSlot()
def on_apply(self):
Expand Down
41 changes: 24 additions & 17 deletions shapeout2/gui/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -130,41 +130,48 @@
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<item row="0" column="1">
<widget class="QLineEdit" name="lme4_rpath"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>R executable</string>
<string>lme4 package</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="toolButton_lme4_search">
<item row="2" column="2">
<widget class="QPushButton" name="pushButton_lme4_install">
<property name="text">
<string>Search manually...</string>
<string>Install...</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lme4_rpath"/>
<item row="2" column="1">
<widget class="QLabel" name="label_lme4_installed">
<property name="text">
<string>installed / not installed</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<item row="0" column="2">
<widget class="QPushButton" name="pushButton_lme4_search">
<property name="text">
<string>lme4 package</string>
<string>Search manually...</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_lme4_installed">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>installed / not installed</string>
<string>R executable</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QToolButton" name="toolButton_lme4_install">
<item row="1" column="1">
<widget class="QLabel" name="label_r_version">
<property name="text">
<string>Install...</string>
<string>R version</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit f9a9cdf

Please sign in to comment.