This version has TRACKING code.
TRACKING only increments a single counter each time the plug-in is called/used.
#!/usr/bin/env python
# timer.py
# Creator: TT
# =======================================================================================
# NOTICE: This version has tracking code which increments a single counter each use.
# You can get untracked version at http://gimpchat.com/viewtopic.php?f=9&t=20651#p285522
# =======================================================================================
# This plug-in was intended to be used as a way to roughly measure a manual process.
# If you map it to a shortcut (ie. Ctrl+T) then just Ctrl+T before you do your manual editing/operations in GIMP
# Then when you're done, just Ctrl+T again and it'll gimp_message the time in seconds since the last time you hit Ctrl+T
# Open Source
# Rel: 1.0
from gimpfu import *
import time
# TRACKING CODE STARTS ================================================================================
# ================================================================================================
import requests
def hit_it(): #this function is called whenever we want to increment counter of var timertt in data below
TRACKING_VARNAME = 'timertt' #Change this value to track different var for each plug-in
# Replace these values with your Firebase configuration
firebase_config = {"apiKey": "AIzaSyApnXYZuSzdpQNXYg0ZWHLF2t3VHjqmf9k","databaseURL": "https://single-counter-default-rtdb.firebaseio.com/"}
counter_path = TRACKING_VARNAME + ".json"
response = requests.get(firebase_config['databaseURL']+counter_path,params={"key": firebase_config["apiKey"]})
if response.status_code == 200:
current_value = response.json()
if current_value is None: #FIRST RUN EVER doesn't have a value we'll just make value 0 so it can be incremented
current_value = 0
new_value = current_value + 1
update_response = requests.put(firebase_config['databaseURL']+counter_path,json=new_value,params={"key": firebase_config["apiKey"]})
if update_response.status_code == 200:
pass
#pdb.gimp_message(new_value) #debug to see incremented value
# TRACKING CODE ENDS ==================================================================================
# =================================================================================================
global_var_id = 'timertt' #used to store our startt timer.
def set_global_variable(value):
gimp.set_data(global_var_id, str(value))
def get_global_variable():
return float(gimp.get_data(global_var_id))
def timer_tt():
try:
startt = get_global_variable()
except RuntimeError:
startt = time.time()
endt = time.time()
time_taken = endt-startt
pdb.gimp_message("Time since last call in secs:" + str(time_taken))
hit_it() #tracking usage here
set_global_variable(time.time())
# Register the Python-Fu plugin
register(
"python_fu_timer_tt",
"Times since last this plug-in was call",
"Times since last this plug-in was call",
"TT",
"TT",
"2023.11.25",
"Timer",
"", # Alternately use RGB, RGB*, GRAY*, INDEXED etc.
[
#INPUT BEGINS
#(PF_IMAGE, "img", "Image", None),
#(PF_DRAWABLE, "layer", "Drawable", None),
#INPUT ENDS
],
[],
timer_tt,
menu="<Image>/Python-Fu")
main()
here's the tracking code portion
# TRACKING CODE STARTS ================================================================================
# ================================================================================================
import requests
def hit_it(): #this function is called whenever we want to increment counter of var timertt in data below
TRACKING_VARNAME = 'timertt' #Change this value to track different var for each plug-in
# Replace these values with your Firebase configuration
firebase_config = {"apiKey": "AIzaSyApnXYZuSzdpQNXYg0ZWHLF2t3VHjqmf9k","databaseURL": "https://single-counter-default-rtdb.firebaseio.com/"}
counter_path = TRACKING_VARNAME + ".json"
response = requests.get(firebase_config['databaseURL']+counter_path,params={"key": firebase_config["apiKey"]})
if response.status_code == 200:
current_value = response.json()
if current_value is None: #FIRST RUN EVER doesn't have a value we'll just make value 0 so it can be incremented
current_value = 0
new_value = current_value + 1
update_response = requests.put(firebase_config['databaseURL']+counter_path,json=new_value,params={"key": firebase_config["apiKey"]})
if update_response.status_code == 200:
pass
#pdb.gimp_message(new_value) #debug to see incremented value
# TRACKING CODE ENDS ==================================================================================
# =================================================================================================
it defines one function call hit_it() which is called once by the plug-in itself that hits the database and increases a single counter
with TRACKING_VARNAME = 'timertt'
for a different plug-in i would change the timertt to something else.
and then anyone can view these tracked single counters on
GIMP Plug-in Stats UsageIf you plan to use this tracking for other plug-ins it'll work and define the counter the first time you run it as 1 if you define your own TRACKING_VARNAME.
but it won't show up on the above stats page until I add it to the page.
But you can view the TRACKING_VARNAME you're interested in by going to
https://tinmantaken.blogspot.com/2023/11/view-gimp-plug-in-usage-stats.html?var=timertttestjust replace timertttest with your TRACKING_VARNAME value to temporarily see the value before it's hardcode added to the stats page.
There is also commented out line at end of TRACKING CODE that you uncomment and see the value using pdb.gimp_message.
this tracking call is called when the plug-in isn't doing time calculation so the timer functionality is still as accurate as before.