Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Check if Excel is running within a plugin

If you have a question or need help, this is the place to be.
Post Reply
Diabl0570
Posts: 30
Joined: Sun Feb 28, 2010 6:05 pm

Check if Excel is running within a plugin

Post by Diabl0570 »

hello,

i'm working on a plugin, in that plugin i want to check if excel is running
here is my code for so far:

Code: Select all

class ifExcelIsRunning(eg.ActionBase):

	def __call__(self):
		eg.globals.Excel_Check="false"
		eg.globals.ActiveMacro="Excel"
		alOpen=eg.plugins.Window.FindWindow(u'EXCEL.EXE', None, None, None, None, None, False, 0.0, 0)
		print alOpen
		print eg.plugins.Window.BringToFront()
		eg.plugins.MyNewPlugin.LogFileHandler("Excel is al geopend!")
		import win32gui
		Check_if_open = win32gui.MessageBox(0, "Error: \\nin order to run this marco successfully \\nyou need to close all open excel projects, \n\n do you want to close Excel now?", "Warning!!!!", 1)
		if Check_if_open == 1:
			eg.plugins.MyNewPlugin.LogFileHandler("Excel Word gesloten")
			eg.globals.Excel_Check="true"
			eg.plugins.Window.FindWindow(u'EXCEL.EXE', None, None, None, None, None, False, 0.0, 0)
			eg.plugins.Window.BringToFront()
			eg.plugins.Window.Close()
			win32gui.MessageBox(0, "Kies eerst of u het bestand wilt opslaan, en klik daarna pas hier verder!!", "Warning!!!!", 1)
		if eg.globals.Excel_Check == "false":
			eg.plugins.EventGhost.TriggerEvent(u'Excel_Vars', 0.0)
		else: 
			print "wacht op antwoord, sluit excel?"
			eg.plugins.MyNewPlugin.LogFileHandler("File found moving on to the next action")
			eg.plugins.EventGhost.TriggerEvent(u'Excel_Check', 0.0)
	
this code gives no errors, now i want to add:
when FindWindows didn't find the window cancel this action.

if i edit the this action in eventghost, there is a option for this but this doesn't work if i use it in a plugin
am i doing something wrong or is there another check if FindWindow is true or false?
i already tryed things like:

Code: Select all

		eg.globals.ActiveMacro="Excel"
		alOpen=eg.plugins.Window.FindWindow(u'EXCEL.EXE', None, None, None, None, None, True, 0.0, 0)
		print alOpen
		print eg.plugins.Window.BringToFront()
this all give as result "None"
Who can help me with my problem ?

Thanks in advanced!
stottle
Plugin Developer
Posts: 636
Joined: Sun Apr 26, 2009 10:59 pm

Re: Check if Excel is running within a plugin

Post by stottle »

If I understand correctly, wouldn't the following work (the if/return at the end)?

Code: Select all

   def __call__(self):
      eg.globals.Excel_Check="false"
      eg.globals.ActiveMacro="Excel"
      alOpen=eg.plugins.Window.FindWindow(u'EXCEL.EXE', None, None, None, None, None, False, 0.0, 0)
      if len(alOpen) == 0:
           return
Brett
miljbee
Experienced User
Posts: 146
Joined: Fri Mar 27, 2009 1:29 pm
Location: Orl├®ans, France

Re: Check if Excel is running within a plugin

Post by miljbee »

If I remember well, I read somewhere that plugins should never affect eg.globals vars. I don't remember exactly where I read this, and I haven't the skills required to understand why it might be right or wrong ....

Do you know ?
miljbee
TCP Events : A Better Network Event Sender/Receiver Plugin.
The Network Event Sender/Receiver in C#
Get events in EG from Google Calendar.
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Check if Excel is running within a plugin

Post by Pako »

Bitmonster wrote:No plugin should ever assign something to eg.globals or change anything in it. Never!
The eg.globals namespace is exclusive for the user's Python scripts and commands.
If your plugin wants to publish variables to the user, the preferred way is to implement getter actions, that simply return the value.
This way the user can also easily see all informations your plugin can provide.
Notes for plugin developers
Posted: Fri Aug 28, 2009 9:37 pm

Pako
miljbee
Experienced User
Posts: 146
Joined: Fri Mar 27, 2009 1:29 pm
Location: Orl├®ans, France

Re: Check if Excel is running within a plugin

Post by miljbee »

ok, but what is the risk of doing it ?!

I am currently working on something. It might be a plugin. It will absolutely need to assign eg.globals vars. So what will happen ? will my computer implode ?!
miljbee
TCP Events : A Better Network Event Sender/Receiver Plugin.
The Network Event Sender/Receiver in C#
Get events in EG from Google Calendar.
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Check if Excel is running within a plugin

Post by Pako »

miljbee wrote:ok, but what is the risk of doing it ?!
I am currently working on something. It might be a plugin. It will absolutely need to assign eg.globals vars. So what will happen ? will my computer implode ?!
It is possible that the answer you expect from me.
Unfortunately I do not know the exact reasons. I'm not Bitmonster.
But Bitmonster certainly knew very well what he wrote.
I do not think that your computer will explode, but on the other hand, I do not understand the reasons why you do not respect this simple principle.
BTW: I expect your comments to filter feature in the Log Redirector plugin.
Pako
miljbee
Experienced User
Posts: 146
Joined: Fri Mar 27, 2009 1:29 pm
Location: Orl├®ans, France

Re: Check if Excel is running within a plugin

Post by miljbee »

BTW: I expect your comments to filter feature in the Log Redirector plugin.
I saw it, but didn't took the time to try it. Sorry !
Don't worry, I will let you know how cool it is as soon I will use it.

Thank you very much !

BTW: Did you take a look at the Google Calendar script ? ;-)
miljbee
TCP Events : A Better Network Event Sender/Receiver Plugin.
The Network Event Sender/Receiver in C#
Get events in EG from Google Calendar.
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Check if Excel is running within a plugin

Post by Pako »

miljbee wrote:BTW: Did you take a look at the Google Calendar script ? ;-)
Yes, I noticed this post.
But my life is so simple that I do not need Google Calendar.
And that's why I have not had cause to deal with the script.
Pako
stottle
Plugin Developer
Posts: 636
Joined: Sun Apr 26, 2009 10:59 pm

Re: Check if Excel is running within a plugin

Post by stottle »

miljbee wrote:ok, but what is the risk of doing it ?!

I am currently working on something. It might be a plugin. It will absolutely need to assign eg.globals vars. So what will happen ? will my computer implode ?!
Python/EG are so flexible I have a hard time believing that the only way to solve a problem is to do something Bitmonster says never to do. Have you considered other options?

Brett
miljbee
Experienced User
Posts: 146
Joined: Fri Mar 27, 2009 1:29 pm
Location: Orl├®ans, France

Re: Check if Excel is running within a plugin

Post by miljbee »

stottle wrote:
miljbee wrote:ok, but what is the risk of doing it ?!

I am currently working on something. It might be a plugin. It will absolutely need to assign eg.globals vars. So what will happen ? will my computer implode ?!
Python/EG are so flexible I have a hard time believing that the only way to solve a problem is to do something Bitmonster says never to do. Have you considered other options?

Brett
Ok, he says never ever. Sorry, I shouldn't have asked why not !

But, you are right, I will try to see things differently, to leave eg.globals outside my plugin.
miljbee
TCP Events : A Better Network Event Sender/Receiver Plugin.
The Network Event Sender/Receiver in C#
Get events in EG from Google Calendar.
Post Reply