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.

How to use global variable to set Fullscreen status?

If you have a question or need help, this is the place to be.
Post Reply
molitar
Experienced User
Posts: 209
Joined: Fri Sep 11, 2009 6:44 am

How to use global variable to set Fullscreen status?

Post by molitar »

Ok since I lost my old code from drive crash I can't remember for the life of me how I used global variable. I need to create a variable global for Fullscreen so when I toggle Fullscreen I toggle status of Fullscreen. That way I can run a If Fullscreen = "True" then enable Show OSD on Display 2 macro. How can I do this in EventGhost because for the life of me I can't remember how I did this before. If their was only some easier way to check if screen is in fullscreen or not because when it is my video is displayed on the secondary display.
molitar
Experienced User
Posts: 209
Joined: Fri Sep 11, 2009 6:44 am

Re: How to use global variable to set Fullscreen status?

Post by molitar »

Playing with an old code on forum I got a method to get windows state.

Code: Select all

from win32gui import GetWindowPlacement
#SW_SHOWNORMAL = 1
#SW_SHOWMINIMIZED = 2
#SW_SHOWMAXIMIZED = 3
FindWin = eg.WindowMatcher(None, None, u'MediaPlayerClassicW' , None, None, None, True, 0.0, 0)
hwnd = FindWin()
def GetWindowStatus(hwnd):
    showList  = (None, "Normal", "Minimized", "Maximized")
    placement = GetWindowPlacement(hwnd)
    
    if placement[4] == (1671, 1050, 2951, 1770):
        return "Fullscreen"
    else:
        return showList[placement[1]]

eg.globals.Fullscreen = GetWindowStatus(hwnd[0])
print "Window Status = " + eg.globals.Fullscreen
Now when I try to do a check against the eg.globals.Fullscreen by doing a...

If eg.globals.fullscreen = "Fullscreen":
print Fullscreen

all I get is error message.. how can I use the variable to do an if statement? The above was for a test.. Also if I wanted to run another macro by using the if statement how can I make a call to another macro for example 'Fullscreen without resolution' macro?
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: How to use global variable to set Fullscreen status?

Post by Pako »

Why are you here did not put the copy of error message?
Perhaps it is wrong to only letter "f".
Your term should be correct as follows:

Code: Select all

if eg.globals.Fullscreen == "Fullscreen":
Pako
molitar
Experienced User
Posts: 209
Joined: Fri Sep 11, 2009 6:44 am

Re: How to use global variable to set Fullscreen status?

Post by molitar »

I thought so but I get error message..

Error in Action: "if eg.globals.Fullscreen == "Fullscreen": "
Traceback (most recent call last) (1387):
File "<string>", line 1
if eg.globals.Fullscreen == "Fullscreen":
^
SyntaxError: unexpected EOF while parsing

Ok not sure what I did to change the error I moved the location of the line for the assigning the value of the eg.globals.Fullscreen variable and it is now happy.. Moved it from above the if placement to below it and in front of the print. The error went away and appears to be working fine now.
Last edited by molitar on Wed Jan 27, 2010 6:25 am, edited 1 time in total.
molitar
Experienced User
Posts: 209
Joined: Fri Sep 11, 2009 6:44 am

Re: How to use global variable to set Fullscreen status?

Post by molitar »

Ok I figured out my problem.. the code was right but after I did the line..

print "Window Status = " + eg.globals.Fullscreen

it would lose it's global variable so that is the reason the error code was comming up.. changed the line location where I assign the global variable and it's working perfectly now.

Code: Select all

from win32gui import GetWindowPlacement

#SW_SHOWNORMAL = 1
#SW_SHOWMINIMIZED = 2
#SW_SHOWMAXIMIZED = 3

FindWin = eg.WindowMatcher(None, None, u'MediaPlayerClassicW' , None, None, None, True, 0.0, 0)
hwnd = FindWin()

def GetWindowStatus(hwnd):
    showList  = (None, "Normal", "Minimized", "Maximized")
    placement = GetWindowPlacement(hwnd)
   
    if placement[4] == (1671, 1050, 2951, 1770):
        return "Fullscreen"
    else:
        return showList[placement[1]]

eg.globals.WindowsState = GetWindowStatus(hwnd[0])
print "Windows State = " + eg.globals.WindowsState
Now I have almost a perfect script with this check windows state macro before calling any of my toggles it now remains in the proper state as well as I can now determine where the OSD display needs to show. Only one other thing could perfect my script and that is.. Is their a method to determine which Display screen a window is showing on? If so I could than do script that will not matter where the exact coordinates of the window is to determine if the display is fullscreen. Currently I had to print the placement to get the value for place[4] to determine if windows is maximized or not, but if I could just check if the display is showing on Display 0 or Display 1 that would be a more efficient method to determine if I am in fullscreen or not.
Post Reply