Maya phone number query - python

I'm working on a script that needs a phone number queried from an tex field or int field for maya. I using python and I can't seem to find anything that works. Can you help?
Thanks
TED
Ok This is the mess that I came up with.
def makeTui():
if(cmds.window('window2',q=1,ex=1)):cmds.deleteUI('window2')
cmds.window('window2',menuBar=1)
cmds.formLayout('formLayout1')
cmds.text(label='Phone Number')
num = cmds.intField('textField4',width=100,height=20,changeCommand = num_callback)
cmds.text('text95',label='Service Provider')
cmds.optionMenu('optionMenu1')
cmds.menuItem(label='AT&T')
cmds.menuItem(label='Verizon')
cmds.menuItem(label='Sprint')
cmds.menuItem(label='Cricket')
cmds.menuItem(label='Tmobil')
cmds.iconTextButton('iconTextButton45',parent='formLayout1',image='render.png',command='num_callback()')
cmds.formLayout('formLayout1',e=1,attachForm=[['textField4', 'left', 100], ['text95', 'top', 30], ['optionMenu1', 'top', 30], ['optionMenu1', 'left', 100], ['iconTextButton45', 'left', 100], ['iconTextButton45', 'top', 60]])
cmds.showWindow('window2')
makeTui()
def num_callback():
print cmds.intField(num, q=True, value=True)

You want to define your callback function in the same scope as the UI items - that saves a lot of work in trying to remember the names of the widgets that you need to work on.
def create_ui():
window = cmds.window()
column = cmds.columnLayout(adj=True)
# three items arranged horizontally
row = cmds.rowLayout(nc = 3)
numfield = cmds.textFieldGrp(label = 'phone number')
cmds.text("provider")
provider = cmds.optionMenu()
for p in ('AT&T', 'Verizon', 'Sprint', 'T-Mobile'):
cmds.menuItem(label = p)
cmds.setParent("..")
# define this function here so it knows the widgets for
# the text field and the option menu
def render_button():
phoneno = cmds.textFieldGrp(numfield, q=True, text=True)
# remove any punctuation:
digits =[int(c) for c in phoneno if c.isdigit()]
providername = cmds.optionMenu(provider, q=True, v=True)
print digits, providername
cmds.iconTextButton(image='render.png', c = render_button)
cmds.showWindow(window)
Here the callback function knows the 'names' of the field for entering numbers and the optionmenu for picking providers. The actual work would go into the render_buttons() function. I used a text field, incidentally, since many people will expect to type things like 1(555)111-2222 and an intField wont' allow it.

Related

how to pass the value from checkboxes from one screen to next screen in Urwid?

hi everyone i am new with the urwid. i want to send the values of checkboxes which are selected from checkbox list it will send the next page i want to use these value in my next function how can archive this.below is my code
from urwid import (CheckBox, SimpleListWalker, ListBox, Text, Frame,
MainLoop, ExitMainLoop, connect_signal)
words = ["obelus", "bumfuzzle", "rubaboo", "ballyhoo", "everywhen",
"octothorpe", "meldrop", "sozzled", "pizazz", "pronk"]
palette = [
('reverse','light gray','black'),
('important','dark blue','light gray',('standout','underline')),
('buttn','white','default'),
('buttnf','white','dark blue','bold'),
('h2', 'white,underline,bold', 'dark red'),
('header','white','dark red', 'bold'),
('body', 'default', 'default'),]
def update_footer(widget, state):
footer.set_text(", ".join([checkbox.label
for checkbox in checkboxes
if checkbox.state is True]))
checkboxes = []
for word in words:
checkbox = CheckBox(label=word)
connect_signal(checkbox, "postchange", update_footer)
checkboxes.append(checkbox)
list_walker = SimpleListWalker(contents=checkboxes)
listbox = ListBox(list_walker)
footer = Text(markup="")
print(listbox)
frame = Frame(header=header , body=listbox)
MainLoop(widget=frame).run()

IPython Widgets Separated by Character Rather Than Word

As you can tell in the picture below, the table is separated by characters rather than full words.
def apply(f):
text = f
text = re.sub(r'\W+', ' ', text)
res = LM().check_probabilities(text, topk=20)
l = str(res)
paraphrase_widget = widgets.SelectMultiple(
options=l,
description='Paraphrases',
disabled=False,
layout= widgets.Layout(width='100%')
)
display(paraphrase_widget)
return {"result": res}
apply("In order to")
The issue here is in unpacking pytorch's prediction and passing those results to the widget in proper format (a list of tuples). Here's how you can do that:
# Modify your widget to the following
paraphrase_widget = widgets.SelectMultiple(
options=res['pred_topk'][2],
description='Paraphrases',
disabled=False,
layout= widgets.Layout(width='100%', height="300px")
)
Here's what this looks like for me:

How do I write from a list (each index independently) - within a dictionary - to a list of Entries?

I am setting up a number of Entry fields and trace-variables based on a user inputted integer. The entry information is then store to a list in dictionary.
Two buttons exist: 'enable', which enables the entry-fields for editing but at the same time, fetches the information from the dictionary and displays it on the entry field.
'disable' button clears the entry fields and disables editing. Also updates the dictionary.
The problem is reading each individual entry back into the entry fields with the dictionary looking like this:
dict_test = {'A': ['B', [1, 1], True, {'E': '', 'F': [], 'G': []}]}
I cannot take the individual values of 'F' and display it on the respective entry field when 'enable' is selected.
I know how to access the whole list of 'F' (dict_test['A'][3]['F'])
# User input:
phases = 3
# The Dictionary to which the trace-variables are stored
dict_test = {'A': ['B', [1, 1], True, {'E': '', 'F': [], 'G': []}]}
headings = ["FRa"]
sv = [StringVar() for i in range(phases)] # Holds the Entry inputs
fra_list = []
# The Entry-fields
fra_entries = [Entry(frame, width=10, state=DISABLED, justify=RIGHT, textvariable=sv[i]) for i in range(phases)]
...
enable_button = Button(root, text="Enable", command=lambda: enable())
disable_button = Button(root, text="Disable", command=lambda: disable())
...
def enable():
for i in range(len(fra_entries)):
fra_entries[i].config(state=NORMAL)
sv[i].set(dict_test['A'][3]['F'][i]) # Causes the problem !!!!
def disable():
dict_test['A'][3]['F'] = []
fra_list = []
for i in range(phases):
fra_list.append(sv[i].get())
dict_test['A'][3]['F'].append(fra_list[i])
for i in range(len(fra_entries)):
fra_entries[i].config(state=DISABLED)
sv[i].set("")
The disabled option does its exact function: initializes 'F', re-reads the entries, stores it in dict_test and disables the entries.
'enable', however, shows an 'index out of bounds' error when trying to loop through 'F'
for j in range(len(dict_test['A'][3]['F'])):
sv[j].set(dict_test['A'][3]['F'][j])

getting an iterable value from intslidergrp

I have an intSlidergrp to make a given number of spheres, but the method I tried gives me this error: ''int' object is not iterable' so does anyone know how to make a for-loop out of the info given in the slidergrp.
def givenLights(*args):
wantedLights = cmds.intSliderGrp( sldr2, query=True,value=lights)
print wantedLights
for item in wantedLights:
cmds.polySphere(sx=5, sy=5)
win = cmds.window(title="electrical chords", widthHeight =(300,400),
topLeftCorner= (200,350))
cmds.columnLayout(adj = True, rs=(10))
lights = 0
sldr2 = cmds.intSliderGrp( field=True, value=lights,minValue=0,maxValue=100)
btn6 = cmds.button(label="Allign given lights",command=givenLights)
cmds.showWindow(win)
I found it myself
for i in range(inp):
cmds.polySphere(sx=5, sy=5)
I didn't add the range

How do you retrieve the cell row of a changed QComboBox as a QCellWidget of a QTableWidget?

I am trying to get the row and column of a changed combobox in a QTableWidget.
Here is how my table is set up. Look at the bottom to see what I am trying to do.
def click_btn_mailouts(self):
self.cur.execute("""SELECT s.StudentID, s.FullName, m.PreviouslyMailed, m.nextMail, m.learnersDate, m.RestrictedDate, m.DefensiveDate FROM
StudentProfile s LEFT JOIN Mailouts m ON s.studentID=m.studentID""")
self.all_data = self.cur.fetchall()
self.table.setRowCount(len(self.all_data))
self.tableFields = ["Check","Full name","Previously mailed?","Next mail","learners date","Restricted date","Defensive driving date"]
self.columnList = ["StudentID","FullName","PreviouslyMailed","NextMail","learnersDate","RestrictedDate","DefensiveDate"]
self.table.setColumnCount(len(self.tableFields))
self.table.setHorizontalHeaderLabels(self.tableFields)
self.checkbox_list = []
for i, item in enumerate(self.all_data):
FullName = QtGui.QTableWidgetItem(str(item[1]))
PreviouslyMailed = QtGui.QComboBox()
PreviouslyMailed.addItem("Yes")
PreviouslyMailed.addItem("No")
LearnersDate = QtGui.QTableWidgetItem(str(item[3]))
RestrictedDate = QtGui.QTableWidgetItem(str(item[4]))
DefensiveDate = QtGui.QTableWidgetItem(str(item[5]))
NextMail = QtGui.QTableWidgetItem(str(item[6]))
self.table.setItem(i, 1, FullName)
self.table.setCellWidget(i, 2, PreviouslyMailed)
self.table.setItem(i, 3, LearnersDate)
self.table.setItem(i, 4, RestrictedDate)
self.table.setItem(i, 5, DefensiveDate)
self.table.setItem(i, 6, NextMail)
chkBoxItem = QtGui.QTableWidgetItem()
chkBoxItem.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
chkBoxItem.setCheckState(QtCore.Qt.Unchecked)
self.checkbox_list.append(chkBoxItem)
self.table.setItem(i, 0, self.checkbox_list[i])
FullName.setFlags(FullName.flags() & ~Qt.ItemIsEditable)
NextMail.setFlags(NextMail.flags() & ~Qt.ItemIsEditable)
"""Heres what I am trying to do:"""
PreviouslyMailed.currentIndexChanged.connect(self.comboBox_change(self.table.cellWidget(row,1).currentText()))
"""I want 'row' to be the row that has the combobox that has been changed."""
If I understand correctly, when attaching the signal i will be the value of the row that you want to send (or, maybe i+1?). You can easily send additional data with Qt signals, by using a wrapper function or lambda as follows:
for a in range(5):
x = QComboBox()
x.currentIndexChanged.connect( lambda i: my_other_function(i, another_var) )
Here, we connect the lambda to the signal, and when it is called the internal function will in turn be called with the extra data. This is functionally equivalent to:
def my_wrapper(i):
my_other_function(i, another_var)
for a in range(5):
x = QComboBox()
x.currentIndexChanged.connect( my_wrapper )
But, as you will discover if you try to do this, this doesn't always work. If you try and pass the variable a to the internal function, it will always be set to the value a was at the end of the loop.
for a in range(5):
x = QComboBox()
x.currentIndexChanged.connect( lambda i: my_other_function(i, a) ) # a will always be 4
You can get around this by rebinding the value of a to a new variable each time — the easiest way being passing it in as a named parameter to the lambda. For example —
for a in range(5):
x = QComboBox()
x.currentIndexChanged.connect( lambda i, a=a: my_other_function(i, a) ) # Each combo will send the index, plus the value of a
You should be able to use the above to send the correct value for row for each QComboBox you create.

Categories

Resources