Click Drag Function Maya Python - python

I am trying to write my 1St Maya Python Script......I know I have a ways to go before I don't keep getting dozens of Syntax Errors....But it's a simple script with no UI, and any even tidbits or clues I can get to get it to work will set me off with scripting.
Just a simple fuction of 'Clicking and dragging' visibilities on or off of the Display Layer boxes..the main function I am trying to define is:
draggerContext?
or
cmds.selectPref(clickBoxSize=True)
how to implement the fuction on/off..
any clues would be of help as the trickiest part of this script is defining the Function of CLick Drag select...
Thanks
my script that does not work yet:
import maya.cmds as cmds
#Click and drag to Turn On/Off Visibilities of the Display Layers
draggerContext_id = "dga"
def dga():
cmds.selectPref(clickBoxSize=True)
cmds.selectcmds.selectPref(clickBoxSize=True)
if:
clickdragBoxSize.sel=True(layerEditorLayerButtonVisibilityChange):
cmds.selectPref(clickBoxSize=True)
else:
cmds.select(layerEditorLayerButtonVisibilityChange=True)
SelectLayerEditorButtonVisibility()

Related

Using Python's tk_tools.py led

I need some help with the led option 'on_click_callback=' of the led widget in the module tk_tools.py. Here's what I have:
reactor_led = Led(win, size=50, toggle_on_click=True, on_click_callback=led_clicked(ON))
reactor_led.to_red()
reactor_led.to_green(on=True)
reactor_led.grid()
The led does get displayed properly in its window, and it does react correctly to a mouse click. I've omitted the code for led_clicked, but it is being called when I click the 'led'. The parameter "ON" is the boolean state of the led when clicked, but I can't come up with the actual code to reference that to pass to the call-back function. I need a working example to understand it.
Thanks

using returned value to import module

Im a bit stuck!
Im new to python coding and this is my second project and Ive hit a wall.
basically Ive made a GUI with 12 radio buttons in 3 sets, (3,3,6) plus an "execute" button, plus various other scripts to execute certain GPIO outputs.
what i want is to be able to select 3 options from the GUI and when i hit the "execute" button for it to run the appropriate .py file
i have got it working to return a value from the 3 variables like so:
def sel():
X = dr1.get()
Y = dr2.get()
Z = dr3.get()
return X+Y+Z
this gives me a value for example of "appleorangebanana"
or with different radio buttons selected a value of "applegrapebanana"
all possible returned values have a corresponding .py file saved with its own script.
where im getting stuck is using the returned value to run the right file when i hit the "execute" button
thanks for any help

I need a way to pull values from a text input written in .kv string to a function in my python functions

So I've created a GUI for a program I'm writing, and what I'm currently stuck on is the running of the calculations I want it to perform. I've done everything in Python 3.5, with a Kivy GUI build string to create the tabs (using tabbed panel and screen manager). I've got a button at the bottom of the tab to which this question pertains which says "Calculate" and should be taking the values of the text entries and operating them as part of the equation I want them to do.
Is the
.get
function going to be helpful in this case for doing this, or do I want to call more like:
class TabSys(TabbedPanel):
def calculate_psc_clicked(self):
#when they click the button which is id'd as "calculate_psc," this function
#will pull the values and perform the calculations
self.Cp_entry = self.Cp_entry.text
self.P_entry = self.P_entry.text
self.lhv_entry = self.lhv_entry.text
The above code is the TabSys class for my build string in kivy language, after it comes the
class nyce_meemApp(App):
def build(self):
return TabSys()
if __name__ == '__main__':
nyce_meemApp().run()
To actually run all the code. I don't want to inundate the question with code, so I'll leave it there, and I can put up any other pieces of code that anybody wants (if need be I can share the file).
Thanks

Python: win32gui.SetForegroundWindow

I have just written simple script to launch an applciation and I am trying to use "SendKeys" module to send keystrokes to this application. There is one "Snapshot" button, but I cant get Python to click "Snapshot" button, as the new window is not in focus. So I am planning to use Win32gui module's win32gui.FindWindow and win32gui.SetForegroundWindow functionality. But it gives me error- invalid handle. My app name is "DMCap"
Here is code snippet in Python:
handle = win32gui.FindWindow(0, "DMCap") //paassing 0 as I dont know classname
win32gui.SetForegroundWindow(handle) //put the window in foreground
Can anyone help me? Is this Python code correct? Can I send handle directly like this?
Your code should run just fine as-is, IF there is truly a window titled "DMCap." To get a list of handles and titles, run the code below:
import win32gui
def window_enum_handler(hwnd, resultList):
if win32gui.IsWindowVisible(hwnd) and win32gui.GetWindowText(hwnd) != '':
resultList.append((hwnd, win32gui.GetWindowText(hwnd)))
def get_app_list(handles=[]):
mlst=[]
win32gui.EnumWindows(window_enum_handler, handles)
for handle in handles:
mlst.append(handle)
return mlst
appwindows = get_app_list()
for i in appwindows:
print i
This will produce a list of tuples containing handle, title pairs.

Detecting Close Scene or Change Scene

HI I'm working with Pyqt4 to make a UI in Maya, but I want that the UI close or refresh when the user open or change Scene.
Is there a way in python to detect this change?
scriptJob is what you need.
The following might with some customization might be helpful.
import maya.cmds as cmds
def refresher():
# the function which does the closing/refreshing
pass
cmds.scriptJob(e=["NewSceneOpened", refresher])
cmds.scriptJob(e=["SceneOpened", refresher])
cmds.scriptJob(e=["flushingScene", refresher])

Categories