Getting brain boggled on menu creation

Discussions on extending SharpCap using the built in Python scripting functionality
Post Reply
tmnathe
Posts: 21
Joined: Fri Jul 29, 2022 4:13 am

Getting brain boggled on menu creation

#1

Post by tmnathe »

I'm neck deep in getting this silly command line menu selection working and just getting widely confused with all the different options.
So I need some help.

For now, I'm just setting up a selection of menu choices that set my mounts tracking rate.

Here's the current code, with comment markers where things go wrong.
Thanks in advance!

# import time
# import datetime
import clr
import os
import sys
# import array

# print("\n")
# print ("Ironpython Version ") + str(sys.version)
# print("\n")

print("Tracking Choices:\n 1 - Sidereal\n 2 - Lunar\n 3 - Solar\n 4 - None")

x=(1, 2, 3, 4) # <- Things go wrong here

print("Enter Tracking Choice: ") (+ int(x)) # <- Not sure what to do here

choices_dict = {1: 'Sidereal', 2: 'Lunar', 3: 'Solar', 4: 'None'}

enter(x=int(x))

print(choices_dict.get(x, 'Only Numbers 1 through 4, please.'))

if int(1):
SharpCap.Mounts.SelectedMount.TrackingRate.Sidereal

elif int(2):
SharpCap.Mounts.SelectedMount.TrackingRate.Lunar

elif int(3):
SharpCap.Mounts.SelectedMount.TrackingRate.Solar

elif int(4):
SharpCap.Mounts.SelectedMount.TrackingRate.None

else:
print("Not a number between 1 through 4")
User avatar
admin
Site Admin
Posts: 13348
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Getting brain boggled on menu creation

#2

Post by admin »

Hi,

before jumping in with detailed changes to the code, from the look of it, I think you are expecting to interact with the code in the python editor window in the way that old-style basic programs used to work - ie...

Program prints

Code: Select all

Enter tracking choice :
You type

Code: Select all

2<ENTER>
and at this point the code will spot that 2 is 'Lunar' and set the tracking rate.

Now, the python way to get the value from the user is to use the 'input' function - ie

Code: Select all

x = input()
But... I just tried this and it doesn't work currently - it gives an error

Code: Select all

LookupError: unknown encoding: codepage___0
I will investigate to see if I can work out why that is happening (and if I can fix it), but unless I do get that working, you are kind of stuck.

cheers,

Robin
tmnathe
Posts: 21
Joined: Fri Jul 29, 2022 4:13 am

Re: Getting brain boggled on menu creation

#3

Post by tmnathe »

Oh wow, you mean that I managed to bumble my way into a bug? I guess that's pretty cool.

I'm not beholden to any one thing, I'm just learning Python and just barely understanding what I'm doing. So I really do appreciate your patience with a newbie like me.
But I'll apply what changes you mentioned and patiently wait on your guru magic.

Thanks!
Tom Nather
tmnathe
Posts: 21
Joined: Fri Jul 29, 2022 4:13 am

Re: Getting brain boggled on menu creation

#4

Post by tmnathe »

Hi Brian

Figured out part of the problem (after scouring other Python forums).

Instead of using x=input(), use x=raw_input().

Now I'm getting a little further. But instead of the program stopping to allow user input, it marches right along to the end of the program. I think that has something to do with how I have the dictionary set up and the following if-elif-else statements are set up. I just typed them in, knowing there might be problems.

Further debugging is in progress.

Tom
User avatar
admin
Site Admin
Posts: 13348
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Getting brain boggled on menu creation

#5

Post by admin »

Hi Tom,

ah, interesting... I think you must be using SharpCap 4.0, since the results you are reporting are different to those I was seeing in 4.1... In fact I've checked and raw_input() does give something in 4.0, but doesn't wait. In 4.1 it is not usable (because of changes between python 2.7 and 3.4).

The underlying problem though is the same... In both cases the editing window is not wired up to feed things that you type to python's input/raw_input functions, so you either get an empty string back and it doesn't wait in some cases, or you get an error.

I haven't yet worked out a way to connect up the two parts in a workable way, so I don't think you can count on input() or raw_input() working properly in the near future, sorry :(

If you want simple input functionality to do things like change the tracking rate, you can add custom buttons to the toolbar in scripting. You can see a simple example of a custom button that will open the first camera here : viewtopic.php?p=712#p712

cheers,

Robin
tmnathe
Posts: 21
Joined: Fri Jul 29, 2022 4:13 am

Re: Getting brain boggled on menu creation

#6

Post by tmnathe »

Thanks, Robin!

Yes, I am using 4.0 (just checked). I didn't know about 4.1.

But, it looks like I'll have to learn to do custom buttons sooner than I wanted to (I was hoping to understand that command syntax first by using command line prompts). But that's ok, it's just another layer to the learning process.

But thank you again for looking into that.

Tom
Post Reply