It is easy to get the highligted range in the time slider using:
import maya.cmds as cmds
import maya.mel as mel
aTimeSlider = mel.eval('$tmpVar=$gPlayBackSlider')
timeRange = cmds.timeControl(aTimeSlider, q=True, rangeArray=True)
Likewise the Qt widget can be accessed with
from maya import mel
from maya import OpenMayaUI as omui
try:
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from PySide2 import __version__
from shiboken2 import wrapInstance
except ImportError:
from PySide.QtCore import *
from PySide.QtGui import *
from PySide import __version__
from shiboken import wrapInstance
widgetStr = mel.eval( 'string $tempString = $gPlayBackSlider' )
ptr = omui.MQtUtil.findControl( widgetStr )
timeSliderWidget = wrapInstance(long(ptr), QWidget)
However, setting the highlighted range programmatically of the time slider seems nearly impossible. Is there really no way?
I was thinking that there may be a way to modify the Qt widget, but I'm lost on this one.
EDIT:
It is the highlighted range I'm trying to set programmatically.
This seems to be the same question as this question.
I posted a hacky workaround there as an answer.
Posting it here too for completeness sake: Here's the biggest hacky workaround there is. Using Qt Mouse press, move and release events to mimic the mouse behavior on the time slider widget to have it select.
In code I'm temporarily changing the time slider range to maximize the screen space for the frames I want to click on.