Old 09-21-2017, 06:00 AM   #1
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,844
Default Python & Tkinter for ReaScript GUI

Hi Scripters !

I just succeeded to install Python x64 and make it works with REAPER.

I wanted to experiment GUI creation with Tkinter, a GUI framework for python.

It's been a while since we didn't see someone coding a ReaScript in Python. Python is sure less portable than Lua/EEL with REAPER, but I think nice things can still be made with it.

We can't import external Lua libraries, but we can import external Python libraries for eg.

Also, as Tkinter GUI element are "recognized" by the OS as such (and not like a Canvas like with JSFX), it is really great for accessibility (tab navigation between buttons with ability for the OS to recognize the text, for text to speech assistant for example), and for providing a lot of extra functions that would have to be coded from 0 with GFX.

One downside with Tkinter windows is that they can't be docked, or pin on top (you can use an external software for that).

There is various GUI elements with tkinter, and a lot of doc online.
Here is a french page which have a screenshots for each element.

With it you can build complex (and accessible !) GUI like, ReaChorder.

I just made something I wanted since a long time: a Multiline Text Input, which also have all keyboard shortcut than the OS can offer (Select All, Copy, Select, Maj+click etc...):



(very useful script)

So, despite that Lua is still super cool for ease of development and portability, EEL for speed efficiency, I think Python is still a valid choice for ReaScript, for building accessible and complex GUI.

The Multiline text input script is only 60 lines of code.

What do you think ?
X-Raym is offline   Reply With Quote
Old 09-21-2017, 06:43 AM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,844
Default

Plus, you can play snake :P

From: Jeu du serpent (Snake) en Python (Tkinter) - Tableaux Maths

X-Raym is offline   Reply With Quote
Old 09-21-2017, 11:42 AM   #3
me2beats
Human being with feelings
 
me2beats's Avatar
 
Join Date: Jul 2015
Location: Yekaterinburg, Russia
Posts: 400
Default

Very interesting)
__________________
My Reapack Repo
Donation
me2beats is offline   Reply With Quote
Old 09-21-2017, 09:28 PM   #4
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 1,463
Default

hi, x.

i worked with breeder several years ago with this kind of thing. i found the python/tkinter approach to be very clunky and too deeply layered for practical purposes. it got to be a problem when upgrading to keep everything compatible, at least for this non-scripter. we used tkinter to create a gui with text and checkboxes.

i think the main thing we worked on was a script for copy/paste of item attributes, things like volume, pan, etc. from one item to another. spk77 later replicated the script in eel which i actually find much better. having the scripting reliant on three separate layers, reaper/python/tkinter, rather than just reaper seemed like too much work over time. at the time we did it, though, eel had not yet shown up in reaper so it was the only way to go.

don't mean to be discouraging. be very curious to see if things have gotten simpler over time, especially with all of the great scripter, such as yourself, working with reaper now.

edit:
found a thread from a little over four years ago about what we were doing:

https://forum.cockos.com/showthread.php?t=123583

thanks,
BabaG

Last edited by babag; 09-21-2017 at 09:44 PM.
babag is offline   Reply With Quote
Old 09-22-2017, 02:14 AM   #5
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,844
Default

hi babag,

thanks for sharing your experience on the subject !

you are right, as it as more dependencies, updates are more supposed to break things, ans as they must be installed by the user himself, there is a bigger risk a errors.

for simple buttons or sliders then indeed EEL/Lua can do the trick nicely.
But for some kind of input, like this full featured multiline text input, there is no alternative than Tkinter. Indeed, GFX windows are canvas, where your print stuffs. text is not recognized as such by the OS. building a multiline text editor with that will be very hard and not even acessible.

Fortunatly, Reapack brings script updates more easily (in case there is something to fix) and python 3 is here a while now, so I think it is more solid and friendly with backward compatibility.

We'll have to keep your warnings in mind anyway. ReaScript in Python may have some pitfalls. but he has few things to offer that worths the try

also, the beyond.reaper projects seems very interting (but I don't fully understand in what case to use it)
https://forum.cockos.com/showthread.php?t=129696
X-Raym is offline   Reply With Quote
Old 09-22-2017, 05:54 AM   #6
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Germany
Posts: 5,010
Default

Quote:
Originally Posted by X-Raym View Post
also, the beyond.reaper projects seems very interting (but I don't fully understand in what case to use it)
Simply put beyond.reaper.python tunnels the complete interface between reaper and a python script through OSC, so that you can run it as an external program (on the same or a network-attached box). Hence you can do your python program stand-alone outside of Reaper.

A friend of mine did a fairly complex application that way using Reaper as an external functionality remote-controlled by his application.

-Michael
__________________
www.boa-sorte.de
mschnell is offline   Reply With Quote
Old 09-22-2017, 08:22 AM   #7
Bri1
Human being with feelings
 
Bri1's Avatar
 
Join Date: Dec 2016
Location: England
Posts: 1,602
Default

Quote:
Hi Scripters !

I just succeeded to install Python x64 and make it works with REAPER.

What do you think ?
No proper scripter here but,i think this is the way to seemlessly integrate some blender functions!!
exe.llent that 1 now knows the routes they may go.
There's all sorts of wikkid stuff thats pre made--osl+shaders as well.
Would be rea_lly nice to port some of these nice tools.
Even some of the milkdrop2 code is quite nice(not .py though don't think)
Bri1 is offline   Reply With Quote
Old 09-25-2017, 05:53 PM   #8
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,844
Default

@mschnell
Thanks for the precision!

@all
I put a minimal Python Tkinter template for ReaScript on ReaTeam Template repo, if you want to experiment:
ReaScripts-Templates/X-Raym_Basic tkinter python.py at master · ReaTeam/ReaScripts-Templates

You only need to add your own buttons,


Note that there is also several possible layout

GUI Programming with Python: Layout Management in Tkinter

Have fun!
X-Raym is offline   Reply With Quote
Old 06-14-2018, 12:29 AM   #9
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,844
Default

Ok, I don't know how I miss that but I found few broken things with running Tkinter inside REAPER:
  • If the script is running, you will not be able to click any action on the action list
  • It stills keyboard focus even if not in front!
So yes, using beyond.reaper is the solution for tkinter integration. Though, it is not very user friendly to set up (there is a great doc, but there is quite some technical stuff to do. A script may be done to simplify the process a bit by auto creating settings files based on user configuration, and even by putting beyond.reaper on reapack).
X-Raym is offline   Reply With Quote
Old 06-14-2018, 01:50 PM   #10
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 1,847
Default

I wonder whether it would it be possible to integrate wxWidgets into SWS?
juliansader is online now   Reply With Quote
Old 06-14-2018, 02:17 PM   #11
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,844
Default

@juliansader
Interesting idea. I have absolutely no idea what would be possible, we need SWS specialist feedback... Maybe open a thread :P


Have you tested it outside REAPER ? Is it good and well documented ?
Lastupdate on sourceforge is from 2012.... :S


Most modern Lua GUI are Corona or Love2D.



Also, SWS or maybe dedicated extension, based on myreaperplugin.


Ultimatly, if Lua in REAPER could load C libraries it would solve every problem I think. It would then not be needed to encapsulate things in extension.


--
I also wonder if a beyond.reaper in Lua could be written, to let external lua apps have access to REAPER API.


Lots of things to explore :P
X-Raym is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:50 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.