Overwrite Copy command when getting out from terminal

17 views
Skip to first unread message

likage

unread,
Jan 16, 2017, 8:49:09 PM1/16/17
to Python Programming for Autodesk Maya
Pardon me if this is slightly off-topic but I need help.

I am trying to get my python script to to work in a linux terminal by grabbing the output such that the output results 'overwrites' the copy command (ctrl+c).
Currently while I am able to get this to work by opening a maya session but as soon as I tried running `python run_script.py` in the terminal console, I got the following error:
QApplication: Must construct a QApplication before accessing a QClipboard
Traceback (most recent call last):
 
File "get_pending_status_files_modi.py", line 10, in <module>
    cb
.clear(mode=cb.Clipboard )
AttributeError: 'NoneType' object has no attribute 'clear'


This is the code of my script:
def main():
    data_list
= ['this-is-a-test', 'for-learning', 'purposes-only']
    connect_result
= '|'.join(data_list)
    output
= '{0}{1}{2}'.format('(', connect_result, ')')
   
print output
   
    cb
.setText(output, mode=cb.Clipboard)

main
()

Though this is a small example, but I am using this for large amount of values in the data_list, and hence I want to know if there are any other ways that I can make use of?
By the way, I am unable to install any other libraries as I am using my office's computer while using linux environment, some of the methods online, using of `xsel`, `xclip` or `pyperclip` does not work for me, unfortunately..

Justin Israel

unread,
Jan 17, 2017, 1:11:59 AM1/17/17
to python_in...@googlegroups.com
On Tue, Jan 17, 2017 at 2:49 PM likage <dissid...@gmail.com> wrote:
Pardon me if this is slightly off-topic but I need help.

I am trying to get my python script to to work in a linux terminal by grabbing the output such that the output results 'overwrites' the copy command (ctrl+c).
Currently while I am able to get this to work by opening a maya session but as soon as I tried running `python run_script.py` in the terminal console, I got the following error:
QApplication: Must construct a QApplication before accessing a QClipboard
Traceback (most recent call last):
 
File "get_pending_status_files_modi.py", line 10, in <module>
    cb
.clear(mode=cb.Clipboard )
AttributeError: 'NoneType' object has no attribute 'clear'


When you are running scripts within Maya, you get a QApplication instance for free, because Maya has already created one as part of itself being a Qt application. If you want your script to work both inside and outside of Maya, then you can use an ifmain guard to only create a QApplication if your script is being run as an executable:

def main():
    # normal entry point for script in maya

if __name__ == "__main__":
    app = QtGui.QApplication([])
    main()
    # you will probably never get here if main() blocks. But then again,
    # it depends on whether your code needs the event loop started or not
    app.exec_() 
 

As for why your cb variable is None, I don't know, because you haven't shown enough of a code example to show where it gets created.

This is the code of my script:
def main():
    data_list
= ['this-is-a-test', 'for-learning', 'purposes-only']
    connect_result
= '|'.join(data_list)
    output
= '{0}{1}{2}'.format('(', connect_result, ')')
   
print output
   
    cb
.setText(output, mode=cb.Clipboard)

main
()

Though this is a small example, but I am using this for large amount of values in the data_list, and hence I want to know if there are any other ways that I can make use of?
By the way, I am unable to install any other libraries as I am using my office's computer while using linux environment, some of the methods online, using of `xsel`, `xclip` or `pyperclip` does not work for me, unfortunately..

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ae3eacd7-3c8e-43b4-8d05-c49c3da31e22%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages