Using pyqt4 and python 2.6, I am using a qcombobox to provide a list of options. I am having problems with using the selected option. I have been able to use a signal to trigger a method when the option is selected, but the problem is that when the user clicks run, the contents of several of these comboboxes need to be taken into account. So basically I need to get the selected contents of a combobox as a string. Thus far I have only been able use this:
print combobox1.currentText()
to get this:
PyQt4.QtCore.QString(u'Test Selection2')
when all I really want is the 'Test Selection' bit, any ideas?
My combo box was made like this:
combobox1 = qt.QComboBox()
combobox1.addItems(['Test Selection1', 'Test Selection2'])
mainLayout.addWidget(combobox1, 0, 0)
You can convert the QString type to python string by just using the str
function. Assuming you are not using any Unicode characters you can get a python
string as below:
text = str(combobox1.currentText())
If you are using any unicode characters, you can do:
text = unicode(combobox1.currentText())
Getting the Text of ComboBox when the item is changed
self.ui.comboBox.activated.connect(self.pass_Net_Adap)
def pass_Net_Adap(self):
print str(self.ui.comboBox.currentText())
PyQt4 can be forced to use a new API in which QString is automatically converted to and from a Python object:
import sip
sip.setapi('QString', 2)
With this API, QtCore.QString class is no longer available and self.ui.comboBox.currentText() will return a Python string or unicode object.
See Selecting Incompatible APIs from the doc.
If you want the text value of a QString object you can use the __str__ property, like this:
>>> a = QtCore.QString("Happy Happy, Joy Joy!")
>>> a
PyQt4.QtCore.QString(u'Happy Happy, Joy Joy!')
>>> a.__str__()
u'Happy Happy, Joy Joy!'
Hope that helps.
Related
I'm trying to manipulate the dict output that showing in the html page using Flask and Jinja2 template.
I'm looking for help with
Adding new lines between every dict values.
make http text clickable for https://example.com:8087
The way I created my dictionary is
usedPort[node][z_port] = (z_owner, docker_stack, url)
The expectation of the result is
john_doe
Zeppelin-Engineer-Individual-TAP
https://example.com:8087
But actually, I got
(john_doe, Zeppelin-Engineer-Individual-TAP, https://example.com:8087)
There's nothing involved print operation, I don't want to print the output in the terminal but want to show this dict value in the html page instead.
for http text, I've tried with webbrowser module unfortunately, It didn't work.
You are using a tuple, and you do not tell how you display it. If you simply pass the tuple to something that displays it (be it print or anything else) it will use the default representation, which is what you get.
Instead, pass what you want to actually represent:
'\n'.join(str(x) for x in my_tuple) # Can use use `'\n'.join(my_tuple) if everything is a string
For some overkill you can define your own set (using collection.UserTuple or just inheriting from tuple which could create some problems for some uses)
class Tuple(tuple):
def __repr__(self)
return '\n'.join(str(x) for x in self)
The you would have to use Tuple(...) instead of just (...), but be default you would get newlines between values anywhere.
Sorry if this is really basic, I cannot find a workaround. I have a variable called doc that stores the number 510 that was copied from an excel cell.
I need to type it in a field, but I need to continue typing in another field on the same page afterwards.
My code has:
type(doc)
The log shows:
[log] TYPE "510#ENTER."
The full code looks like this:
type(doc)
wait(1)
type(Key.DOWN)
type(Key.BACKSPACE+Key.BACKSPACE+Key.BACKSPACE+Key.BACKSPACE)
wait(1)
type(code)
However, I can't get to the type(code) because it switches page before I get there...
Using paste() maybe solved your issue here but this is not the right way to do that as Sikuli does not automatically presses any buttons.
Your problem is probably with the doc variable itself. In your case, you probably just copied the new line character with your variable from excel and that's why Sikuli is hitting Enter. To avoid that, try stripping the new line from your variable prior to typing it, like this:
doc.rstrip()
Then do your usual type(doc) and it should be fine.
Another thing that works is: doc.strip()
It turns out sikuli writes /n after strings, so strip removes that /n.
I ran this example code with 2 polyCubes in scene.
import pymel.core as pymel
pymel.select('pCube1', 'blinn1')
print pymel.ls(sl = True)
print pymel.ls(sl = True)[0]
and this is my output
[nt.Transform(u'pCube1'), nt.Blinn(u'blinn1')]
pCube1
I know the elements inside this list are PyNodes, but printing them gives out a string type name of the node. Is there anyway to access the PyNode directly from this list?
Found the answer myself.
So apparently the Script Editor returns a representation of PyNode when we print it. Like it's an overloaded str. It is still a PyNode but looks like a string only in Maya's Script Editor. To make it actually appear like a PyNode, we have to use repr() or enclose in back-ticks (`)
Here is the link where I found the answer.
: http://download.autodesk.com/us/maya/2011help/pymel/tutorial.html
Formatting: Read Me First to Avoid Confusion section
This is a WebSphere related question.
I am trying to turn this command into variables
AdminConfig.modify('(cells/taspmociias204Cell01/clusters/cam_group|resources.xml#J2EEResourceProperty_1324400045826)'
I've found that this command:
AdminConfig.list('J2EEResourceProperty', 'URL*cam_group*)').splitlines()
Will return:
['URL(cells/taspmociias204Cell01/clusters/cam_group|resources.xml#J2EEResourceProperty_1324400045826)', 'URL(cells/taspmociias204Cell01/clusters/cam_group|resources.xml#J2EEResourceProperty_1355156316906)']
So I turned that command into a variable:
j2ee = AdminConfig.list('J2EEResourceProperty', 'URL*cam_group*)').splitlines()
And i'm able to get the string that I want by typing "j2ee[0]" I get
'URL(cells/taspmociias204Cell01/clusters/cam_group|resources.xml#J2EEResourceProperty_1324400045826)'
So that is exactly what I wanted, minus the URL part in the front. How can I get rid of those characters?!
I'm not sure if I understood your requirement, but it seems to me that you want to modify some attributes of J2EEResourceProperty object.
If this is the case, then you don't need to remove that "URL" string, actually you shouldn't do that. The string 'URL(cells/taspmociias204Cell01/clusters/cam_group|resources.xml#J2EEResourceProperty_1324400045826)' fully identifies WebSphere configuration object. Try this:
AdminConfig.modify('URL(cells/taspmociias204Cell01/clusters/cam_group|resources.xml#J2EEResourceProperty_1324400045826)', [['value', 'the new value'], ['description', 'the new description']])
BTW: you can also try using WDR library (https://github.com/WDR/wdr/). Then your script would look as follows:
prop = listConfigObjects('J2EEResourceProperty')[0]
prop.value = 'the new value'
prop.description = 'the new description'
Disclosure: I'm one of WDR contributors.
You could always use a simple replace regular expression to parse out the URL part.
For example:
import re
mystr = 'URL(blahblahblah)'
re.sub(r'^URL', "", mystr)
This is a handy tool to learn and test your regular expressions to make sure they are correct.
http://gskinner.com/RegExr/
I'm using pywinauto to list the control identifiers of a particular application. I can do that just fine. However, I want to save those control identifiers to file, or better yet assign them to a string or list, but cannot write them or assign them .... Does anyone know a way to get these identifiers to a file or memory programmatically?
sample code:
import os
import time
from pywinauto import application
from SendKeys import SendKeys
app=application.Application()
app.start_(r"C:\Program Files\myapp.exe")
app.dlg.print_control_identifiers()
Control Identifiers:
Button - 'Exit' (L900, T649, R975, B672)
'Button' 'Button0' 'Button1' 'Exit' 'ExitButton'
Button - 'About' (L339, T646, R410, B672)
'About' 'AboutButton' 'Button2'
...
...
...
I tried the following:
my_App_ci = app.dlg.print_control_identifiers()
And:
my_App_ci = []
my_App_ci.append(app.dlg.print_control_identifiers())
to no avail ....
You can use print_control_identifiers(filename="path\to\your\desktop\file.txt")
print_control_identifiers prints to stdout instead of returning a string. I did a quick look at the source and I could not see any functions to get them as strings, which is pretty crappy design IMHO.
You could capture the information by reassigning sys.stdout to an StringIO object and get the string from that. Or read the source to see what print_control_identifiers does and make a version that returns a list of strings.