I'm using BotCity for automation but the system doesn't work.
After listing the image and indicating the action on the UI tab, BotCity does not create the code on the 'CODE' tab, how can I solve this problem?
from botcity.core import DesktopBot
from botcity.maestro import *
class Bot(DesktopBot):
def action(self, execution=None):
self.browse("https://www.facebook.com/groups/xxxxxx")
#in this field, the code should be created after the image is selected, but that doesn't happen, even if I leave the course selected in this line
def not_found(self, label):
print(f"Element not found: {label}")
if __name__ == '__main__':
Bot.main()
Related
I'm trying to create a gradio User Interface which does the following
on the left panel I have a File control, that allows the selection of a local file (eg. a .csv)
when a file is selected a "Process" button should be made visible
when the "Process" button is pressed, a function is called, reading the contents of the file, and processing it in some ways, resulting in a string
the resulting string is shown in a TextArea in the right column
I'm stuck implementing point 2. I can select the file, but can't make the Process button become visible.
This is my code so far (not yet implementing points 3. a:
import gradio as gr
def file_selected(file_input):
print("yes, file_selected is invoked")
print(process_button)
process_button.visible=True
demo.render()
return process_button
with gr.Blocks() as demo:
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("### Data")
file_input = gr.File(label="Select File")
process_button = gr.Button("Process", visible=False)
with gr.Column(scale=2, min_width=600):
gr.Markdown("### Output")
result_display = gr.TextArea(default="", label="Result", lines=10, visible=False)
file_input.change(fn=file_selected, inputs=file_input, outputs=process_button)
if __name__ == "__main__":
demo.launch()
I see that at file selection the message is printed (and print(process_button) prints "button" so I'm sure this variable is not None), but the button doesn't appear on the page.
edited: fixed some errors not directly related to the problem.
There were many problems with the code (I fixed those not related with the main issue in the original post), but in the end what solved my problem (making the button visible) was that instead to rerender,
def file_selected():
...
process_button.visible=True
demo.render()
I just had to return the process_button.update
def file_selected(file_input):
...
return gr.update(visible=True)
(Actually this was documented in gradio's online docs; sorry, I didn't notice it before)
This is the complete working code:
import gradio as gr
def file_selected(file_input):
print("yes, file_selected is invoked")
print(process_button)
return gr.update(visible=True)
with gr.Blocks() as demo:
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("### Data")
file_input = gr.File(label="Select File")
process_button = gr.Button("Process", visible=False)
with gr.Column(scale=2, min_width=600):
gr.Markdown("### Output")
result_display = gr.TextArea(default="", label="Result", lines=10, visible=False)
file_input.change(fn=file_selected, inputs=file_input, outputs=process_button)
if __name__ == "__main__":
demo.launch()
I'm learning Python while trying to develop helper tools for Maya using Python and PySide. (Quite ambitious but there is no progress without challenges, right)
Basically, I'm writing a tool that would help me export animation as fbx files to a folder I set in any given location on my PC.
I've finished to write the export process. There should be no issue here, I'm stuck with the UI part of it.
Currently this is how my UI is looking. I want to be able to set the path to the place where I want the script to export the files.
When I select the path and press "Select Folder", I want the path of the selected folder to display in the text line of the UI. And "Remember" it so that when I press Export FBX animation or Export rig it would use that path and would save files there.
But I have no clue how to do that. Can anyone help the clueless me how to make this happen?
I would appreciate any help. Thank you )
Here is my current code:
`
import CreatureAnimBakeProcess
reload(CreatureAnimBakeProcess)
from maya import cmds
import os
from PySide2 import QtWidgets, QtCore, QtGui
class CreatureAnimBakeUI(QtWidgets.QDialog):
def __init__(self):
super(CreatureAnimBakeUI, self).__init__()
self.setWindowTitle('Creature Exporter')
self.library = CreatureAnimBakeProcess.CreatureExport()
self.buildUI()
def buildUI(self):
print 'building ui'
layout = QtWidgets.QVBoxLayout(self)
setPathWidget = QtWidgets.QWidget()
setPathLayout = QtWidgets.QVBoxLayout(setPathWidget)
layout.addWidget(setPathWidget)
self.setPathField = QtWidgets.QLineEdit()
setPathLayout.addWidget(self.setPathField)
setBtn = QtWidgets.QPushButton('Set Export Folder')
setBtn.clicked.connect(self.setPath)
setPathLayout.addWidget(setBtn)
#============================================
btnWidget = QtWidgets.QWidget()
btnLayout = QtWidgets.QVBoxLayout(btnWidget)
layout.addWidget(btnWidget)
ExportFBXBtn = QtWidgets.QPushButton('Export FBX Animation')
ExportFBXBtn.clicked.connect(self.exportFbxAnim)
btnLayout.addWidget(ExportFBXBtn)
ExportRIGBtn = QtWidgets.QPushButton('Export RIG')
ExportRIGBtn.clicked.connect(self.exportRIG)
btnLayout.addWidget(ExportRIGBtn)
return
def getDirectory(self):
directory = os.path.join(cmds.internalVar(userAppDir=True), 'Animation')
if not os.path.exists(directory):
os.mkdir(directory)
return
def setPath(self):
directory = self.getDirectory()
pathName = QtWidgets.QFileDialog.getExistingDirectory(self, directory, "Creature Exporter")
return
def exportFbxAnim(self):
pass
def exportRIG(self):
pass
def showUI():
ui = CreatureAnimBakeUI()
ui.show()
return ui
`
You can use self.setPathField.setText(pathName) to show the value, you can also assign it to self.exportPath = pathName so you can re use it.
I am only showing code snippets where I changed, the remainder of your code needs no changes.
def __init__(self):
super(CreatureAnimBakeUI, self).__init__()
# have it assigned to None
self.exportPath = None # changed here
self.setWindowTitle("Creature Exporter")
self.buildUI()
def setPath(self):
directory = self.getDirectory()
pathName = QtWidgets.QFileDialog.getExistingDirectory(
self, directory, "Creature Exporter"
)
if pathName: # changed here
# "remember the value"
self.exportPath = pathName
# show it in the text line of the UI
self.setPathField.setText(pathName)
return
self.exportPath will be None initially, once you select a folder it will have that value saved. So this if checks if the value is not set and forces the user to set a value, if it is already set that value will be used.
def exportFbxAnim(self): # changed here
if self.exportPath is None:
# call self.setPath if self.exportPath is None
self.setPath()
# self.exportPath should have the value you expect
def exportRIG(self): # changed here
if self.exportPath is None:
# call self.setPath if self.exportPath is None
self.setPath()
# self.exportPath should have the value you expect
This is my first attempt at using the Tkinter plugin, I know very little past what tutorials I could find. All the answers I've seen so far put a class inside the py file that your building, I however have a plethora of tests that are already compiled into a Test class that runs many separate tests. All the tests run and no errors are encountered before trying to add to the ui.
I would like to be able to run each suite by clicking a button. My problem seems that I'm missing a step some where but not getting any errors or action when I click the button, but an error after I click and close the ui window. I should point out that importing the settings file (which contains most of the webdriver imports) does not help either. I get the same error.
Traceback:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python37\lib\tkinter\__init__.py", line 1702, in __call__
return self.func(*args)
File "C:\Python37\lib\unittest\case.py", line 663, in __call__
return self.run(*args, **kwds)
File "C:\Python37\lib\unittest\case.py", line 590, in run
testMethod = getattr(self, self._testMethodName)
AttributeError: 'Test' object has no attribute 'runTest'
My ui code:
import sys, os, tkinter, TESTadmin
top = tkinter.Tk()
a = TESTadmin.Test()
B = tkinter.Button(top, text= "Test Window", command=a )
B.pack()
top.mainloop()
for clarity my main test file:
from helpers.settings import *
from pieces import adminLogin, adminLogout, docs
class Test(unittest.TestCase):
def setUp(self):
# Maximize Window (remove quotes to use)
'''sel.maximize_window()'''
self.browser = webdriver.Firefox()
self.browser.get("https://mywebsite.net")
# We instantiate and start the browser
def testCases(self):# Add Tests Below
#log in to admin side
login = adminLogin.AdminLogin.do(self)
#docs page
docpage = docs.Docs.do(self)
#log out
logout = adminLogout.Logout.do(self)
if G.log:
for k in G.log.items():
print(k)
### Uncomment to close browser after test ###
def tearDown(self):
self.browser.close()
if __name__ == "__main__":
unittest.main()
As it would turn out, the answer like I thought is simple.
this line :
def testCases(self):
needs to read:
def runTest(self):
after that change every thing works percectly.
My confusion is because originally when building these tests I was following the directions here -> https://selenium-python.readthedocs.io/
They show you to use the testCases() method, and this works! Just not for calling the class. I didn't know where to put the function let alone know that Webdriver had a built in function other than what i was using.
When the user saves a file I want a check to happen prior to saving. If the check fails then it doesn't save. I got this working with mSceneMessage and kBeforeSaveCheck, but I don't know how to customize the pop-up message when it fails. Is this possible?
import maya.OpenMaya as om
import maya.cmds as cmds
def func(retCode, clientData):
objExist = cmds.objExists('pSphere1')
om.MScriptUtil.setBool(retCode, (not objExist) ) # Cancel save if there's pSphere1 in the scene
cb_id = om.MSceneMessage.addCheckCallback(om.MSceneMessage.kBeforeSaveCheck, func)
Right now it displays
File operation cancelled by user supplied callback.
I'm a bit slow to the question, but I needed something similar today so I figured I'd respond. I cannot decide if I would recommend this in the general case, but strictly speaking, it is possible to change a considerable number of static strings in the Maya interface using the displayString command. The easy part is, you know the string you are looking for
import maya.cmds as cmds
message = u"File operation cancelled by user supplied callback."
keys = cmds.displayString("_", q=True, keys=True)
for k in keys:
value = cmds.displayString(k, q=True, value=True)
if value == message:
print("Found matching displayString: {}".format(k))
Running this on Maya 2015 finds over 30000 registered display strings and returns a single matching key: s_TfileIOStrings.rFileOpCancelledByUser. Seems promising to me.
Here's your initial code modified to change the display string:
import maya.OpenMaya as om
import maya.cmds as cmds
def func(retCode, clientData):
"""Cancel save if there is a pSphere1 in the scene"""
objExist = cmds.objExists('pSphere1')
string_key = "s_TfileIOStrings.rFileOpCancelledByUser"
string_default = "File operation cancelled by user supplied callback."
string_error = "There is a pSphere1 node in your scene"
message = string_error if objExist else string_default
cmds.displayString(string_key, replace=True, value=message)
om.MScriptUtil.setBool(retCode, (not objExist))
cb_id = om.MSceneMessage.addCheckCallback(om.MSceneMessage.kBeforeSaveCheck, func)
I have extended the UI file resulting from the Plugin builder with Qt Creator.
Just added some checkboxes and a combobox, named layercombo to the form.
The application is named jacktest.py. It uses an intermediate file jackdialog.py (generated from the plugin builder, left unchanged).
Compiled the UI file and the resource file. Then added some code to the plugin and tested this. It's no problem to get the available layer names in a QMessagebox. But how to add these to the combobox ?
Should be simple, but no option succeeds in referencing the combobox.
Error message: AttributeError: jacktest instance has no attribute 'layercombo'.
Result from my latest try:
# run method that performs all the real work
def run(self):
# create and show the dialog
dlg = jacktestDialog()
# show the dialog
dlg.show()
result = dlg.exec_()
for layer in self.iface.legendInterface().layers():
if layer.type() == QgsMapLayer.VectorLayer:
QMessageBox.information( self.iface.mainWindow(), "Info", layer.name())
self.layercombo.Items.Insert(0, layer.name())
# See if OK was pressed
if result == 1:
# do something useful (delete the line containing pass and
# substitute with your code
pass
You are trying to reference the current class (which is not your dialog) when you are setting the layercombo items
Replace:
self.layercombo.Items.Insert(0, layer.name())
with
dlg.ui.layercombo.Items.Insert(0, layer.name())
but you code still won't work correctly as exec_() is blocking and waits until it returns so you are adding items to an invisible dialog.
Try this instead:
# create and show the dialog
dlg = jacktestDialog()
# show the dialog
for layer in self.iface.legendInterface().layers():
if layer.type() == QgsMapLayer.VectorLayer:
QMessageBox.information( self.iface.mainWindow(), "Info", layer.name())
dlg.ui.layercombo.Items.Insert(0, layer.name())
result = dlg.exec_()
Went on in developing a Signal within the run module (code: def run (self):)
QObject.connect(dlg.ui.layercombo,SIGNAL('currentIndexChanged (int)'),self.select_one)
and the code of select_one is:
def select_one(self):
comboindex = dlg.ui.layercombo.currentIndex()
QMessageBox.information(self.iface.mainWindow(), "Info", comboindex)
Error message:
comboindex = dlg.ui.layercombo.currentIndex()
NameError: global name 'dlg' is not defined
Suppose I have to reference dlg as a parameter in the function call, but this is not working until now.