I found a way to start a behaviour by creating a dialog in Choregraphe, but it does not work.
The script of the dialog is the following:
u(keyword / key sentence): robot_response (optional)
^start(applicationID/behaviour_1)
^wait(applicationID/behaviour_1)
The robot (NAO, version 2.8.6.23) catches my keyword, says the expected response, but the behaviour does not start: the robot goes into stand-by and I have often to restart it. Anyway, the application seems to be running (by looking at active content). I tried to run manually the behaviour and it works well, so I don't understand what I'm doing wrong...
PS: Both the application and the dialog are installed on robot applications, of course.
Does your other behavior use dialogue? What could be happening is that applicationID/behaviour_1 tries to start listening / activate dialogue, and fails right away because there is already a dialogue running (the one you showed us).
^start is intended for simple behaviors like animations, if you want to actually launch another activity with it's own logic etc. you should use ^switchFocus instead of ^start - what that will do is stop your current behavior that has this dialogue (so, no need for the ^wait), and start a new one. This will only work if Autonomous Life is active - Autonomous Life's job is to orchestrate activities so that only one is active at a given time, to prevent bugs caused by a bit of background code in one behavior causing problems in another.
("activities" are basically behaviors that are intended to be "top level", like applications or games, as opposed to little things like animations that are fine to run in the background)
Related
I'd like to know if drop frame is available in PyCharm / Intellij with Python plugin.
Here's what the button looks like (it doesn't show up on the debug toolbar so I assume it's just not available for PyCharm) -->
How to step one step back in IntelliJ?
What I'm trying to do is to re-play a function when I see a problem, to inspect it more. ("come back in time")
(I've used this before in Eclipse with Java, it would replay the current scope if you edited it and saved changes. of course the global scope remains changed after running a function many times, but for most cases it's very useful)
Thanks for telling!
As of version 2017.3.3, there is no drop frame feature as that in IntelliJ. The pycharm docs referred above seems wrong.
Since you want to 're-ply a function', 'Evaluate Expression' works great for that purpose. I use a lot when I debug. It basically allows to run any code at runtime with the variables and functions in that context.
It is the icon on the most right on the debug window.
Put a break point on the line before the line where goes wrong, debug the program, when it tops on the break point, click on 'Evaluate Expression' icon, copy the function with issues, paste it and run it.
PyCharm 2017.2 seems to have added the functionality you're looking for. The documentation describes a "Drop frame button" on the Debug Stepping Toolbar:
Interrupts execution and returns to the initial point of method execution. In the process, it drops the current method frames from the stack.
Hi all Python developers!
In Eclipse with PyDev it is possible to edit a Python file while debugging. On save, the PyDev debugger will reload the updated code into the running program and uses my new code. How can I do the same thing in JetBrains PyCharm (using Community Edition)?
Eclipse / PyDev writes an output like this when I do that:
pydev debugger: Start reloading module: "MyWidget" ...
pydev debugger: Updated function code: <function close at 0x055F4E70>
pydev debugger: reload finished
I searched settings and web and could not find any hint. Very glad about any idea. Thx.
Edit: I found out in Eclipse/PyDev one has to be in debug mode to be able to use this feature. I tested in PyCharm, but there was no reload done.
PyCharm does not support edit and continue in either the community edition or the professional edition but here is a workaround that I have found while debugging.
Since you can run arbitrary code in the console and/or the expression evaluator, in a lot of cases, you can execute changes to the code without having to restart the application. This isn't exactly like edit-and-continue (which is a feature I really like in Visual Studio and should be part of Pycharm) but it goes a long way towards avoiding having to restart the program from scratch after a change to see if the new code works as expected.
Let me illustrate a couple of the techniques I use:
Let's say you have the following code (with a couple of typos/bugs to illustrate the techniques)
test_value = [10,9,8,7,6,55,4,3,2,1]
for i in range(0,10):
if test_value[i] == i:
print "found the value: " + i
If you run this code, first it errors because you can't print string plus integer but also I wanted to match on 5, not have 55 in the array. So here we go.
Set a break point on the for statement like this and run the code in the debugger.
When it breaks into the debugger, you realize that it should be 5 not 55. Rather than restarting, you can change line 1 to test_value = [10,9,8,7,6,5,4,3,2,1] then select the line, right click and choose Execute Line in Console... which will change the value of test_value to be the array with a 5. Now, the if statement on line 4 becomes true on the value 5. This will then trigger the syntax error on line 5.
Now if you want to make sure you have the syntax correct you can change line 5 to print "found the value: " + str(i), select the line and choose Evaluate Expression... from the right button context menu. When you click Evaluate, the result will show up either in the dialog (or in this case, since it is a print command, in the console)
Now that I've fixed these two issues, I can run the code successfully on the second pass rather than possibly multiple passes it might have taken if I didn't use these techniques. These techniques really pay off if you find a bug deep in the code where it took a while to set up.
Obviously, this is a very contrived example, but hopefully this shows how you can use both Evaluate Expression... and Execute Line in Console... to your advantage while debugging without having to restart your application each time you find a bug in the code.
Also, if you happen to be using Django, PyCharm (professional) will re-launch the server if you make changes to the code. So if you are looking at your web page and notice a problem, you can make a change to the code and switch back to the web page and as you do, either the running application or the debugged application will re-launch and the new code will be running when you refresh the page. Again, not really edit-and-continue but a pretty rapid way to make a change and test.
After all I found a useful and acceptable workaround for my question. It works in PyCharm Community Edition 3.1.2 and I assume it will do in commercial edition as well. I tested on a mid-scale project using Python 2.7.6, PySide (Qt) with one main window and 20+ widgets, tabs, whatever. Follow these steps...
Work in PyCharm on a python project :-)
Execute your code in Debug mode (did not tried Release so far)
Edit some code in one your modules imported during the life of your program
Make your program pause. To achieve this, you can click the "Pause" button of in PyCharms Debug view and then any place in your applications main window where it would need to do something (for example on a tab header). If you have a long a running task and no UI, you may place a breakpoint in a place your program often comes by.
In the Debug view, switch to the Console tab. There is a button on the left Show command line. Click this.
In the console, type in reload(MyModifiedModule) if this call fails, write import MyModifiedModule and try again.
Click resume in PyCharm.
Try the code you fixed.
There are some restrictions on this... It won't fix changes in your main method or main window, cause it won't be created again. In my tests I could not reload widgets from Qt. But it worked for classes like data containers or workers.
May the force be with you as you try this and do not hesitate to add your experiences.
I have the commercial version of PyCharm and just tried testing a simple python script. The script is the following:
for i in range(0,100):
print i
I ran the code in debug mode and placed a break point at the "print i" statement. When the debugger stopped during the first iteration I changed the code to look like this:
for i in range(0,100):
print i
print 'hello'
PyCharm did not reload/re-compile the altered script. Given this simple test my best guess would be that PyCharm does not dynamically reload .py files.
You can add hot reloading features by installing Reloadium plugin.
https://plugins.jetbrains.com/plugin/18509-reloadium
Example use (gif)
It also works without pycharm.
More details:
https://github.com/reloadware/reloadium
I am very much concerned about my productivity all the time. I have recently come across this beautiful chrome extension Limitless
But this is only measuring what i'm doing within the chrome application. As I work most of the time with pdfs, videos etc, I want to develop similar application for linux(ubuntu) desktop enviroment.
Basically I want the script to run continuously as long as the workstation is on.
It should be able to know what I'm currently looking at (for eg a pdf file or a lecture video in vlc) and get the name of the respective file, start time, end times etc and finally post to db.
It is better if it could know if the system is idle or at sleep.
I don't have slightest clue at bash scripting. so my questions is could this task be accomplished with python.
What I've tried?
I started with a search in google "get current application python", "current window title python" etc etc and really surprised to see absurd results.
Please give me pointers on this.
I think you are asking for vocabulary. So I give you what I know.
You are using Ubuntu so your Window Manager may be Gnome.
The window manager knows which window has the focus.
So maybe you want to find out which window has the focus and you want to map it to the Process that opened the window.
What you need to focus on is is module for Python or a Python Binding for the window manager. This module is likely to also be able to control the windows.
The window manager is started with startx.
You could try to call a command line tool and catch the results
How do get the process list on command line:
https://stackoverflow.com/questions/53489/how-do-you-list-all-processes-on-the-command-line-in-windows
And how to call a tool with python:
Python subprocess.call and subprocess.Popen stdout
[edit] Repeating the call in Intervals and counting the intervals a process were running gives you a good estimation of running time of a process...
[edit2] As GreenAsJade said, you search a way to find out which windows has the focus.
See How do I detect the currently focused application?
I created an complete logger-type program, that logs the certain data from the internet sources. It's GUI I coded in wx.python, now I want to daemonize it (if it is the right term). The program needs to run in background and user has to have option to call/open GUI when he pleases. How can I achieve this with wx.python?
I wouldn't really "daemonize" it per se. Instead, I would just put it in the system tray...at least, that's what I would do on Windows. I assume you can do something similar on the other OSes. Basically you want to bind the frame to wx.EVT_ICONIZE and in that method, you hide it. Then when the user double-clicks the taskbar icon, you want to show it and probably Raise it too.
There's some badly formatted code here: http://bytes.com/topic/python/answers/699757-wxpython-how-minimize-taskbar (I've used a variation of it myself, so I know it works).
And here's some information on Task bar icons: http://www.blog.pythonlibrary.org/2011/12/13/wxpython-101-creating-taskbar-icons/
SO I am infact doing something very similar to this user posts:
https://stackoverflow.com/questions/6800292/python-ai-and-3d-animation
but it has no answers and I couldn't contact the user.
Basically I have a functioning python script that answers me with an action accordingly to my voice command. (Fetch emails, weather forecast, turn lights ON/OFF, etc), it has been made using the pyspeech library which is pretty darn good.
Now I want to give my programm a "face"! I thought about modelling the face with Blender (have some knowledge and would build up on it) and I know I could animate it, so the lips move and such.
So I want to know if it is at all possible to:
Load the "face" that I made from blender from my main python script (so when my programm start the face would be there on the screen too)
Run from the script the animations such that when for example when my programm says "You're welcome" I would run the animation that the lips move on the face to simulate it is speaking.
I know that blender has a good python integration (maybe correct is to say it is built on?) and that is why I thought it would be a good program to use.
Hope someone can help and tell me if that is at all possible and maybe show me some right way to go, my googling just showed me always python scripting with Blender which is not what I exactly need here... I think...
Cheers,
Flavio
Indeed, what you want is possible.
If all you want is to play pre-rendered animation videos based on decisions on your program, any GUI that allows you to embedd and play video in a widget will do for your application.
You could rool out your own GUI using Pygame (which has video support, but you will need one of the "minor" more or less "amateur" widget toolkits made for pygame to make up the remaining of your application, as pygame is pretty low level.
On a higher level, although I'had not embedded video, I think you could go with PyQT4 (googled a bit, not that many examples either, buthints that there are eamples in QT4 source) or GTK+ (the samething, it looks like there are more examples).
Another option would be to build your application to run inside the Blener Game Engine itself - It offers both a high level Toolkit, and ways to customize behaviors to user actions (even without coding).
The major drawback in doing this is: I don't know which are the options to distribute an application that needs Blender Game Engine nowadays - your users will need to install Blender (but it is likely Blender folks made an easy way to jhandle this).
On the upper hand: you get the most flexibility, it would even be possible to render some sequences in realtime (as opposed to pre-rendered videos) in your app.
One thing: Blender nowadays use Python 3.x - if the other libraries you need are Python 2, you willl need to make one different process for the GUI inside Blender, and exchange data with your application's backeend in Python 2 (for example using jsonrpc or xmlrpc - that is enoguh simple in Python).