Example #1
0
class GoogleEarth():
    """
    This is a class that starts Google Earth and performs operations
    on the Google Earth window.

    Attributes:
        keyboard_commands : KeyboardCommand class object
        new_width (int) : Width for repositioning Google Earth window
        new_height (int) : Height for repositioning Google Earth window
        desktop_geometry : Available screen geometry based on current resolution
        screen_geometry : Total screen geometry based on current resolution

    Args:
        desktop_geo : Available screen geometry
        screen_geo : Total screen geometry
    """
    def __init__(self, desktop_geo, screen_geo):
        """
        Please see help(GoogleEarth) for more info.
        """
        self.keyboard_commands = KeyboardCommands()

        self.new_width = None
        self.new_height = None

        self.desktop_geometry = desktop_geo
        self.screen_geometry = screen_geo

    def check_process_running(self, process_name):
        """
        Checks if there are any processes currently running that contain a given name.

        Parameters:
            process_name (string) : Name of the process to be checked

        Returns:
            bool: Returns True if process found, else returns False
        """
        # Check if there is any running process that contains the given name processName.
        # Iterate over the all the running process
        for proc in psutil.process_iter():
            try:
                if process_name.lower() in proc.name().lower():
                    return True
            except (psutil.NoSuchProcess, psutil.AccessDenied,
                    psutil.ZombieProcess):
                pass
        return False

    def initialize_google_earth(self):
        """
        Checks if Google Earth is running and starts Google Earth if it is not running.
        Calls toggle_button_off to check if Google Earth toolbar is open.
        """
        #Checking if Google Earth is already running
        if self.check_process_running('google-earth'):
            self.start_google_earth()

        else:
            #Start Google Earth if it is not already running and resize window
            os.system("nohup google-earth-pro </dev/null >/dev/null 2>&1 &")
            time.sleep(2)
            self.start_google_earth()
        # Calls toggle_button_off to check if toolbar open
        self.toggle_button_off()

    def start_google_earth(self):
        """
        Checks if Google Earth is maximized and then sets width and height for positioning
        Google Earth. Repositions Google Earth to upper 3/4 of screen and resizes Google
        Earth to take up width of available screen.
        """
        # Calls check_if_fullscreen to check if Google Earth is maximized
        self.check_if_fullscreen()
        # Calls set_screen_resolution to set new width and height based on current resolution
        self.set_screen_resolution()
        # Sets command to reposition and resize Google Earth window
        comm = "wmctrl -r 'Google Earth' -e 0,0,0," + str(int(self.new_width)) + "," + \
                str(int(self.new_height))
        # Sends command to reposition and resize Google Earth window
        os.system(comm)
        # Pause to make sure command issued successfully
        time.sleep(2)

    def set_screen_resolution(self):
        """
        Sets the Google Earth window width and height values based on monitor resolution.
        """
        # Sets new width for Google Earth based on available screen width
        self.new_width = self.desktop_geometry.width()
        # Sets new height for Google Earth to be 3/4 of available height minus offset
        # for window title
        self.new_height = ((self.desktop_geometry.height() * (3 / 4)) - 37)

    def reposition_earth_small(self):
        """
        Checks if Google Earth is maximized, then repositions and resizes Google Earth to
        have half the width of current available screen space and 3/4 of available screen
        height.
        """
        # Checks if Google Earth is maximized
        self.check_if_fullscreen()
        # Sets command to reposition and resize Google Earth window
        comm = "wmctrl -r 'Google Earth' -e 0,0,0," + str(int(self.new_width / 2)) + "," + \
                str(int(self.new_height))
        # Sends command to reposition and resize Google Earth window
        os.system(comm)
        # Pause to make sure command issued successfully
        time.sleep(2)

    def reposition_earth_large(self):
        """
        Checks if Google Earth is maximized, then repositions and resizes Google Earth to
        have the fulls width of current available screen space and 3/4 of available screen
        height.
        """
        # Checks if Google Earth is maximized
        self.check_if_fullscreen()
        # Sets command to reposition and resize Google Earth window
        comm = "wmctrl -r 'Google Earth' -e 0,0,0," + str(int(self.new_width)) + "," + \
                str(int(self.new_height))
        # Sends command to reposition and resize Google Earth window
        os.system(comm)
        # Pause to make sure command issued successfully
        time.sleep(2)

    def toggle_button_off(self):
        """
        Closes sidebar in Google Earth that cause problems when sending commands
        to the Google Earth window.
        """
        # Checks to see if the Google Earth sidebar is open
        sidebar_coords = self.keyboard_commands.locate_image(
            'images/clicked_sidebar.png')
        # If the sidebar is open, call close_sidebar to close it
        if sidebar_coords:
            self.keyboard_commands.close_sidebar()

    def start_up_tips(self):
        """
        Checks if Start-up Tips widnow is open in Google Earth.

        Returns:
            bool: Returns True if Google Earth Start Up Tips window open, else returns False
        """
        # Checks to see if Google Earth start up tips window is open
        start_up_tips_coords = self.keyboard_commands.locate_image(
            'images/close.png')
        # If the Google Earth start up tips window is open, return True, else False
        if start_up_tips_coords:
            return True
        else:
            return False

    def check_if_fullscreen(self):
        """
        Checks if Google Earth window is maximized, which prevents Google Earth from
        receiving resize commands. If Google Earth window is maximized, minimizes the
        window.
        """
        # Checks if Google Earth window is maximized
        fullscreen = self.keyboard_commands.locate_image(
            'images/fullscreen.png')
        # If the window is maximized, minimizes it
        if fullscreen:
            self.keyboard_commands.click_with_location(fullscreen)
            time.sleep(2)

    def close_earth(self):
        """
        Closes the Google Earth window.
        """
        os.system("wmctrl -c Google Earth Pro")
Example #2
0
class GoogleEarth():
    def __init__(self):
        self.current_command = ''
        self.keyboard_commands = KeyboardCommands()
        self.screen_position = []
        self.resolution = ''

    def check_process_running(self, process_name):
        #Check if there is any running process that contains the given name processName.
        #Iterate over the all the running process
        for proc in psutil.process_iter():
            try:
                # Check if process name contains the given name string.
                if process_name.lower() in proc.name().lower():
                    return True
            except (psutil.NoSuchProcess, psutil.AccessDenied,
                    psutil.ZombieProcess):
                pass
        return False

    def initialize_google_earth(self):

        #Checking if Google Earth is already running
        if self.check_process_running('google-earth'):
            self.start_google_earth()

        else:
            #Start Google Earth if it is not already running and resize window
            os.system("nohup google-earth-pro </dev/null >/dev/null 2>&1 &")
            time.sleep(2)
            self.start_google_earth()

        sidebar_coords = self.keyboard_commands.locate_image(
            'clicked_sidebar.png')

        if sidebar_coords:
            self.keyboard_commands.click_with_location(sidebar_coords)
            time.sleep(2)
            self.keyboard_commands.drag_mouse(80, 200, 1)
            self.keyboard_commands.click_without_location()

        else:
            os.system("wmctrl -a Google Earth Pro")
            sidebar_coords = self.keyboard_commands.locate_image(
                'unclicked_sidebar.png')
            self.keyboard_commands.move_mouse_to_coords(sidebar_coords)
            self.keyboard_commands.drag_mouse(80, 200, 1)
            self.keyboard_commands.click_without_location()

    def start_google_earth(self):
        self.set_screen_resolution()
        comm = "wmctrl -r 'Google Earth' -e 0," + str(int(self.resolution[0])) + "," + \
                str(int(self.resolution[1])) + "," + str(self.screen_position[0]) + "," + \
                str(self.screen_position[1])
        os.system(comm)
        time.sleep(2)

    def set_screen_resolution(self):
        output = subprocess.Popen('xrandr | grep "\*" | cut -d" " -f4',
                                  shell=True,
                                  stdout=subprocess.PIPE).communicate()[0]
        self.resolution = output.split()[0].split(b'x')

        self.screen_position.append(int((int(self.resolution[0]) * (1 / 2))))
        self.screen_position.append(int((int(self.resolution[1]) * (2 / 3))))
        self.resolution[0] = (int(self.resolution[0]) /
                              2) - (self.screen_position[0] / 2)
        self.resolution[1] = (int(self.resolution[1]) /
                              2) - (self.screen_position[1] / 2)

    def get_screen_resolution(self):
        return self.resolution

    def get_screen_position(self):
        return self.screen_position
Example #3
0
class GoogleEarth():
    """
    This is a class that starts Google Earth and performs operations
    on the Google Earth window.

    Attributes:
        keyboard_commands : Instantiates keyboard command class object for sending
            commands to Google Earth
        screen_position (list) : Position values for moving and resizing windows based
            on screen resolution
        resolution (string) : Resolution of the current monitor
    """
    def __init__(self, desktop_geometry):
        """
        Please see help(GoogleEarth) for more info
        """
        self.keyboard_commands = KeyboardCommands()
        self.screen_position = []
        self.screen_resize = []
        self.desktop_geometry = desktop_geometry

    def check_process_running(self, process_name):
        """
        Checks if there are any processes currently running that contain a given name.

        Parameters:
        process_name (string) : Name of the process to be checked

        Returns:
        bool: Returns True if process found, else returns False
        """
        # Check if there is any running process that contains the given name processName.
        # Iterate over the all the running process
        for proc in psutil.process_iter():
            try:
                if process_name.lower() in proc.name().lower():
                    return True
            except (psutil.NoSuchProcess, psutil.AccessDenied,
                    psutil.ZombieProcess):
                pass
        return False

    def initialize_google_earth(self):
        """
        Checks if Google Earth is running and starts Google Earth if it is not running.
        Following start up, closes two Google Earth toolbars.
        """
        #Checking if Google Earth is already running
        if self.check_process_running('google-earth'):
            self.start_google_earth()

        else:
            #Start Google Earth if it is not already running and resize window
            os.system("nohup google-earth-pro </dev/null >/dev/null 2>&1 &")
            time.sleep(2)
            self.start_google_earth()

        self.toggle_buttons_off()

    def start_google_earth(self):
        """
        Gets the current screen resolution and starts Google Earth. Repositions Google Earth
        in the center of the screen with a size determined by the current screen resolution.
        """
        self.set_screen_resolution()

        sidebar_coords = self.keyboard_commands.locate_image('fullscreen.png')

        if sidebar_coords:
            self.keyboard_commands.click_with_location(sidebar_coords)
            time.sleep(2)

        comm = "wmctrl -r 'Google Earth' -e 0,0,0," + str(int(self.screen_resize[0])) + "," + \
                str(int(self.screen_resize[1]))
        os.system(comm)
        time.sleep(2)

    def set_screen_resolution(self):
        """
        Sets the Google Earth window resize and screen position based on monitor resolution.
        """
        #print(self.desktop_geometry.width(), self.desktop_geometry.height())
        self.screen_resize.append(self.desktop_geometry.width())
        self.screen_resize.append(self.desktop_geometry.height() * (3 / 4))

        #print(self.screen_resize[0], self.screen_resize[1])

        self.screen_position.append((self.desktop_geometry.width() / 2))
        self.screen_position.append((self.desktop_geometry.height() / 2))

    def reposition_earth_small(self):
        # REPLACE with hotkey for ALT + F10 to toggle full screen
        sidebar_coords = self.keyboard_commands.locate_image('fullscreen.png')

        if sidebar_coords:
            self.keyboard_commands.click_with_location(sidebar_coords)
            time.sleep(2)

        comm = "wmctrl -r 'Google Earth' -e 0,0,0," + str(int(self.screen_resize[0] / 2)) + "," + \
                str(int(self.screen_resize[1]))
        os.system(comm)
        time.sleep(2)

    def reposition_earth_large(self):
        # REPLACE with hotkey for ALT + F10 to toggle full screen
        sidebar_coords = self.keyboard_commands.locate_image('fullscreen.png')

        if sidebar_coords:
            self.keyboard_commands.click_with_location(sidebar_coords)
            time.sleep(2)

        comm = "wmctrl -r 'Google Earth' -e 0,0,0," + str(int(self.screen_resize[0])) + "," + \
                str(int(self.screen_resize[1]))
        os.system(comm)
        time.sleep(2)

    def toggle_buttons_off(self):
        """
        Toggles two toolbars in Google Earth that cause problems when sending commands
        to the Google Earth window.
        """
        sidebar_coords = self.keyboard_commands.locate_image('close.png')

        if sidebar_coords:
            self.keyboard_commands.click_with_location(sidebar_coords)
            time.sleep(2)

        sidebar_coords = self.keyboard_commands.locate_image(
            'clicked_sidebar.png')

        if sidebar_coords:
            self.keyboard_commands.click_with_location(sidebar_coords)
            time.sleep(2)

    def get_screen_resize(self):
        """
        Returns the values used to resize the Google Earth window.

        Returns:
            resolution (str) : Current Google Earth window size.
        """
        return self.screen_resize

    def get_screen_position(self):
        """
        Returns the Google Earth window X and Y positions.

        Returns:
            screen_position (list) : X and Y positions determined by current screen resolution.
        """
        return self.screen_position

    def close_earth(self):
        """
        Closes the Google Earth window.
        """
        os.system("wmctrl -c Google Earth Pro")