• Dear visitors,

    The email issue has been finally solved.
    Thank you for your patience and happy browsing.

    Team ACM.

Struggling with first app

MrRalphMan

New Member
Hi all,

I trying to create a simple app, but falling at the first hurdle.

I first create the most simple app, just the three imports, acmain and setting the app with header and size.

This initially works, but if I do something simple, such as some functions, it stops loading with no errors in pylog.txt.
I then try deleting the folder and non of the python apps load.

It's odd as the log.txt shows that it has 18 apps to load and they all fail.
What's really odd it shows the previous three attempts, which have been deleted, so AC or CM is holding an idea on them.

When I first tried, I got sim info loaded and it was all working, with any errors in the pylog.txt, but now nothing.

What I did get when it stopped working was the following error in log. Txt.

ERROR: Python ERROR LOADING MODULE :sys.path.append(<app path>).


Not on my pc now, but can certainly get more info for tomorrow.

Paul
 

fughettaboutit

aka leBluem aka Please Stop This
when loading "sim_info.py"
you also need the ctype libs imported correctly first
you probably miss those?
stdlib\_ctypes.pyd
stdlib64\_ctypes.pyd

an app that has them, just copy from there:
 

MrRalphMan

New Member
Thanks for the reply, I did have these in place.

It seems that it will work and then I change one line, like add a ac.log and it all falls apart.

Currently my other apps are working, but I just get the ever helpful.

ERROR: Python ERROR LOADING MODULE :sys.path.append('apps/python/desktopSwitcher')

Here is the code as it is, as it's crazy how it just breaks and gives me no info.


Python:
#Import required modules
import sys
import os
import os.path
import platform
if platform.architecture()[0] == "64bit":
    sysdir=os.path.dirname(__file__)+'/lib/stdlib64'
else:
    sysdir=os.path.dirname(__file__)+'/lib/stdlib'
sys.path.insert(0, sysdir)
os.environ['PATH'] = os.environ['PATH'] + ";."

import ac
import acsys
import configparser
import traceback

#from lib.sim_info_cbv import sm
from module.debug import debug

from lib.pyaccsharedmemory import accSharedMemory
asm = accSharedMemory()
sm = asm.read_shared_memory()
                          
#Variables
desktop = 1
currentSession = -1

#Fields
toggleAppSizeButton = None
lbl_desktop = None
lbl_session = None
appWindow = None

#Session Types
#1 - Practice
#2 - Qualify
#3 - Race
#4 - Hotlap
#5 - Time Attack
#6 - Drift
#7 - Drag

choice_1 = ""
choice_2 = ""
choice_3 = ""
choice_4 = ""

settingsSection = "general"

min_win_x = 200
min_win_y = 80
max_win_x = 200
max_win_y = 200
minimised = True

def acMain(ac_version):
    #Global Variables
    global currentSession, desktop
    #App Window
    global appWindow
    #Global Fields
    global lbl_desktop, lbl_session, toggleAppSizeButton
    #Screen fields
    global min_win_x, min_win_y, max_win_x, max_win_y, minimised
    
  
    #Set up window
    appWindow = ac.newApp("desktopSwitcher")
    
    ac.setSize(appWindow, min_win_x, min_win_y)
    
    
    
    #Get Session
    currentSession = sm.Graphics.session
    ac.log('desktopSwitcher: currentSession in acMain = ' + str(currentSession))

    
    #Add fields to form
    
    #Current Desktop
    lbl_desktop = ac.addLabel(appWindow, "Current Desktop = " + str(desktop))
    ac.setPosition(lbl_desktop,3,30)
    
    lbl_session = ac.addLabel(appWindow, "Current Session = " + returnSessionName(currentSession))
    ac.setPosition(lbl_session,3,50)
    
    toggleAppSizeButton = ac.addButton(appWindow, "+")
    ac.setPosition(toggleAppSizeButton, 170, 30)
    ac.setSize(toggleAppSizeButton, 20, 20)
    ac.addOnClickedListener(toggleAppSizeButton, onToggleAppSizeButtonClickedListener)
    
    
    #Dropdowns for selecting Session type
    lst_desktop1 = ac.addListBox(appWindow, "lst_desktop_1")
    ac.setPosition(lst_desktop1, 3, 70)
    ac.addItem(lst_desktop1,"Practice")
    ac.addItem(lst_desktop1,"Qualify")
    ac.addItem(lst_desktop1,"Race")
    ac.addItem(lst_desktop1,"Hotlap")
    ac.addItem(lst_desktop1,"Time attack")
    ac.addItem(lst_desktop1,"Drift")
    ac.addItem(lst_desktop1,"Drag")
    
    lst_desktop2 = ac.addListBox(appWindow, "lst_desktop_2")
    ac.setPosition(lst_desktop2, 3, 90)
    ac.addItem(lst_desktop2,"Practice")
    ac.addItem(lst_desktop2,"Qualify")
    ac.addItem(lst_desktop2,"Race")
    ac.addItem(lst_desktop2,"Hotlap")
    ac.addItem(lst_desktop2,"Time attack")
    ac.addItem(lst_desktop2,"Drift")
    ac.addItem(lst_desktop2,"Drag")
    
    lst_desktop3 = ac.addListBox(appWindow, "lst_desktop_3")
    ac.setPosition(lst_desktop3, 3, 110)
    ac.addItem(lst_desktop3,"Practice")
    ac.addItem(lst_desktop3,"Qualify")
    ac.addItem(lst_desktop3,"Race")
    ac.addItem(lst_desktop3,"Hotlap")
    ac.addItem(lst_desktop3,"Time attack")
    ac.addItem(lst_desktop3,"Drift")
    ac.addItem(lst_desktop3,"Drag")
    
    lst_desktop4 = ac.addListBox(appWindow, "lst_desktop_4")
    ac.setPosition(lst_desktop4, 3, 130)
    ac.addItem(lst_desktop4,"Practice")
    ac.addItem(lst_desktop4,"Qualify")
    ac.addItem(lst_desktop4,"Race")
    ac.addItem(lst_desktop4,"Hotlap")
    ac.addItem(lst_desktop4,"Time attack")
    ac.addItem(lst_desktop4,"Drift")
    ac.addItem(lst_desktop4,"Drag")
    
    getSettings()
    
    
    return "desktopSwitcher"
    
def acUpdate(deltaT):
    #Global Variables
    global currentSession, desktop
    #Global Fields
    global lbl_desktop, lbl_session
    
    session = sm.Graphics.session
    if session != currentSession:
        currentSession = session;
        ac.setText(lbl_session, "Current session: {}".format(returnSessionName(currentSession)))
        
    
def returnSessionName(sessionID):
    if sessionID == 0:
        return "Practice (" + str(sessionID) + ")"
    elif sessionID == 1:
        return "Qualify (" + str(sessionID) + ")"
    elif sessionID == 2:
        return "Race (" + str(sessionID) + ")"
    elif sessionID == 3:
        return "Hotlap (" + str(sessionID) + ")"
    elif sessionID == 4:
        return "Time Attack (" + str(sessionID) + ")"
    elif sessionID == 5:
        return "Drift (" + str(sessionID) + ")"
    elif sessionID == 6:
        return "Drag (" + str(sessionID) + ")"
    else:
        return "Unknown (" + str(sessionID) + ")"
    
def getSettings():
    #Add global variables
    global choice_1, choice_2, choice_3, choice_4
    global desktop
    
    #setup config
    try:
        FilePath = os.path.dirname(__file__)+'/settings/settings.ini'
        if not os.path.isfile(FilePath):
            with open(FilePath, "w") as sf:
                debug("Settings file created")
        settingsParser = configparser.ConfigParser()
        settingsParser.optionxform = str
        settingsParser.read(FilePath)

        desktop = int(getSettingsValue(settingsParser, settingsSection, "desktop", -1))
        choice_1 = str(getSettingsValue(settingsParser, settingsSection, "choice_1", "na"))
        choice_2 = str(getSettingsValue(settingsParser, settingsSection, "choice_2", "na"))
        choice_3 = str(getSettingsValue(settingsParser, settingsSection, "choice_3", "na"))
        choice_4 = str(getSettingsValue(settingsParser, settingsSection, "choice_4", "na"))

        with open(FilePath, 'w') as settingsFile:
             FilePath.write(settingsFile)
        return True
    except exception:
        debug("Error while loading settings : " + traceback.format_exc())
        return False
        
def getSettingsValue(parser, section, option, value, boolean = False):
    if parser.has_option(str(section), str(option)):
        if boolean:
            return parser.getboolean(str(section), option)
        else:
            return parser.get(str(section), str(option))
    else:
        return setSettingsValue(parser, section, option, value)


def setSettingsValue(parser, section, option, value):
    if not parser.has_section(section):
        parser.add_section(section)

    parser.set(str(section), str(option), str(value))
    return value
    
def onToggleAppSizeButtonClickedListener(*args):
    global minimised, toggleAppSizeButton
    ac.log("desktopSwitcher: minimised = " + str(minimised))

    minimised = not minimised
    if minimised:
        ac.setText(toggleAppSizeButton, "+")
    else:
        ac.setText(toggleAppSizeButton, "-")

    updateUIVisibility()
    
def updateUIVisibility():
    #Screen fields
    global appWindow
    global min_win_x, min_win_y, max_win_x, max_win_y, minimised
    global lst_desktop1, lst_desktop2, lst_desktop3, lst_desktop4

    if minimised:
        ac.setSize(appWindow, min_win_x, min_win_y)
        ac.setVisible(lst_desktop1, False)
        ac.setVisible(lst_desktop2, False)
        ac.setVisible(lst_desktop3, False)
        ac.setVisible(lst_desktop4, False)
    else:
        ac.setSize(appWindow, max_win_x, max_win_y)
        ac.setVisible(lst_desktop1, True)
        ac.setVisible(lst_desktop2, True)
        ac.setVisible(lst_desktop3, True)
        ac.setVisible(lst_desktop4, True)
 

fughettaboutit

aka leBluem aka Please Stop This
strange, you know python is quite serious about white spaces
ie you should not mix tabs and spaces
9051


9050


btw using "VisualStudio Code" editor here
 

MrRalphMan

New Member
Also I changed this line from

ac.log("desktopSwitcher: minimised = " + str(minimised))
to
ac.setText(lbl_session, "Current session: {}".format(returnSessionName(currentSession)))

And this stopped all my Python apps from loading, and changing it back does not fix it..

Arrrghhh
 

MrRalphMan

New Member
Ok, I am calming down now.. Seems that I have gotten to a place where I don't destroy my Python apps every time.

I have a question around the acUpdate function, does this only update when you are moving along the track? What triggers it?

Paul
 

MrRalphMan

New Member
This is my acUpdate() and it's not firing, or at least I'm not getting any output.
Python:
def acUpdate(deltaT):
    #Global Variables
    global currentSession, desktop
    #Global Fields
    global lbl_desktop, lbl_session
    
    session = sm.graphics.session
    ac.log("desktopSwitcher: acUpdate, session = " + str(session))
    if session != currentSession:
        currentSession = session;
        ac.setText(lbl_session, "Current session 2: {}".format(returnSessionName(currentSession)))
Paul
 

MrRalphMan

New Member
Hey dude, thank you.

Python is not my first language.. :(

Of course I changed this and python apps don't load anymore.

After having to kill CM and restart, the apps are working, but I'm still not seeing anything changing

Should have the ac.log command worked in acUpdate? Just so I know it's working.

Paul
 
Top