Benjamin-Loison / pyzo

Python to the people
https://pyzo.org
Other
0 stars 0 forks source link

`Open directory in file browser` does not work on Linux Mint with pip install #1

Open Benjamin-Loison opened 7 months ago

Benjamin-Loison commented 7 months ago

DuckDuckGo and Google "Open directory in file browser" "pyzo" only lead to the source code itself.

Would ease getting path to workaround #3 and opening a terminal in its folder to use git with this script.

Experience this issue with Linux Mint (hence nemo file browser) and Pyzo 4.14.4 with pip (PyPi confirms that it is the latest release). Current latest is 4.15.0.

apt show pyzo
Package: pyzo
Version: 4.11.2-1
...

So should give a try to GitHub release in a virtual machine.

Nothing happens in shell if started pyzo with it when click on Open directory in file browser.

Maybe related to pyzo/issues/{206,455}.

Same issue with 4.15.0.

Do not think that

Request: /home/benjamin/test.py
Reply: Try opening file '/home/benjamin/test.py'

is related to click on the considered button it is just because I start pyzo as follows:

./pyzo ~/test.py

because opening or saving a file makes pyzo crash.

Let us try to compile pyzo to have the really last changes. Just using ./pyzolauncher.py takes into account my local testing change. Still have the issue with the default branch main updated last week.

grep -rn 'Open directory in file browser' --exclude-dir=translations
pyzo/core/menu.py:1691:            translate("menu", "Open directory in file browser"),
pyzo/core/menu.py:1809:            translate("menu", "Open directory in file browser"),

Have indeed 2 menus having this option:

image

image

None of both works.

        self.addItem(
            translate("menu", "Open directory in file browser"),
            None,
            self._editItemCallback,
            "opendir",
        )
        self.addItem(
            translate("menu", "Open directory in file browser"),
            None,
            self._fileAction,
            "opendir",
        )

Only self._ lines differ.

grep -rwn opendir
pyzo/core/menu.py:1524:            "opendir",
pyzo/core/menu.py:1545:        if action == "opendir":
pyzo/core/menu.py:1694:            "opendir",
pyzo/core/menu.py:1735:        if action == "opendir":
pyzo/core/menu.py:1812:            "opendir",
pyzo/core/menu.py:1877:        elif action == "opendir":

Note that opendir does not return any result in original repository issues.

The first opendir occurrence is:

        self.addItem(
            translate("menu", "Open current directory in file browser"),
            None,
            self._editItemCallback,
            "opendir",
        )

Note the different end-user text.

image

does not work as well.

        if action == "opendir":
            curdir = self._shell.get_kernel_cd()
            fileBrowser = pyzo.toolManager.getTool("pyzofilebrowser")
            if curdir and fileBrowser:
                fileBrowser.setPath(curdir)
        if action == "opendir":
            fileBrowser = pyzo.toolManager.getTool("pyzofilebrowser")
            if fileBrowser:
                fileBrowser.setPath(os.path.dirname(self._editor.filename))
        elif action == "opendir":
            fileBrowser = pyzo.toolManager.getTool("pyzofilebrowser")
            if fileBrowser:
                fileBrowser.setPath(os.path.dirname(item.filename))

Only curdir and fileBrowser.setPath argument differ.

Let us focus on the file name right-click possiblity, i.e. lines 1812 and 1877.

        elif action == "opendir":
            fileBrowser = pyzo.toolManager.getTool("pyzofilebrowser")
            print(f'{fileBrowser=}')
            if fileBrowser:
                print(f'{item.filename=} {os.path.dirname(item.filename)=}')
                fileBrowser.setPath(os.path.dirname(item.filename))
fileBrowser=<pyzo.tools.pyzoFileBrowser.PyzoFileBrowser object at 0x7f13ccb153f0>
item.filename='/home/benjamin/test.py' os.path.dirname(item.filename)='/home/benjamin'

seem correct.

grep -rwn 'setPath'
pyzo/tools/pyzoFileBrowser/__init__.py:127:    def setPath(self, path):
pyzo/tools/pyzoFileBrowser/__init__.py:130:        browser._tree.setPath(path)
pyzo/tools/pyzoFileBrowser/browser.py:40:        self._tree.setPath(cleanpath(self.config.path))
pyzo/tools/pyzoFileBrowser/browser.py:57:        self._pathEdit.dirChanged.connect(self._tree.setPath)
pyzo/tools/pyzoFileBrowser/browser.py:58:        self._projects.dirChanged.connect(self._tree.setPath)
pyzo/tools/pyzoFileBrowser/browser.py:63:        self._tree.dirChanged.connect(self._pathEdit.setPath)
pyzo/tools/pyzoFileBrowser/browser.py:64:        self._tree.dirChanged.connect(self._projects.setPath)
pyzo/tools/pyzoFileBrowser/browser.py:315:        # for win32 setRootPath is done self.setPath(...)
pyzo/tools/pyzoFileBrowser/browser.py:323:    def setPath(self, path):
pyzo/tools/pyzoFileBrowser/browser.py:374:        self.setPath(path)
pyzo/tools/pyzoFileBrowser/browser.py:425:    def setPath(self, path):
pyzo/tools/pyzoFileBrowser/browser.py:535:        self.setPath(self._path)
pyzo/tools/pyzoFileBrowser/browser.py:544:            self.setPath(self._path)
pyzo/tools/pyzoFileBrowser/tree.py:282:        self.treeWidget().setPath(self.path())
pyzo/tools/pyzoFileBrowser/tree.py:305:        self.treeWidget().setPath(self.path())
pyzo/tools/pyzoFileBrowser/tree.py:630:    def setPath(self, path):
pyzo/tools/pyzoFileBrowser/tree.py:673:            self.setPath(cleanpath(MOUNTS))
pyzo/tools/pyzoFileBrowser/tree.py:675:            self.setPath(newPath)
pyzo/tools/pyzoFileBrowser/tree.py:874:        self.parent().setPath(self.parent().path())
pyzo/core/menu.py:1549:                fileBrowser.setPath(curdir)
pyzo/core/menu.py:1738:                fileBrowser.setPath(os.path.dirname(self._editor.filename))
pyzo/core/menu.py:1882:                fileBrowser.setPath(os.path.dirname(item.filename))
grep -rn 'def setPath'
pyzo/tools/pyzoFileBrowser/__init__.py:127:    def setPath(self, path):
pyzo/tools/pyzoFileBrowser/browser.py:323:    def setPath(self, path):
pyzo/tools/pyzoFileBrowser/browser.py:425:    def setPath(self, path):
pyzo/tools/pyzoFileBrowser/tree.py:630:    def setPath(self, path):
    def setPath(self, path):
        """Set the shown path."""
        print(f'{self._browsers=}')
        browser = self._browsers[0]
        browser._tree.setPath(path)
self._browsers=[<pyzo.tools.pyzoFileBrowser.browser.Browser object at 0x7f1ba820d7e0>]
    def setPath(self, path):
        """Set the path to display. Does nothing if this widget has focus."""
        if sys.platform == "win32":
            oldDrive, _ = op.splitdrive(self.text())
            newDrive, _ = op.splitdrive(path)
            if oldDrive != newDrive:
                self._dirModel.setRootPath(newDrive)
        print(f'{self.hasFocus()=}')
        if not self.hasFocus():
            self.setText(path)
            self.checkValid()  # Reset style if it was invalid first
self.hasFocus()=False

Same issue on Windows with Pyzo 4.15.0.

Using Pyzo debugger would be interesting but does not seem to apply to itself.

    def setPath(self, path):
        print('Executed pyzo/tools/pyzoFileBrowser/browser.py:425')
        self._path = path
        # Find project index
        projectIndex, L = 0, 0
        pathn = op.normcase(path) + op.sep
        for i in range(self._combo.count()):
            projectPath = self._combo.itemData(i) + op.sep
            if pathn.startswith(projectPath) and len(projectPath) > L:
                projectIndex, L = i, len(projectPath)
        # Select project or not ...
        self._combo.setCurrentIndex(projectIndex)
        if projectIndex:
            self._but.setIcon(pyzo.icons.star2)
            self._but.setMenu(self._menu)
        else:
            self._but.setIcon(pyzo.icons.star3)
            self._but.setMenu(None)
Executed pyzo/tools/pyzoFileBrowser/browser.py:425
    def setPath(self, path):
        """Set the current path shown by the treeview."""
        print('Executed pyzo/tools/pyzoFileBrowser/tree.py:630')
        # Close old proxy
        if self._proxy is not None:
            self._proxy.cancel()
            failed = []
            for signal, func in [
                (self.destroyed, self._proxy.cancel),
                (self._proxy.changed, self.onChanged),
                (self._proxy.deleted, self.onDeleted),
                (self._proxy.errored, self.onErrored),
            ]:
                try:
                    signal.disconnect(func)
                except Exception:
                    failed.append(signal)
            if failed:
                pass  # print("Failed to disconnect", failed)
        # Create new proxy
        if True:
            self._proxy = self.parent()._fsProxy.dir(path)
            self._proxy.changed.connect(self.onChanged)
            self._proxy.deleted.connect(self.onDeleted)
            self._proxy.errored.connect(self.onErrored)
            self.destroyed.connect(self._proxy.cancel)
        # Activate the proxy, we'll get a call at onChanged() asap.
        if path.lower() == MOUNTS.lower():
            self.clear()
            createMounts(self.parent(), self)
        else:
            self._proxy.track()
            self._proxy.push()
        # Store dir in config
        self.parent().config.path = path
        # Signal that the dir has changed
        # Note that our contents may not be visible yet.
        self.dirChanged.emit(self.path())
Executed pyzo/tools/pyzoFileBrowser/browser.py:425

Should verify finally with a folder not being default current working directory.

Benjamin-Loison commented 2 months ago

It seems that it is just for Tools > File Browser.

Benjamin-Loison commented 2 months ago

Instead of copy-pasting code, should have commit and use a permalink to both have a link and the associated code with my prints.

Benjamin-Loison commented 2 months ago

Could make Open directory in file browser show File Browser Tool if it was hidden.

That way the purpose of this option would be clear.