Changes

From Gramps

Gramps 5.2 Wiki Manual - Gramplets

1,139 bytes added, 16:54, 1 July 2024
m
Python Evaluation: sample script for Python Eval
[[File:PythonEvaluation-Gramplet-detached-example-52.png|right|thumb|301px|Fig {{#var:chapter}}.{{#vardefineecho:figure|{{#expr:{{#var:figure}}+1}}}} Python Evaluation Gramplet - detached example]]
The {{man label|Python Evaluation}} window tool is intended to test Python scripts with Gramps data.
 
Sample code for listing Gramps internal "[https://github.com/gramps-project/gramps/blob/master/gramps/gen/const.py constants]":
 
<pre>
import os
import sys
from gramps.gen.const import *
 
# Get all uppercase variables from the current namespace
ENV = {
name: value for name, value in locals().items()
if name.isupper() and not name.startswith('_') and isinstance(value, str)
}
 
# Print each item in the dictionary, indicating if it's a hidden directory
for key, value in ENV.items():
try:
if os.path.isdir(value):
if sys.platform.startswith('win'):
import ctypes
attrs = ctypes.windll.kernel32.GetFileAttributesW(value)
hidden_status = "HIDDEN" if attrs != -1 and bool(attrs & 2) else "NOT HIDDEN"
else:
hidden_status = "HIDDEN" if os.path.basename(value).startswith('.') else "NOT HIDDEN"
print(f"({hidden_status}) {key} : {value}")
else:
print(f"{key} : {value} (NOT A DIRECTORY)")
except Exception as e:
print(f"{key} : {value} (ERROR : {str(e)})")
</pre>
 
==== See Also ====
* [[Addon:Python_Shell_Gramplet|Python Shell]] addon gramplet
5,421
edits

Navigation menu