Giter Club home page Giter Club logo

Comments (13)

Godzil avatar Godzil commented on May 8, 2024 1

If you use that, please add a fallback, an external tool like xdg-user-dir is not necessarily installed:

godzil@box4 ~ $ xdg-user-dir
-bash: xdg-user-dir: command not found

from pyxel.

kitao avatar kitao commented on May 8, 2024

The filename for captured images is decided in the _get_capture_filename method in app.py.
And it only takes care of Windows and Mac for now.

If there's some way to get the path to the desktop on Linux, I'll add the code for that. And if there's no common way for that, I think the home directory can be used instead of the desktop.

Do you know how to get the desktop path on Linux? (I hope it's not different for each distribution.)
Or I should use the home directory on Linux?

from pyxel.

JeanAraujo avatar JeanAraujo commented on May 8, 2024

Both

import os
os.popen('xdg-user-dir DESKTOP').read().split('\n')[0]

and

import subprocess
subprocess.check_output(['xdg-user-dir', 'DESKTOP']).decode('utf-8').split('\n')[0]

Worked for me on Ubuntu and Fedora, I don't know if it works on all distribution though.

from pyxel.

kitao avatar kitao commented on May 8, 2024

I fixed it and released as 0.7.4.
Could you confirm it works right?

from pyxel.

vesche avatar vesche commented on May 8, 2024

@Godzil The implemented method that fixed this issue ea462c6 does not use xdg-user-dir.

from pyxel.

Godzil avatar Godzil commented on May 8, 2024

Well this is not the actual code:

path = os.popen('xdg-user-dir DESKTOP').read().split('\n')[0]

from pyxel.

JeanAraujo avatar JeanAraujo commented on May 8, 2024

@Godzil I was afraid that something like that would happen.
Two ways of solving this are:

  1. Using some other python module to do this and setting it as a dependency. (I think that there is a xdg module for python but I didn't check it out yet)
  2. Mixing my solution with @vesche 's to something like:
import subprocess
[...]
else:
    try:
        path = subprocess.check_output(["xdg-user-dir", "DESKTOP"], shell=True).decode('utf-8').split('\n')
    except subprocess.CalledProcessError:
        path = os.path.expanduser('~')

from pyxel.

kitao avatar kitao commented on May 8, 2024

@JeanAraujo @Godzil
Actually I don't have Linux environment now.
Though the code above looks correct, doest this code work on Linux actual? If so, I'll use this.

from pyxel.

JeanAraujo avatar JeanAraujo commented on May 8, 2024
def _get_capture_filename():
        if os.name == 'nt':
            path = os.path.join(
                os.path.join(os.environ['USERPROFILE']), 'Desktop')
        else:
            try:
                path = subprocess.check_output(["xdg-user-dir DESKTOP"], shell=True).decode('utf-8').split('\n')[0]
            except subprocess.CalledProcessError:
                path = os.path.expanduser('~')

        return os.path.join(
            path,
            datetime.datetime.now().strftime('pyxel-%y%m%d-%H%M%S'))

Works for me, but I would first like @Godzil and @vesche thoughts on this 🤔

from pyxel.

Godzil avatar Godzil commented on May 8, 2024

@kitao As you must know there is not just one Linux distribution, and not all necessarily provide the same set of tools.

xdg-user-dir is not a tool installed by default on all distributions, on one of my computer, this tool does not exist, so relying only on it is not a good idea.

@JeanAraujo seems to be a good solution, try if the tool works, if not, fallback using the user folder, apart from missing Mac OS X, xdg-user is clearly not supported under Mac OS X.

from pyxel.

JeanAraujo avatar JeanAraujo commented on May 8, 2024

Oh, that's true, @Godzil
I'm sorry :p

   @staticmethod
    def _get_capture_filename():
        plat = platform.system()

        if plat == 'Windows':
            path = os.path.join(
                os.path.join(os.environ['USERPROFILE']), 'Desktop')
        elif plat == 'Darwin':
            path = os.path.join(
                os.path.join(os.path.expanduser('~')), 'Desktop')
        else:
            path = os.path.join(
                os.path.join(os.path.expanduser('~')), 'Desktop')
            if not os.path.exists(path):
                try:
                    path = subprocess.check_output(["xdg-user-dir DESKTOP"], shell=True).decode('utf-8').split('\n')[0]
                except subprocess.CalledProcessError:
                    path = os.path.expanduser('~')

        return os.path.join(
            path,
            datetime.datetime.now().strftime('pyxel-%y%m%d-%H%M%S'))

Well, this code looks a bit... extensive, but it supposedly works. I can't use a linux system at the moment so I'll check it later.
I still want @vesche thoughts on it.

from pyxel.

kitao avatar kitao commented on May 8, 2024

I imported the above code and released it as 0.7.5.
Please let me know if it doesn't work.

from pyxel.

JeanAraujo avatar JeanAraujo commented on May 8, 2024

Changed, tested and solved on #32.
Tested on Ubuntu 18.04.1 LTS

from pyxel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.