"""
This is a demonstration file to explain how to
use a generic action.

#. Open the Preferences and look in the *Configurable Actions* section for the name
   *Demo: open folder pythonUserExtensions*.
   Set an unused keyboard key for that action, apply the changes and exit the Preferences;
#. By using the specified action key, a file explorer will be opened at the *pythonUserExtensions* folder.

:author: ORS Team
:contact: http://theobjects.com
:email: info@theobjects.com
:organization: Object Research Systems (ORS), Inc.
:address: 760 St-Paul West, suite 101, Montréal, Québec, Canada, H3C 1M4
:copyright: Object Research Systems (ORS), Inc. All rights reserved 2020.
:date: Sep 29 2017 11:43
:dragonflyVersion: 3.1.0.307 (D)
:UUID: f08fc3a6a52c11e7a50e448a5b5d70c0
"""

__version__ = '1.0.0'

import os
import subprocess

from ORSServiceClass.actionAndMenu.action import Action
from ORSServiceClass.actions.genericaction import GenericAction
from ORSServiceClass.system.pathServices import OrsPath


class DemoGenericAction_f08fc3a6a52c11e7a50e448a5b5d70c0(GenericAction):

    @classmethod
    def getState(cls):
        """
        If applicable, specify here the specific state in which the action can be executed.
        """
        return ''

    @classmethod
    def getTitle(cls):
        """
        If applicable, specify here the string to display for this action.
        """
        return 'Demo: open folder pythonUserExtensions'

    @classmethod
    def getAction(cls):
        anAction = Action(enterAction='DemoGenericAction_f08fc3a6a52c11e7a50e448a5b5d70c0.executeEnterAction()',
                          action='DemoGenericAction_f08fc3a6a52c11e7a50e448a5b5d70c0.executeAction()',
                          exitAction='DemoGenericAction_f08fc3a6a52c11e7a50e448a5b5d70c0.executeExitAction()')
        return anAction

    @classmethod
    def executeEnterAction(cls):
        """
        Will be executed once when action starts.
        """
        directoryToOpen = os.path.join(OrsPath.getPythonUserRoot())
        commandToExecute = 'explorer "{}"'.format(directoryToOpen)
        subprocess.Popen(commandToExecute)

    @classmethod
    def executeAction(cls):
        """
        Will be executed repetitively when action is maintained.
        """
        pass

    @classmethod
    def executeExitAction(cls):
        """
        Will be executed once when action ends.
        """
        pass

