Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wxGUI/lmgr: add menu item for launching dialog for setting RStudio path #1232

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gui/wxpython/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,9 @@ def _defaultSettings(self):
"nodata": {"enable": False},
},
},
"rstudio": {
"path": "",
},
}

# quick fix, https://trac.osgeo.org/grass/ticket/1233
Expand Down
95 changes: 93 additions & 2 deletions gui/wxpython/gui_core/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@
- :class:`SymbolDialog`
- :class:`QuitDialog`
- :class:`DefaultFontDialog`
- :class:`DirBrowseDialog`

(C) 2008-2016 by the GRASS Development Team
(C) 2008-2021 by the GRASS Development Team
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(C) 2008-2021 by the GRASS Development Team
(C) 2008-2024 by the GRASS Development Team


This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.

@author Martin Landa <landa.martin gmail.com>
@author Anna Kratochvilova <kratochanna gmail.com> (GroupDialog, SymbolDialog)
@author Tomas Zigo <tomas.zigo slovanet.sk> (DirBrowseDialog)
"""

import os
import re

import wx
import wx.lib.filebrowsebutton as filebrowse

from grass.script import core as grass
from grass.script.utils import naturally_sorted, try_remove
Expand All @@ -47,7 +50,13 @@
OgrTypeSelect,
SubGroupSelect,
)
from gui_core.widgets import SingleSymbolPanel, SimpleValidator, MapValidator
from gui_core.widgets import (
GenericValidator,
GListCtrl,

Check failure on line 55 in gui/wxpython/gui_core/dialogs.py

View workflow job for this annotation

GitHub Actions / Python Code Quality Checks (ubuntu-22.04)

Ruff (F401)

gui/wxpython/gui_core/dialogs.py:55:5: F401 `gui_core.widgets.GListCtrl` imported but unused
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[ruff] reported by reviewdog 🐶

Suggested change
GListCtrl,

MapValidator,
SimpleValidator,
SingleSymbolPanel,
)
from core.settings import UserSettings
from core.debug import Debug
from core.utils import is_shell_running
Expand Down Expand Up @@ -2611,3 +2620,85 @@
else:
self.renderfont.SetBitmap(EmptyBitmap(size[0], size[1]))
try_remove(self.tmp_file)


class DirBrowseDialog(wx.Dialog):
"""Simple dialog with DirBrowseButton widget."""

def __init__(
self,
parent,
message,
caption="",
defaultValue="",
validator=wx.DefaultValidator,
style=wx.OK | wx.CANCEL | wx.CENTRE,
textStyle=0,
textSize=(300, -1),
size=(400, -1),
**kwargs,
):
wx.Dialog.__init__(
self, parent=parent, id=wx.ID_ANY, title=caption, size=size, **kwargs
)

vbox = wx.BoxSizer(wx.VERTICAL)

stline = StaticText(self, id=wx.ID_ANY, label=message)
vbox.Add(stline, proportion=0, flag=wx.EXPAND | wx.ALL, border=10)

self._dirBrowse = filebrowse.DirBrowseButton(
parent=self,
id=wx.ID_ANY,
labelText=_("Directory:"),
dialogTitle=_("Choose directory for export"),
buttonText=_("Browse"),
startDirectory=os.getcwd(),

Check failure on line 2656 in gui/wxpython/gui_core/dialogs.py

View workflow job for this annotation

GitHub Actions / Python Code Quality Checks (ubuntu-22.04)

Ruff (PTH109)

gui/wxpython/gui_core/dialogs.py:2656:28: PTH109 `os.getcwd()` should be replaced by `Path.cwd()`
)
self._dirBrowse.SetValidator(
GenericValidator(
condition=self._pathExists, callback=self._pathDoesNotExists
)
)
wx.CallAfter(self._dirBrowse.SetFocus)

vbox.Add(
self._dirBrowse,
proportion=0,
flag=wx.EXPAND | wx.LEFT | wx.RIGHT,
border=10,
)

sizer = self.CreateSeparatedButtonSizer(style)
vbox.Add(sizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=10)

self.SetSizerAndFit(vbox)
self.SetSizeHints(size[0], size[1], -1, -1)

self.Bind(wx.EVT_BUTTON, self.OnPathValidation, self.FindWindow(id=wx.ID_OK))

def _pathExists(self, path):
return os.path.exists(path)

def _pathDoesNotExists(self, ctrl):
GMessage(
parent=self,
message=_(
"RStudio path <{}> doesn't exists. "
"Set correct path, please.".format(ctrl.GetValue())

Check failure on line 2688 in gui/wxpython/gui_core/dialogs.py

View workflow job for this annotation

GitHub Actions / Python Code Quality Checks (ubuntu-22.04)

Ruff (INT002)

gui/wxpython/gui_core/dialogs.py:2687:17: INT002 `format` method argument is resolved before function call; consider `_("string %s") % arg`
),
)

def OnPathValidation(self, event):
if self.Validate() and self.TransferDataFromWindow():
if self.IsModal():
self.EndModal(wx.ID_OK)
else:
self.SetReturnCode(wx.ID_OK)
self.Show(False)

def GetValue(self):
return self._dirBrowse.GetValue()

def SetValue(self, value):
self._dirBrowse.SetValue(value)
25 changes: 25 additions & 0 deletions gui/wxpython/lmgr/frame.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update date range

Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
from lmgr.giface import LayerManagerGrassInterface
from mapdisp.frame import MapDisplay
from datacatalog.catalog import DataCatalog
from gui_core.dialogs import DirBrowseDialog
from history.browser import HistoryBrowser
from gui_core.forms import GUI
from gui_core.wrap import Menu, TextEntryDialog
Expand Down Expand Up @@ -758,6 +759,30 @@ def OnLocationWizard(self, event):
show_confirmation=True,
)

def OnSetRStudioPath(self, event):
"""Set RStudio path"""
dlg = DirBrowseDialog(
parent=self,
message=_("Set RStudio path:"),
caption=_("Set RStudio path"),
)

rstudio_path = UserSettings.Get(group="rstudio", key="path")
if rstudio_path:
dlg.SetValue(value=rstudio_path)

if dlg.ShowModal() == wx.ID_OK:
rstudio_path = dlg.GetValue()
UserSettings.Set(group="rstudio", key="path", value=rstudio_path)
fileSettings = {}
UserSettings.ReadSettingsFile(settings=fileSettings)
fileSettings["rstudio"] = UserSettings.Get(group="rstudio")
UserSettings.SaveToFile(fileSettings)
if rstudio_path not in os.environ["PATH"]:
os.environ["PATH"] += os.pathsep + rstudio_path

dlg.Destroy()

def OnSettingsChanged(self):
"""Here can be functions which have to be called
after receiving settingsChanged signal.
Expand Down
4 changes: 4 additions & 0 deletions gui/wxpython/xml/toolboxes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,10 @@
<separator/>
<wxgui-item name="CreateNewLocation"/>
<wxgui-item name="CreateNewMapset"/>
<separator/>
<wxgui-item name="SetRStudioPath"/>
<separator/>
<wxgui-item name="VersionAndCopyright"/>
</items>
</toolbox>
<toolbox name="MapProjections">
Expand Down
12 changes: 12 additions & 0 deletions gui/wxpython/xml/wxgui_items.xml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,18 @@
<description>Creates new mapset in the current project, changes current mapset.</description>
<keywords>general,mapset,create</keywords>
</wxgui-item>
<wxgui-item name="SetRStudioPath">
<label>Set RStudio path</label>
<handler>OnSetRStudioPath</handler>
<description>Set RStudio path.</description>
<keywords>general,rstudio,path</keywords>
</wxgui-item>
<wxgui-item name="VersionAndCopyright">
<label>Version and copyright</label>
<command>g.version -c</command>
<description>Displays version and copyright information.</description>
<keywords>general,version</keywords>
</wxgui-item>
<wxgui-item name="DisplayMapProjection">
<label>Display map projection</label>
<command>g.proj -p</command>
Expand Down
Loading