I am at my wits end on debugging this script. I have accessed multiple AI sites and Python forums in an effort to "debug" this script. As far as I can determine, the script is correct/valid; however, I get inconsistent results when I execute it using the most current version of SharpCap (4.1.13621). Sometimes the menu shows on top and other times I have to minimize the application to see the menu. I also get a number of syntax errors even when the syntax is correct. I only use spaces for indentation and have confirmed that there are no "tabs" in the indentation process. I previously had problems with SharpCap which were fixed with the addition of SHARPCAP_APPLICATION. However, there are no SharpCap references in this script and I cannot "import" SHARPCAP_APPLICATION. I am relatively new to Python so don't claim to be a "programmer" per se.
I realize this is a big request but could someone take a look at my script and help me fix it so that it runs consistently in SharpCap? Many thanks in advance.
Script Does Not Execute Consistently - Invalid Syntax Errors
Script Does Not Execute Consistently - Invalid Syntax Errors
- Attachments
-
- Perplexity Automated If-Then-Goto Session Controller4.py
- (14.36 KiB) Downloaded 36 times
Re: Script Does Not Execute Consistently - Invalid Syntax Errors
I got some additional help on this request. Attached is the corrected script. Thanks to anyone who took the time to read my post.
- Attachments
-
- Perplexity Automated If-Then-Goto Session Controller4.py
- (15.78 KiB) Downloaded 29 times
- admin
- Site Admin
- Posts: 17610
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: Script Does Not Execute Consistently - Invalid Syntax Errors
Hi,
the best thing for debugging this sort of problem is to add print() statements at key points in the code so that you see progress as you run it - i.e.
Also, while you are testing remove the loops so that the code just runs once - less chance of getting stuck.
When I ran through it, I noticed that the InputBox window would appear sometimes in front of SharpCap and sometimes behind. Sometimes it would be hiding behind the script window. This problem occurs because the InputBox function doesn't have a way to specify the 'parent' window to attach the input box to (Windows always sit in front of their parent window). Anyway, this is tricky because SharpCap doesn't have a nice way for scripting to get the value required if you were using a function that had that option (like MessageBox.Show in System.Windows.Forms).
I suspect that the inconsistency is mostly the input window sometimes hiding behind other windows and sometimes not. For any inconsistent syntax errors, make sure you test with a fresh run of SharpCap each time - sometimes the script may not like running on top of the definitions left behind by the previous run.
cheers,
Robin
the best thing for debugging this sort of problem is to add print() statements at key points in the code so that you see progress as you run it - i.e.
Code: Select all
print('about to display input box')
When I ran through it, I noticed that the InputBox window would appear sometimes in front of SharpCap and sometimes behind. Sometimes it would be hiding behind the script window. This problem occurs because the InputBox function doesn't have a way to specify the 'parent' window to attach the input box to (Windows always sit in front of their parent window). Anyway, this is tricky because SharpCap doesn't have a nice way for scripting to get the value required if you were using a function that had that option (like MessageBox.Show in System.Windows.Forms).
I suspect that the inconsistency is mostly the input window sometimes hiding behind other windows and sometimes not. For any inconsistent syntax errors, make sure you test with a fresh run of SharpCap each time - sometimes the script may not like running on top of the definitions left behind by the previous run.
cheers,
Robin
- admin
- Site Admin
- Posts: 17610
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: Script Does Not Execute Consistently - Invalid Syntax Errors
Oops, actually I missed the obvious... If you have a way to pass in a parent window into (for example) System.Windows.Forms.MessageBox.Show, the value to pass is
If you need a raw HWND (window handle) for some other API,
cheers,
Robin
Code: Select all
SharpCap.MainWindow
Code: Select all
SharpCap.MainWindow.Handle
Robin
Re: Script Does Not Execute Consistently - Invalid Syntax Errors
Thanks again for the advice!