embedding the P3 Speller in a Python application
embedding the P3 Speller in a Python application
Hi, I am relatively new when it comes to BCI2000. I am trying to modify the P3 Speller application module and transform it into a sequence order game for my thesis. I've been looking at the source code for P3Speller, but I can't find a simple way to modify the interface from there (I don't really need to modify the base array, just add more functionality).
Searching the forum, I found this interesting idea to embed P3 Speller inside a WinForm
viewtopic.php?f=5&t=1083&sid=1d8821e48c ... b9f604d07f
My question is if it would be possible to do something similar to this using python and BCI2000Remote. That is, I would like to have the P3 Speller inside a frame or panel of my own Python application. I think this would allow me to focus only on my application code
Currently, using BCI2000Remote.py I can run BCI2000 from python, but this opens as separate windows
I would appreciate if someone could help me with this.
Searching the forum, I found this interesting idea to embed P3 Speller inside a WinForm
viewtopic.php?f=5&t=1083&sid=1d8821e48c ... b9f604d07f
My question is if it would be possible to do something similar to this using python and BCI2000Remote. That is, I would like to have the P3 Speller inside a frame or panel of my own Python application. I think this would allow me to focus only on my application code
Currently, using BCI2000Remote.py I can run BCI2000 from python, but this opens as separate windows
I would appreciate if someone could help me with this.
Re: embedding the P3 Speller in a Python application
I think that's a good path to follow.
The link you gave contains some information about how to achieve this using the Windows API. There is some outdated reference to "VCL Forms," but the general idea is the same:
* get a handle to the P3Speller process' main window,
* create a subwindow inside your own application to hold the P3Speller,
* make the P3Speller process' main window the only child of the new subwindow.
Unfortunately, I cannot guide you how to use the Windows API from python. The Windows API itself is extensively documented on MSDN (www.msdn.com).
Regards,
Juergen
The link you gave contains some information about how to achieve this using the Windows API. There is some outdated reference to "VCL Forms," but the general idea is the same:
* get a handle to the P3Speller process' main window,
* create a subwindow inside your own application to hold the P3Speller,
* make the P3Speller process' main window the only child of the new subwindow.
Unfortunately, I cannot guide you how to use the Windows API from python. The Windows API itself is extensively documented on MSDN (www.msdn.com).
Regards,
Juergen
Re: embedding the P3 Speller in a Python application
Hi Juergen,mellinger wrote: ↑21 Oct 2020, 08:52 I think that's a good path to follow.
The link you gave contains some information about how to achieve this using the Windows API. There is some outdated reference to "VCL Forms," but the general idea is the same:
* get a handle to the P3Speller process' main window,
* create a subwindow inside your own application to hold the P3Speller,
* make the P3Speller process' main window the only child of the new subwindow.
Unfortunately, I cannot guide you how to use the Windows API from python. The Windows API itself is extensively documented on MSDN (www.msdn.com).
Regards,
Juergen
Thanks for your quick response. Indeed I have consulted how to do this in Python and I have found the solution using win32gui which also has the FindWindow () and SetParent () methods that allow me to embed the matrix within its own interface.
I would like to consult you, taking advantage of this space, if you think that there could be some problem with the performance when carrying out the application in this way, because the intention is that it be later used online for cognitive rehabilitation.
In the case where it is best to make the array completely in Python, instead of embedding it, I understand that this could be achieved by using the DummyApplication module to connect BCI2000 with my application. However, I have some doubts with this, mainly on how to insert the StimulusType and StimulusCode states. I understand that I should create these states using "-INSERT STATE StimulusCode 8 0; INSERT STATE StimulusType 1 0" but I'm not sure I fully understand how this works.
On the other hand, in the case of having a separate application written in Python, would it be necessary for my application to control the lighting of the characters in my array, or is it possible to make BCI2000 control this?
I apologize for so many questions, but I would appreciate if you could give me a hand to better understand this.
Greetings
Re: embedding the P3 Speller in a Python application
Hi,
https://www.bci2000.org/mediawiki/index ... _Scripting
Regards,
Juergen
I don't expect any performance, or timing, problems when embedding the P3Speller window into a different application. The P3Speller remains a separate process, and is able to utilize system resources just like before. The general caveat is that you should not run too many or resource-hungry applications on the same machine as you run BCI2000.if you think that there could be some problem with the performance when carrying out the application in this way
INSERT STATE is an Operator scripting command. For more information about Operator scripting commands, see this wiki page:create these states using "-INSERT STATE StimulusCode 8 0; INSERT STATE StimulusType 1 0" but I'm not sure I fully understand how this works
https://www.bci2000.org/mediawiki/index ... _Scripting
I'm not sure whether I correctly understand what you are asking. If the Python side is responsible for building the matrix (array), it will also be responsible for doing the flashing of rows and columns, and for determining the matrix element selected. The BCI2000 P3Speller provides a StimulusCode state which could be used by the Python side in order to determine when and what to flash, but you would need to have the BCI2000 configuration in sync with the Python configuration, and I cannot imagine any advantage over the embedding solution we were discussing so far.On the other hand, in the case of having a separate application written in Python, would it be necessary for my application to control the lighting of the characters in my array, or is it possible to make BCI2000 control this?
Regards,
Juergen
Re: embedding the P3 Speller in a Python application
Hello,
Thank you very much for your help. I have finally made the application by embedding the P3 Speller matrix and it works great at the moment.
I make a small contribution on the implementation of BCI2000Remote.py because I ran into some issues that were fortunately easy to solve.
GetSystemStates () did not correctly return the system state 'Resting', 'Running', 'Suspended', etc.
In my case this was fixed by simply changing
by
I needed to add the string name as an argument for that to be the result, but maybe there is another way to do it
In the GetStateVariable (self, name) function the return is simply missing. For this you only need to add "return result.value" at the end
Greetings
Thank you very much for your help. I have finally made the application by embedding the P3 Speller matrix and it works great at the moment.
I make a small contribution on the implementation of BCI2000Remote.py because I ran into some issues that were fortunately easy to solve.
GetSystemStates () did not correctly return the system state 'Resting', 'Running', 'Suspended', etc.
In my case this was fixed by simply changing
Code: Select all
GetSystemStates (self):
return self._lib.BCI2000Remote_GetSystemState (self._instance)
Code: Select all
GetSystemStates (self, name):
return self._get_string_result (self._lib.BCI2000Remote_GetSystemState, string_arg (name))
In the GetStateVariable (self, name) function the return is simply missing. For this you only need to add "return result.value" at the end
Greetings
Re: embedding the P3 Speller in a Python application
Hi,
thanks a lot for sharing this.
Best regards,
Jürgen
thanks a lot for sharing this.
Straightforward fix, thank you.In the GetStateVariable (self, name) function the return is simply missing. For this you only need to add "return result.value" at the end
There is no function with this name. I assume you mean GetSystemState()? That function does not take an argument, what would you specify as such when calling your version? What happened when you called the original version?GetSystemStates () did not correctly return the system state 'Resting', 'Running', 'Suspended', etc.
Best regards,
Jürgen
Re: embedding the P3 Speller in a Python application
Hi,mellinger wrote: ↑29 Oct 2020, 11:20 Hi,
thanks a lot for sharing this.Straightforward fix, thank you.In the GetStateVariable (self, name) function the return is simply missing. For this you only need to add "return result.value" at the end
There is no function with this name. I assume you mean GetSystemState()? That function does not take an argument, what would you specify as such when calling your version? What happened when you called the original version?GetSystemStates () did not correctly return the system state 'Resting', 'Running', 'Suspended', etc.
Best regards,
Jürgen
I apologize for the delay. As you said, I was referring to the GetSystemState () function. As I said earlier, I'm not sure this is the most practical solution, however the function as it was:
Code: Select all
def GetSystemState (self):
return self._lib.BCI2000Remote_GetSystemState (self._instance)
Code: Select all
def GetSystemState (self):
return self._get_string_result (self._lib.BCI2000Remote_GetSystemState)
Re: embedding the P3 Speller in a Python application
I see. I applied the GetSystemState() fix as well.
Thanks and regards,
Juergen
Thanks and regards,
Juergen
Who is online
Users browsing this forum: No registered users and 23 guests