I'm trying to make a conditional statement based on whether a checkbox is checked or not. I've tried something like the following, but it always returns as true.
self.folderactive = QtGui.QCheckBox(self.folders)
self.folderactive.setGeometry(QtCore.QRect(50, 390, 71, 21))
self.folderactive.setObjectName(_fromUtf8("folderactive"))
if self.folderactive.isChecked:
folders.createDir('Desktop')
print "pass"
elif not self.folderactive.isChecked:
folders.deleteDir('Desktop')
print "nopass"
Is there a way to get a bool value of whether a checkbox is checked or not?
self.folderactive.isChecked isn't a boolean, it's a method - which, in a boolean context, will always evaluate to True. If you want the state of the checkbox, just invoke the method:
if self.folderactive.isChecked():
...
else:
...
x = self.folderactive.isChecked()
x will be True or Falseāa Boolean value.
(It's the brackets at the end that make the difference.)
Related
I am trying to make a bad words system for my server's custom bot, but it seems to only
listen for the first condition, ignoring the second one:
#bot.event
async def on_message(message):
###BAD WORDS CHECK
if message.author == bot.user:
pass
else:
if (any(x in message.content.lower() for x in words2)):
if "hack" or "crack" in message.content.lower():
await message.reply("I think you may be asking for illegal services or illegal advice. Please refer to rule #5 in the welcome channel!")
await message.channel.send("If you think this was a mistake please reply with $report!")
global CAN_REPORT
CAN_REPORT = "yes"
return
else:
pass
await bot.process_commands(message)
The bot will for some reason respond to any message containing any word from words2:
words2 = [
"instagram",
"snapchat",
"roblox",
"paypal",
"facebook",
"gmail",
"fortnite",
"minecraft",
"apex",
"youtube",
]
ignoring whether the message contains "hack", which leads to it replying to every message talking about social media or games. The goal is to check if BOTH conditions are true.
Any help is appreciated!
With this line if "hack" or "crack" in message.content.lower(): you are basically checking if either the string "hack" is true or if "crack" in message.content.lower() is true.
Thus the check always returns true, because "hack" will always be true.
The way to fix this would be something like this:
if "hack" in message.content.lower() or "crack" in message.content.lower():
Or, better yet, do it like you do in the first check:
word_list = ["hack", "crack"]
if any(x in message.content.lower() for x in word_list):
Its simple just add :
if words2 in message.content.lower():
await message.delete()
await ctx.send('that word is banned')
I have one value that is tied to a flag that comes from a config file that I need to show in my soy template. It is either true or false.
If true, the value needs to be "x" (for example, but it is a string)
If false, the value needs to be "" (empty)
Notice that I cannot pass in the true or false value from my config. I also cannot omit the value on false, it has to supply an empty string.
I've tried various forms of if statements using let, but according to my interpretations of the docs, a value declared with let cannot be changed (which doesn't make sense)
This is basically what I need:
{if $inputValue.value == 'true'}
{let $myVar: ($someValueThatExistsInMyTemplate) /}
{else}
{let $myVar: '' /}
{/if}
Then I will use $myVar in my template. However, whenever I try that, I get this error:
Found references to data keys that are not declared in SoyDoc: [myVar]
What can I do!?
Got it working using the ternary operator:
{let $dataParent: ($item.preferences.accordionOnOff.value == 'true') ? ($item.name) : '' /}
I'm having trouble removing a widgets with a label once it's added
Here's the relevant piece of code:
logi= True
if data == []:
logn =Label(text= "Incorrect Username",color=(190,0,0,1),
pos_hint={"right":1.035,"top":1.14})
self.add_widget(logn)
logu =Label(text= "Incorrect Password",color=(190,0,0,1),
pos_hint={"right":1.035,"top":1.04})
self.add_widget(logu)
logi= False
if logi == True:
textinput.text=''
textinput2.text=''
if 'logn' in locals() and 'logu' in locals() :
self.remove_widget(logn)
self.remove_widget(logu)
once the widgets have been added I can't seem to remove them, if i remove the if 'logn' in locals() and 'logu' in locals() :statement I get an error "Local variable referenced before assignment " every time I test this without the above mentioned if statment I make sure the widgets have been added
I assume you are entering this method twice (1st data==[] 2nd time data=[...]). So You should keep your variables at hand (put them on the instance - self)
logi= True
if data == []:
self.logn =Label(text= "Incorrect Username",color=(190,0,0,1),
pos_hint={"right":1.035,"top":1.14})
self.add_widget(self.logn)
self.logu =Label(text= "Incorrect Password",color=(190,0,0,1),
pos_hint={"right":1.035,"top":1.04})
self.add_widget(self.logu)
logi= False
if logi == True:
textinput.text=''
textinput2.text=''
if hasattr(self, 'logn'): #check that we put something here before...
self.remove_widget(self.logn)
self.remove_widget(self.logu)
Note all the places I've added self ...
So I have an object with a set of attributes that are boolean flags that mark whether something has been published or not. There are several different formats it can be published to: published_to_web, published_to_email, published_to_pdf, etc. Rather than having a separate method to reset each format, I thought I would simply use one method, and set the attribute with a variable sent when the pertinent button (web, email, pdf, etc.) was clicked on. So for example a button calls the method and params[:format] = 'web', so I want to set the object's 'publish_to_web' attribute to false:
#bulletin.update_attributes( "published_to_#{params[:format]}", false)
but I can't get it to work. Seems like it should be simple in RoR but I can't seem to get the right juju. I've tried:
#bulletin.update_attributes( "published_to_#{params[:format]}".to_sym, false )
#bulletin.update_attributes( "published_to_#{params[:format]}", false )
#bulletin.update_attributes( "published_to_#{params[:format]}: false" )
#bulletin.update_attributes( ":published_to_#{params[:format]}" => false)
... what's the secret sauce?
#bulletin.update_attributes( "published_to_#{params[:format]}" => false)
Using nodeunit is there an assert to check for false values? Other testing frameworks have something like assertFalse, should I use something like:
test.ok(!shouldBeFalse());
or
test.equals(shouldBeFalse(), false);
Or is there a project that adds a false assertion?
If you want to be sure only boolean false is matched than use strictEqual:
test.strictEqual(shouldBeFalse(), false)
Otherwise equal is ok too.