Exposure & Gain

Discussions on extending SharpCap using the built in Python scripting functionality
User avatar
1CM69
Posts: 63
Joined: Tue Nov 14, 2017 9:49 pm

Re: Exposure & Gain

#21

Post by 1CM69 »

admin wrote: Mon Aug 20, 2018 6:58 pm How about

Code: Select all

	def get_EV():
		exp =  SharpCap.SelectedCamera.Controls.Exposure.ExposureMs/1000
		if exp > 50:
			return str(format(exp, '.0f')) + "(s)"
		else:
			return str(exp)
			
	def btnLE_Click(self, sender, event):
		if SharpCap.SelectedCamera != None:
			self.lbl.LEv.Text = get_EV()
		else:
			SharpCap.ShowNotification('No Camera Selected! Please Select A Camera.')

Basically this way your get_EV() function returns a value rather than trying to set a global variable (which I'm not sure would work), then you just use the value returned from the function - much cleaner.

cheers,

Robin
Hi Robin,
thanks for replying
still getting the error: global name 'get_EV' is not defined though

Cheers

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

Re: Exposure & Gain

#22

Post by admin »

Probably best to post your whole script then so we can have a look at the whole thing.

cheers,

Robin
User avatar
oopfan
Posts: 1320
Joined: Sat Jul 08, 2017 2:37 pm
Location: New York
Contact:

Re: Exposure & Gain

#23

Post by oopfan »

I think the compiler wants a "this" pointer.

Try calling "self.get_EV()"

Brian
User avatar
1CM69
Posts: 63
Joined: Tue Nov 14, 2017 9:49 pm

Re: Exposure & Gain

#24

Post by 1CM69 »

admin wrote: Mon Aug 20, 2018 8:09 pm Probably best to post your whole script then so we can have a look at the whole thing.

cheers,

Robin
Hi Robin,

here is my script as it stands & by no means finished yet:
GUI.txt
(7.16 KiB) Downloaded 152 times
Basically my attempt was to contain all the conditional if..elif..else statement in a separate function that I could call from each of the eventual 4 button clicks (only LUM setup at the mo), thus cutting down coding.

I am totally new to Python but normally code in C# & know that it is possible to simply call a function/method from inside another function to get/pass parameters. For some reason I am not getting it in Python.

The eventual saving of lines of code here probably isn't worth worrying about, just me trying to do as much as possible :D

Cheers..,

Kirk
oopfan wrote: Mon Aug 20, 2018 8:43 pm I think the compiler wants a "this" pointer.

Try calling "self.get_EV()"

Brian
Thanks for the tip Brian, I tried it & sort of got somewhere after chasing down other errors but I think I made a right pig's ear of it.
User avatar
admin
Site Admin
Posts: 13122
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Exposure & Gain

#25

Post by admin »

Hi Kirk,

I was thinking that you could share the version with the get_EV() function that doesn't quite work - having a look at that would probably let myself or Brian work out what's gone wrong fairly quickly.

cheers,

Robin
User avatar
1CM69
Posts: 63
Joined: Tue Nov 14, 2017 9:49 pm

Re: Exposure & Gain

#26

Post by 1CM69 »

OK, sorry.

I’m away from my PC now but basically that test script is identical to the txt file I’ve just posted except I have pasted over the

Code: Select all

def btnLE_Click
section with the second lot of code wrapped in the <code> block from my earlier post including the get_EV function.

If you do need me to post up the actual full script I can do that in the morning.

Regards..,

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

Re: Exposure & Gain

#27

Post by admin »

Hi Kirk,

I think this is what you need

Code: Select all

	def get_EV(self):
		exp =  SharpCap.SelectedCamera.Controls.Exposure.ExposureMs/1000
		if exp > 50:
			return str(format(exp, '.0f')) + "(s)"
		else:
			return str(exp)
			
	def btnLE_Click(self, sender, event):
		if SharpCap.SelectedCamera != None:
			self.lblLEv.Text = self.get_EV()
		else:
			SharpCap.ShowNotification('No Camera Selected! Please Select A Camera.')
Note both the self.get_EV() and the (self) parameter to the get_EV method. All seems a bit clunky from a C++/C# point of view, but that's the way Python works....

cheers,

Robin
User avatar
oopfan
Posts: 1320
Joined: Sat Jul 08, 2017 2:37 pm
Location: New York
Contact:

Re: Exposure & Gain

#28

Post by oopfan »

Note both the self.get_EV() and the (self) parameter to the get_EV method. All seems a bit clunky from a C++/C# point of view, but that's the way Python works....
Actually Python is a cool language. What Kirk ought to do is to put get_EV() in global scope. He currently has it as a member function of his Form class. Just cut and paste it outside the class.

If Udemy online classes are available in the UK they have some good courses in Python, currently costing only 9.99 USD in their back-to-school sale.

https://www.udemy.com/topic/python/

Brian
User avatar
1CM69
Posts: 63
Joined: Tue Nov 14, 2017 9:49 pm

Re: Exposure & Gain

#29

Post by 1CM69 »

admin wrote: Tue Aug 21, 2018 3:32 pm Hi Kirk,

I think this is what you need

Code: Select all

	def get_EV(self):
		exp =  SharpCap.SelectedCamera.Controls.Exposure.ExposureMs/1000
		if exp > 50:
			return str(format(exp, '.0f')) + "(s)"
		else:
			return str(exp)
			
	def btnLE_Click(self, sender, event):
		if SharpCap.SelectedCamera != None:
			self.lblLEv.Text = self.get_EV()
		else:
			SharpCap.ShowNotification('No Camera Selected! Please Select A Camera.')
Note both the self.get_EV() and the (self) parameter to the get_EV method. All seems a bit clunky from a C++/C# point of view, but that's the way Python works....

cheers,

Robin
Thanks Robin, that's perfect, works a charm. I really appreciate your help.

cheers..,

Kirk
oopfan wrote: Tue Aug 21, 2018 4:28 pm
Note both the self.get_EV() and the (self) parameter to the get_EV method. All seems a bit clunky from a C++/C# point of view, but that's the way Python works....
Actually Python is a cool language. What Kirk ought to do is to put get_EV() in global scope. He currently has it as a member function of his Form class. Just cut and paste it outside the class.

If Udemy online classes are available in the UK they have some good courses in Python, currently costing only 9.99 USD in their back-to-school sale.

https://www.udemy.com/topic/python/

Brian
Hi Brian,

thanks for replying, I took your advice & placed the function outside the form class.

I guess the language thing is subjective & just what you get used to but since starting this script I can see far more that I wish to do with it and'll definitely need to check out the link you've posted.

cheers..,

Kirk
User avatar
oopfan
Posts: 1320
Joined: Sat Jul 08, 2017 2:37 pm
Location: New York
Contact:

Re: Exposure & Gain

#30

Post by oopfan »

Hi Kirk,

I've been programming with C, C++, C# beginning in 1985. These days I much prefer Python and JavaScript. I've found that you can be much more expressive with weakly-typed languages. You pay the price of execution speed unfortunately.

Brian
Post Reply