Re: Using Python3 for Superkaramba

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Michele Calgaro via tde-users wrote on 9/28/22 22:39:
In fact, Superkaramba has been so stable for so long that I forget how all the various .theme and .py files interact.

I do see at least one *.py file that begins with
     #!/usr/bin/env superkaramba
and contains a python2 print statement. Commenting out the print statement doesn't seem to change anything, though.

Where do I go to provide details?

     Doc Evans


Hi Doc Evans,
python2 is phasing out (sloooooowly, but it is), so I guess the script in question may need to be updated to py3.
If it is something you can share, please send it through and I will take a look.

Attached is the .py file in question. It's essentially SKSlideShow.py (which also crashes now) with relatively minor changes to get it to work properly (I made the changes in the year 2017) on my system. It's worked fine since 2017.

  Doc

--
Web:  http://enginehousebooks.com/drevans
#!/usr/bin/env superkaramba
# coding: utf-8

# Copyright N7DR

# Released under GPLv2

# Based on SkSlideShow, which, at least on my system, doesn't properly allow multiple
# images on a single desktop

#this import statement allows access to the karamba functions
import datetime
import karamba
import os
import random

# configuration

kuickshow = "/opt/trinity/bin/kuickshow"

lri = 0

# global variables
border_width = 18
border_height = 16
# Theme anchor
# - TL (Top Left)
# - TM (Top Middle)
# - TR (Top Right)
# - ML (Middle Left)
# - MM (Middle Middle)
# - MR (Middle Right)
# - BL (Bottom Left)
# - BM (Bottom Middle)
# - BR (Bottom Right)
theme_anchor = 'MM'
# Theme aspect
# - W : Fit Image Width to Theme Size
# - H : Fit Image Height to Theme Size
# - B : Fit the biggest size to Theme Size
theme_aspect = 'B'
theme_size = 200
theme_width = 236
theme_height = 182

theme_dir = 'aero-g'

#Global Image files pointer
image=0

#Borders images
top_left_corner=0
top_right_corner=0
bottom_left_corner=0
bottom_right_corner=0
top_border=0
bottom_border=0
left_border=0
right_border=0

theme_dir_pid = 0
theme_anchor_pid = 0
theme_aspect_pid = 0

full_image_file_name = ""
directories = []
frequencies = []
n_updates = 0

directory_from_config = "/home/n7dr/misc/superkaramba/themes/N7DR-slideshow/tux"
directory_from_config_pid = 0

display_frequency = str(1)
display_frequency_pid = 0

handle_str = str(random.randint(0, 10000))

debug_file = open("/home/n7dr/misc/superkaramba/themes/N7DR-slideshow/debug-" + handle_str + ".txt", 'w', 1)
debug_file.close()
debug_file_name = ""

#this is called when your widget is initialized
def initWidget(widget):
    global debug_file, \
    debug_file_name, \
    directories, \
    directory_from_config, \
    display_frequency, \
    frequencies, \
    full_image_file_name, \
    image, \
    kuickshow, \
    handle_str, \
    top_left_corner, \
    top_right_corner, \
    bottom_left_corner, \
    bottom_right_corner, \
    top_border, \
    bottom_border, \
    left_border, \
    right_border, \
    theme_dir, \
    theme_anchor, \
    theme_aspect   

    directory_from_config = get_configuration_value(widget, "directory_from_config", directory_from_config)
    display_frequency = get_configuration_value(widget, "display_frequency", display_frequency)
        
#    debug_file.write("cwd: " + os.getcwd() +"\n")
#    debug_file.write("directory_from_config: " + directory_from_config + "\n")    
#    debug_file.write("display_frequency: " + display_frequency + "\n")    
   
#    debug_file.close()
    
#    debug_file = open("/home/n7dr/tmp/superkaramba/themes/N7DR-slideshow/debug.new", 'w')    
            
    karamba.addMenuConfigOption(widget, "directory_from_config", "Images directory")
    karamba.addMenuConfigOption(widget, "display_frequency", "Display frequency (min)")
    
    directory = directory_from_config
    dlist = directory.split("/")
    term = dlist[len(dlist) - 1]
    debug_file_name = "/tmp/" + term + ".txt"
    
    debug_file = open(debug_file_name, 'w', 1)
            
    full_image_file_name = get_full_image_file_name(directory)
    
    debug_file.write("full_image_file_name: " + full_image_file_name + "\n") 
    
    debug_file.write("started at: " + str(datetime.datetime.now()) + "\n")
    
    debug_file.close()
    
#    debug_file = open("/home/n7dr/tmp/superkaramba/themes/N7DR-slideshow/debug.new", 'w')    
    
#Load Background image
    top_left_corner=karamba.createImage(widget,0,0,"images/"+theme_dir+"/top_left_corner.png")
    top_right_corner=karamba.createImage(widget,218,0,"images/"+theme_dir+"/top_right_corner.png")
    bottom_left_corner=karamba.createImage(widget,0,166,"images/"+theme_dir+"/bottom_left_corner.png")
    bottom_right_corner=karamba.createImage(widget,218,166,"images/"+theme_dir+ "/bottom_right_corner.png")
    top_border=karamba.createImage(widget,18,0,"images/"+theme_dir+"/top_border.png")
    bottom_border=karamba.createImage(widget,18,166,"images/"+theme_dir+"/bottom_border.png")
    left_border=karamba.createImage(widget,0,16,"images/"+theme_dir+"/left_border.png")
    right_border=karamba.createImage(widget,218,16,"images/"+theme_dir+"/right_border.png")

#Load in a first image and display on screen
    load_random_image(widget)
        
#    debug_file.write("random image loaded: " + str(image) + "\n")

#        debug_file.close()
    
#        debug_file = open("/home/n7dr/tmp/superkaramba/themes/N7DR-slideshow/debug.new", 'w')    
       
        
#Atach ClickArea to new image and execute kuickshow with the current displayed image
    cmd = kuickshow + " \"" +  full_image_file_name + "\""
    karamba.attachClickArea(widget, image, cmd)
    karamba.redrawWidget(widget)

#    debug_file.write("Done initialising!")
#    debug_file.close()
	#pass

#This is called when your widget is closed.  You can use this to clean
#up open files, etc.  You don't need to delete text and images in your
#theme.  That is done automatically.  This callback is just for cleaning up
#external things.  Most people don't need to put anything here.
def widgetClosed(widget):
    global debug_file
    
    debug_file.close()
#    pass


#this is called every time your widget is updated
#the update inverval is specified in the .theme file
def widgetUpdated(widget):
    global debug_file_name, frequency, n_updates, directories, frequencies, debug_file, kuickshow, full_image_file_name, image, directory_from_config

    debug_file = open(debug_file_name, 'a', 1)
    debug_file.write("widget updated: " + str(datetime.datetime.now()) + "\n")
    debug_file.close()

#    debug_file = open("/home/n7dr/tmp/superkaramba/themes/N7DR-slideshow/debug.updated", 'w')  
#    debug_file.write("Inside the widgetUpdated() function; one more line to write\n")
#    debug_file.write("about to load random image\n") 
    
#    debug_file = open("/home/n7dr/tmp/superkaramba/themes/N7DR-slideshow/debug.updated.new", 'w')  
    
#    n_updates += 1

    directory = directory_from_config
    
#    debug_file.write("directory = " + directory + "\n")
#        debug_file.write("n_updates modulo frequency = " + str(n_updates % frequency) + "\n")

#    debug_file.close()
    
#    debug_file = open("/home/n7dr/tmp/superkaramba/themes/N7DR-slideshow/debug.updated.new.1", 'w')  

       
 #       if n_updates % frequency == 0:
    full_image_file_name = get_full_image_file_name(directory)

    load_random_image(widget)	
    
#    debug_file.close()
    
#Atach ClickArea to new image and execute kuickshow with the current displayed image


    cmd = kuickshow + " \"" +  full_image_file_name + "\""
    
    karamba.attachClickArea(widget, image, cmd)
    karamba.redrawWidget(widget)
    
#    debug_file.close()
    
#    pass

#This gets called everytime our widget is clicked.
#Notes:
#  widget = reference to our widget
#  x = x position (relative to our widget)
#  y = y position (relative to our widget)
#  botton = button clicked:
#                    1 = Left Mouse Button
#                    2 = Middle Mouse Button
#                    3 = Right Mouse Button, but this will never happen
#                        because the right mouse button brings up the
#                        Karamba menu.
#                    4,5 = Scroll wheel up and down
def widgetClicked(widget, x, y, button):
    pass

#This gets called everytime our widget is clicked.
#Notes
#  widget = reference to our widget
#  x = x position (relative to our widget)
#  y = y position (relative to our widget)
#  botton = button being held:
#                    0 = No Mouse Button
#                    1 = Left Mouse Button
#                    2 = Middle Mouse Button
#                    3 = Right Mouse Button, but this will never happen
#                        because the right mouse button brings up the
#                        Karamba menu.
def widgetMouseMoved(widget, x, y, button):
    #Warning:  Don't do anything too intensive here
    #You don't want to run some complex piece of code everytime the mouse moves
    pass


#This gets called when an item is clicked in a popup menu you have created.
#  menu = a reference to the menu
#  id = the number of the item that was clicked.
def menuItemClicked(widget, menu, id):
    pass

#This gets called when an item is clicked in the theme CONFIGURATION menu,
#not the popup menus that you create.
#  key = the reference to the configuration key that was changed
#  value = the new value (true or false) that was selected
def menuOptionChanged(widget, key, value):
    global directory_from_config_pid, frequency_pid
    
    if (key == "directory_from_config"):
        cscol = ["kdialog", "--getexistingdirectory", directory_from_config]
        directory_from_config_pid = karamba.executeInteractive(widget, cscol)
        
    if (key == "display_frequency"):
        cscol = ["kdialog", "--radiolist", "Display frequency:", "1", "1 minute", "on", "5", "5 minutes", "off", "15", "15 minutes", "off"]
        frequency_pid = karamba.executeInteractive(widget, cscol)

#    pass

#This gets called when a meter (image, text, etc) is clicked.
# NOTE you must use attachClickArea() to make a meter
# clickable.  
#  widget = reference to your theme
#  meter = the meter clicked
#  button = the button clicked (see widgetClicked for button numbers)
def meterClicked(widget, meter, button):
    pass

#This gets called when a command you have executed with executeInteractive() outputs something
#to stdout.  This way you can get the output of for example kdialog without freezing up the widget
#waiting for kdialog to end.
#  widget = reference to your theme
#  pid = process number of the program outputting (use this if you execute more than out process)
#  output = the text the program outputted to stdout
def commandOutput(widget, pid, output):
    global directory_from_config_pid, frequency_pid
    
    if (pid == directory_from_config_pid):
        karamba.writeConfigEntry(widget, "directory_from_config", output[0:len(output)-1])
        karamba.reloadTheme(widget)             # reads new config file

    if (pid == frequency_pid):
        karamba.writeConfigEntry(widget, "display_frequency", output[0:len(output)-1])
        karamba.reloadTheme(widget)

#    pass

#This gets called when another theme sends a message.
#  widget = reference to your theme
#  caller = "pretty" name or regular name (name of theme file with a number attached) of sending theme
#  output = the text sent.
def themeNotify(widget, caller, message):
    pass

#This gets called when an item is dropped on this widget.
# NOTE you have to call acceptDrops() before your widget will accept drops.
#  widget = reference to your theme
#  dropText = the text of the dropped item (probably a URL to it's location in KDE)
#  x = the x position on the theme relative to the upper left corner
#  y = the y position on the theme relative to the upper left corner
def itemDropped(widget, dropText, x, y):
    pass


#This gets called when a new program is LOADING in KDE.  When it is done
#loading, startupRemoved() is called, followed by taskAdded().
#  widget = reference to your widget
#  task = A refence to the task that is starting.  
def startupAdded(widget, startup):
    pass

#This gets called when a new program is done LOADING in KDE.
#  widget = reference to your widget
#  task = A refence to the task that just finished loading.  
def startupRemoved(widget, startup):
    pass

#This is called every time a new task (program) is started in KDE.
#  widget = reference to your widget
#  task = A refence to the new task.  Call getTaskInfo() with this reference
#         to get the name, etc of this new task.
def taskAdded(widget, task):
    pass

#This is called everytime a task (program) is closed in KDE.
#  widget = reference to your widget
#  task = A refence to the task.  
def taskRemoved(widget, task):
    pass

#This is called everytime a different task gains focus (IE, the user clicks
#on a different window).  
#  widget = reference to your widget
#  task = A refence to the task.  Call getTaskInfo() with this reference
#         to get the name, etc of this new task.
def activeTaskChanged(widget, task):
    pass

#This is called everytime the systray you created with createSystray() is updated
def systrayUpdated(widget):
    pass

#This is called everytime the current desktop changes
#  widget = reference to your widget
#  desktop = the current desktop
def desktopChanged(widget, desktop):
    pass

#This is called everytime the wallpaper changes on a desktop 
#  widget = reference to your widget
#  desktop = the desktop whose wallpaper changed
def wallpaperChanged(widget, desktop):
    pass

#This is called everytime there is a key press in any focused input field
#  widget = reference to your widget
#  meter = reference to an input box
#  char = the key that was pressed
def keyPressed(widget, meter, char):
    pass

#This function loads a random image from a defined list and checks to see
#if the aspect ratio of the image is near 4:3 and also if it has a resonable size
#and deletes it if not valide it also resize its to the widget size and puts it off screen

def load_random_image(widget): #returns long pointer to a valide image
    global lri, debug_file, full_image_file_name, image, top_left_corner, top_right_corner, bottom_left_corner, bottom_right_corner, top_border, bottom_border, left_border, right_border, theme_aspect, theme_size, theme_anchor, border_width, border_height, theme_width, theme_height
	
#    debug_file.write("inside load_random_image(): " + str(lri) + "\n")
    lri += 1

#    debug_file.close()
    
#    debug_file = open("/home/n7dr/tmp/superkaramba/themes/N7DR-slideshow/debug.new", 'w')    


#    debug_file.write("image: " + str(image) + "\n")

#    debug_file.close()
    
#    debug_file = open("/home/n7dr/tmp/superkaramba/themes/N7DR-slideshow/debug.new", 'w')    


    if image > 0:
        karamba.deleteImage(widget, image)
        image=0
    
#    debug_file.write("creating image: " + str(border_width) + ":" + str(border_height) + ":" + full_image_file_name + "\n")

#    debug_file.close()
    
#    debug_file = open("/home/n7dr/tmp/superkaramba/themes/N7DR-slideshow/debug.new", 'w')    



    image=karamba.createImage(widget, border_width, border_height, full_image_file_name)
    image_height=karamba.getImageHeight(widget, image)
    image_width=karamba.getImageWidth(widget, image)
    
#    debug_file.write("finished defining image parameters\n")

#    debug_file.close()
    
#    debug_file = open("/home/n7dr/tmp/superkaramba/themes/N7DR-slideshow/debug.new", 'w')    

		
						
	#Use convert to resize the image so it is smaller in memory and faster doing resize animations
	
    desired_width = 0
    desired_height = 0
	
    if theme_aspect == 'W':
        desired_width = theme_size
        desired_height = ( ( theme_size * image_height ) / image_width )
    else:
        if theme_aspect == 'H':
            desired_width = ( ( theme_size * image_width ) / image_height )
            desired_height = theme_size
        else:
            if image_width > image_height:
                desired_width = theme_size
                desired_height = ( ( theme_size * image_height ) / image_width )
            else:
                desired_width = ( ( theme_size * image_width ) / image_height )
                desired_height = theme_size

    karamba.resizeImage(widget, image, desired_width, desired_height)
	
    karamba.resizeImage(widget, top_border, desired_width, border_height)
    karamba.resizeImage(widget, left_border, border_width, desired_height)
    karamba.resizeImage(widget, right_border, border_width, desired_height)
    karamba.resizeImage(widget, bottom_border, desired_width, border_height)
	
    karamba.moveImage(widget, right_border, desired_width + border_width, border_height)
    karamba.moveImage(widget, bottom_border, border_width, desired_height + border_height)
    karamba.moveImage(widget, top_right_corner, desired_width + border_width, 0)
    karamba.moveImage(widget, bottom_right_corner, desired_width + border_width, desired_height + border_height)
    karamba.moveImage(widget, bottom_left_corner, 0, desired_height + border_height)
	
    (pos_x, pos_y) = karamba.getWidgetPosition(widget)
	
    if ( (theme_anchor == 'TL') or (theme_anchor == 'ML') or (theme_anchor == 'BL') ):
        pos_x = pos_x
    else:
        if ( (theme_anchor == 'TM') or (theme_anchor == 'MM') or (theme_anchor == 'BM') ):
            pos_x = (pos_x + (theme_width / 2) - (desired_width / 2) - border_width)
        else:
            pos_x = (pos_x + theme_width - desired_width - (2 * border_width))

    if ( (theme_anchor == 'TL') or (theme_anchor == 'TM') or (theme_anchor == 'TR') ):
        pos_y = pos_y
    else:
        if ( (theme_anchor == 'ML') or (theme_anchor == 'MM') or (theme_anchor == 'MR') ):
            pos_y = (pos_y + (theme_height / 2) - (desired_height / 2) - border_height)
        else:
            pos_y = (pos_y + theme_height - desired_height - (2 * border_height))
	
    karamba.moveWidget(widget, pos_x, pos_y)
	
    theme_width = (desired_width + (2 * border_width))
    theme_height = (desired_height + (2 * border_height))
	
    karamba.resizeWidget(widget, theme_width, theme_height)

def get_full_image_file_name(directory): #returns the full name for an image file, given a directory
    global debug_file
    
#    debug_file.write("Inside get_full_image_file_name() for directory " + directory + "\n")
    
#    debug_file.close()
    
#    debug_file = open("/home/n7dr/tmp/superkaramba/themes/N7DR-slideshow/debug.new", 'w')    
    
    files_this_directory = []
        
# get all the image files in this directory
#    for root, dirs, files in os.walk(directory):
#        for this_file in files:
#            debug_file.write("Found file " + this_file + "\n")

#    debug_file.close()
    
#    debug_file = open("/home/n7dr/tmp/superkaramba/themes/N7DR-slideshow/debug.new", 'w')    

    for root, dirs, files in os.walk(directory):
        for this_file in files:
            if os.path.getsize(directory + "/" + this_file) != 0:
                if this_file.endswith(".jpg") or this_file.endswith(".png"):
                    files_this_directory.append(this_file)
#                    debug_file.write("Added: " + directory + "/" + this_file + "\n")

#    debug_file.close()
    
#    debug_file = open("/home/n7dr/tmp/superkaramba/themes/N7DR-slideshow/debug.new", 'w')    
                
    image_file_name = files_this_directory[random.randint(0, len(files_this_directory) - 1)]
        
    return (directory + "/" + image_file_name)

def get_configuration_value(widget, name, current_value = None):
    global debug_file
    
#    debug_file.write("Inside get_configuration_value for " + name + "\n")
    
    if current_value is None:
        if (karamba.readConfigEntry(widget, name)):
#            debug_file.write("Returning value\n")
            return (karamba.readConfigEntry(widget, name))
        else:
#            debug_file.write("Reuruning empty string\n")
            return ("")
    else:
        if (karamba.readConfigEntry(widget, name)):
            current_value = karamba.readConfigEntry(widget, name)
#            debug_file.write("current value now: " + current_value + "\n")
            return (karamba.readConfigEntry(widget, name))
        return (current_value)

# This will be printed when the widget loads.
#print "Loaded my python extension!"
____________________________________________________
tde-users mailing list -- users@xxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxx
Web mail archive available at https://mail.trinitydesktop.org/mailman3/hyperkitty/list/users@xxxxxxxxxxxxxxxxxx

[Index of Archives]     [Trinity Devel]     [KDE]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]     [Trinity Desktop Environment]

  Powered by Linux