the-magnificents / 04-02-2021-Carpentry-for-HGIS

A carpentry workshop focused on Digital Humanities audience that works with Geospatial Data.
Other
2 stars 3 forks source link

04-02-2021-Carpentry-for-HGIS/02_Day_2_Python_GIS/exercise/B0_exercise1_qgis #63

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

Running someone else’s Python script — Python essentials for GIS learners

https://the-magnificents.github.io/04-02-2021-Carpentry-for-HGIS/02_Day_2_Python_GIS/exercise/B0_exercise1_qgis.html

cforgaci commented 3 years ago

Nice, a button appears under the "help" menu! As it only stays there for the current session, how can you make a such button permanent?

jurra commented 3 years ago

Hi @cforgaci, the reason why it is not permanent is because you need to run the script, to make it permanent I would assume you would have to make a plugin or something similar, so that it runs automatically everytime qgis is launched.

You would have to tell qgis somehow to run this script on every start. I don't know how to do that, but I assume it should be possible.

communisker commented 3 years ago

My QGIS version is 2.18.4, after running the gis.buttom.py, the console showed an error message:

Traceback (most recent call last): File "", line 1, in File "//tudelft.net/staff-homes/G/yygan/Desktop/pre_workshop_files-master/qgis/gis_button.py", line 6, in website_action = QAction('Go to gis.stackexchange') NameError: name 'QAction' is not defined

LCarvalhoF commented 3 years ago

I got the same error as Cinco, I have the same version of Qgis

aecryan commented 3 years ago

Hmm, yes my guess is that the issue comes from the fact that this script was written for QGIS version 3, so it may not work the same on version 2. I will do a little research to see if there's a quick change we can make so that it does work :)

aecryan commented 3 years ago

@communisker and @LCarvalhoF to verify, are you opening this python script from your QGIS Python Code Editor? You will get an error if you try running it in the terminal...so I just wanted to double check. It looks like the QAction method is available in QGIS version 2, so that shouldn't be the error.

The workflow is:

  1. Open QGIS
  2. Open the Python console (Plugins > Python console), then the Code Editor (little button that looks like a piece of paper with a pencil on the top of the Python Console)
  3. Open gis_button.py (button on top of code editor that looks like an open folder)
  4. Hit play button

Can you try those steps and let me know if it works?

aecryan commented 3 years ago

This is an important point that we touched upon just briefly this morning - scripts written specifically for QGIS will not work outside of QGIS without some special formatting changes (or libraries that do it automatically). For now, we can run everything in QGIS.

LCarvalhoF commented 3 years ago

I followed exactly the same steps and still get the same error.

aecryan commented 3 years ago

@LCarvalhoF can you jump back into the office hours Zoom and we can take a look?