I'm aware that there are similar problems to mine but I tried those solutions and they don't work.
I have text field:
self.tMail = QtGui.QPlainTextEdit(self.centralwidget)
self.tMail.setGeometry(QtCore.QRect(50, 270, 451, 75))
self.tMail.setAccessibleName(_fromUtf8(""))
self.tMail.setInputMethodHints(QtCore.Qt.ImhNone)
self.tMail.setPlainText(_fromUtf8(""))
self.tMail.setOverwriteMode(False)
self.tMail.setObjectName(_fromUtf8("tMail"))
And i want to add them to the variable string by:
def handleButton(self):
timeString = self.tCzas.text()
mailString = self.tMail.text()
IDString = self.tID.text()
teamString = self.tTeam.text()
print(timeString)
print(mailString)
print(IDString)
print(teamString)`
also I tried:
mailString = self.tMail.plainText()
and I always get an error:
AttributeError: 'QPlainTextEdit' object has no attribute '...'
Why?
QPlainTextEdit doesn't have a text() function. try using the toPlainText() function:
def handleButton(self):
timeString = self.tCzas.toPlainText()
mailString = self.tMail.toPlainText()
IDString = self.tID.toPlainText()
teamString = self.tTeam.toPlainText()
print(timeString)
print(mailString)
print(IDString)
print(teamString)
Related
I was trying to work with TableWidgets on Python and I ran into an issue.
I wanted to check whether the table is filled or not (with str of course).
def add_table (self):
self.kala = self.comboBox.currentText()
self.code_kala = self.comboBox.currentIndex()
self.vahed = self.comboBox_2.currentText()
list_e = []
for i in list(range(10)):
#self.tab = self.tableWidget.item(i,0)
if self.tableWidget.item(i,0).text() != '':
#if self.tab.text() !='':
list_e.append(i)
else:
pass
self.ROW = len(list_e)
self.tableWidget.setItem(self.ROW,0,QTableWidgetItem(self.kala))
self.tableWidget.setItem(self.ROW,1,QTableWidgetItem(str(self.code_kala)))
self.tableWidget.setItem(self.ROW,2,QTableWidgetItem(str(self.vahed)))
and I don't know why I keep getting this error:
NoneType' object has no attribute 'text'
Does anyone know how to solve it?
Also, I know this code doesn't have any problem (I got good results with the same code in another project) but as cmd said:
File "D:\**\***\*****\*******\*\*************.py", line 1755, in add_table
if self.tableWidget.item(i,0).text() != '':
AttributeError: 'NoneType' object has no attribute 'text'
It seems that the table widget might contain 'None' values, so you have to expect them to pop up. Instead of doing this:
if self.tableWidget.item(i,0).text() != '':
do that:
thing = self.tableWidget.item(i,0)
if thing is not None and thing.text() != '':
# do stuff with thing
I am trying to mock "ConfigFactory.parse_file" for unit testing purpose and getting the following error.
AttributeError: 'str' object has no attribute 'as_plain_ordered_dict'
I tried mocking the attribute as_plain_ordered_dict to resolve the issue, but still getting the same error.
class Testt2StatsExporter(unittest.TestCase):
#patch('t2.client.OverlayClient')
#patch('pyhocon.ConfigFactory.parse_file')
#patch('oci.auth.signers.instance_principals_security_token_signer.InstancePrincipalsSecurityTokenSigner')
def test_create_telemetry_client(self, mock_config_factory, mock_security_token_signer, mock_client):
test_config = Mock()
test_config.json.return_value = {'metricsConfig': 'test_config'}
path_to_local_config = Mock()
type(path_to_local_config).as_plain_ordered_dict = PropertyMock(return_value=test_config)
mock_security_token_signer.return_value = "test_token"
mock_config_factory.return_value = test_config
mock_client.return_value = True
self.assertEqual(True, _create_telemetry_client(path_to_local_config))
and here is the main code base that I am testing.
path_to_local_config = '/etc/dlp/t2_config.conf'
def _create_telemetry_client(path_to_local_config: str):
t2config = ConfigFactory.parse_file(path_to_local_config).as_plain_ordered_dict()
common_config = t2config['metricsConfig']
t2_client_config = {'metricsConfig': common_config}
auth_provider = InstancePrincipalsSecurityTokenSigner()
return client.OverlayClient(t2_client_config, authentication_provider=auth_provider)
What can I try next?
I am creating a universal text field that can be used in many python turtle projects. I am trying to create an instance of it but I get this error:
>>> import TextField
>>> tf = TextField('None', False)
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
tf = TextField('None', False)
TypeError: 'module' object is not callable
>>>
What in a module causes this type of error? I completely wrote this module and I'm getting an error creating an instance of it :( ... What do I need in this module to make it 'callable'? I have tried adding a def __call__(self): but that doesn't affect the problem at all, nor create any errors.
Here is the beginning of the script where the problem is most likely happening:
# Created by SUPERMECHM500 # repl.it
# Edited by cdlane # stackoverflow.com
class TextField:
TextFieldBorderColor = '#0019fc'
TextFieldBGColor = '#000000'
TextFieldTextColor = '#ffffff'
ShiftedDigits = {
'1':'!',
'2':'#',
'3':'#',
'4':'$',
'5':'%',
'6':'^',
'7':'&',
'8':'*',
'9':'(',
'0':')'
}
def __init__(self, command, CanBeEmpty): # Ex. textField = TextField('Execute()', True)
self.CmdOnEnter = command
self.turtle = Turtle()
self.CanBeEmpty = CanBeEmpty
self.turtle.speed('fastest')
self.inp = []
self.FullOutput = ""
self.TextSeparation = 7
self.s = self.TextSeparation
self.key_shiftL = False
......
The module is not the class. If your class TextField is in a module called TextField, then it is referred to as TextField.TextField.
Or change your import to
from TextField import TextField
I have a problem with test selenium - page object pattern. My code:
class FormPage(Page):
nameConnect = (By.ID, "name")
def nameUser(self,name):
names = self.driver.find_element(*FormPage.nameConnect)
names.send_keys(name)
class testUser(Page):
start_page = FormPage(self.driver)
start_page.nameUser('user22xx')
my error:
start_page.nameUser('user22xx')
TypeError: 'tuple' object is not callable
How I can change my code? Thanks for your help!
The following code gives the error:
line 19, in modifyXML
self.PreFlopCallPower.text = 'NEW VALUE'
AttributeError: 'str' object has no attribute 'text'
The problem seems to be that self.PreFlopCallPower is only a string and not an elementTree object, even though my example is very similar to the example given on the python etree documentation: self.PreFlopCallPower = entry.find('PreFlopCallPower').text. How can I fix this? I can't see what I'm doing different to the update example listed here: https://docs.python.org/2/library/xml.etree.elementtree.html
import xml.etree.ElementTree as xml
class XMLHandler(object):
def __init__(self,StrategyName):
self.readXML(StrategyName)
self.modifyXML()
def readXML(self, StrategyName):
self.Template = StrategyName
self.tree = xml.parse('strategies.xml')
self.root = self.tree.getroot()
for entry in self.root.findall('Strategy'):
if entry.get('name') == StrategyName:
self.PreFlopCallPower = entry.find('PreFlopCallPower').text
def modifyXML (self):
self.PreFlopCallPower.text = 'NEW VALUE' # ---ERROR OCCURS HERE---
self.PreFlopCallPower.set('updated', 'yes')
self.tree.write('output.xml')
X=XMLHandler('Strategy305PP')
In this line, you're storing the text of the node (hence have a str):
self.PreFlopCallPower = entry.find('PreFlopCallPower').text
Drop the .text to store the node itself:
self.PreFlopCallPower = entry.find('PreFlopCallPower')