caeroc icon indicating copy to clipboard operation
caeroc copied to clipboard

Tkinter alternative backend for GUI

Open ashwinvis opened this issue 8 years ago • 12 comments

As of now PyQt5 and PySide are supported.

ashwinvis avatar Nov 13 '17 16:11 ashwinvis

Ahh, you know this would probably work pretty well in pyscript in the browser.

  • https://docs.pyscript.net/2024.11.1/user-guide/configuration/
  • can import packages from pypi
  • spohisticated GUI via the ltk - https://pyscript.github.io/ltk/?tab=0&runtime=mpy

Neon22 avatar Jan 30 '25 04:01 Neon22

That looks really interesting. Thanks for the tip @Neon22. Feel free to give it a go if you are interested and I can make the necessary changes in the packaging.

This app however will need the full CPython interpreter on WASM (i.e. not just micropython) since we have at least Numpy as a dependency as of now. Maybe it could be possible to use the math standard lib module instead, but I am not 100% sure.

ashwinvis avatar Feb 03 '25 10:02 ashwinvis

OK. Thanks. Just tried a straight import caeroc and was successful at downloading dependencies. So that was a good start. BUT :)

Tried the isentropic example and got the following errors:

  • invalid escape seq \d in a few places.
  • which may be causing the showstopper t_t0 problem it fails on.

I will keep experimenting with your examples.

<exec>:3: DeprecationWarning: 
Pyarrow will become a required dependency of pandas in the next major release of pandas (pandas 3.0),
(to allow more performant data types, such as the Arrow string type, and better interoperability with other libraries)
but was not found to be installed on your system.
If this would cause problems for you,
please provide us feedback at https://github.com/pandas-dev/pandas/issues/54466
        
/lib/python3.12/site-packages/caeroc/formulae/isentropic.py:41: SyntaxWarning: invalid escape sequence '\d'
  """
/lib/python3.12/site-packages/caeroc/formulae/isentropic.py:59: SyntaxWarning: invalid escape sequence '\d'
  """
/lib/python3.12/site-packages/caeroc/formulae/isentropic.py:77: SyntaxWarning: invalid escape sequence '\d'
  """
/lib/python3.12/site-packages/caeroc/formulae/isentropic.py:95: SyntaxWarning: invalid escape sequence '\g'
  """
/lib/python3.12/site-packages/caeroc/formulae/isentropic.py:159: SyntaxWarning: invalid escape sequence '\d'
  """
Install colorlog!
caeroc: Compressible Aerodynamics Calculator
Traceback (most recent call last):
  File "/lib/python312.zip/_pyodide/_base.py", line 597, in eval_code_async
    await CodeRunner(
  File "/lib/python312.zip/_pyodide/_base.py", line 411, in run_async
    coroutine = eval(self.code, globals, locals)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<exec>", line 17, in <module>
AttributeError: 'Isentropic' object has no attribute 't_t0'. Did you mean: 'T_T0'?

Neon22 avatar Feb 03 '25 11:02 Neon22

Here are the error messages for the Airfoil example:

  • same ctrl-d
  • I suspect the last syntax error is a change in python 3.12 (which is what pyscript is built on)
/lib/python3.12/site-packages/caeroc/formulae/isentropic.py:41: SyntaxWarning: invalid escape sequence '\d'
  """
/lib/python3.12/site-packages/caeroc/formulae/isentropic.py:59: SyntaxWarning: invalid escape sequence '\d'
  """
/lib/python3.12/site-packages/caeroc/formulae/isentropic.py:77: SyntaxWarning: invalid escape sequence '\d'
  """
/lib/python3.12/site-packages/caeroc/formulae/isentropic.py:95: SyntaxWarning: invalid escape sequence '\g'
  """
/lib/python3.12/site-packages/caeroc/formulae/isentropic.py:159: SyntaxWarning: invalid escape sequence '\d'
  """
Install colorlog!
caeroc: Compressible Aerodynamics Calculator
/lib/python3.12/site-packages/caeroc/profiles/base.py:15: SyntaxWarning: "is" with 'str' literal. Did you mean "=="?
  if bodytype is "airfoil":

Neon22 avatar Feb 03 '25 11:02 Neon22

  • SyntaxWarning needs some fixes, but those are not errors ... yet. It will be if you use Python 3.13, I suppose.
  • For the AttributeError. It is indeed T_T0. I think I forgot to change the examples. https://github.com/ashwinvis/caeroc/blob/fcab7469c9f970924193b933e52356096a11fef5/src/caeroc/formulae/isentropic.py#L26-L37

ashwinvis avatar Feb 03 '25 11:02 ashwinvis

The example: caeroc_old_single_file.py actually draws a plt even with the error and you can download a png. No code needed editing to make this work. Yay !!

The errors were:

  • also 3.12 related I think,
  • Its also possible that the versions of the dependent packages are getting the latest versions and this may cause problems. But I have not checked this specifically. Looking at the Network tab in the Inspector in Chrome shows the specific packages loaded.
<exec>:15: SyntaxWarning: "is" with 'str' literal. Did you mean "=="?
Traceback (most recent call last):
  File "/lib/python312.zip/_pyodide/_base.py", line 597, in eval_code_async
    await CodeRunner(
  File "/lib/python312.zip/_pyodide/_base.py", line 411, in run_async
    coroutine = eval(self.code, globals, locals)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<exec>", line 281, in <module>
  File "<exec>", line 227, in calc_cp_lin
TypeError: slice indices must be integers or None or have an __index__ method

The link to this example (which you can clone and edit) is:

  • https://pyscript.com/@neon22/caeroc-test/latest?files=main.py
  • I have included what's needed to add a more complex GUI (the Ltk) as well but the main.py is a straight unmodified copy of your example file. The toml and index.html setup the environment.

Neon22 avatar Feb 03 '25 11:02 Neon22

OK. I have gone back to the "Compressible Aerodynamics calculator" and added some basic UI.

  • https://pyscript.com/@neon22/caeroc-test/latest?files=main.py

But getting this error:

File "<exec>", line 231, in calc_cp_lin
TypeError: slice indices must be integers or None or have an __index__ method

The code is:

def calc_cp_lin(self, angle):
   N = angle.size / 2
   angle = angle - self.AoA
   self.cp_lin[:N] = 2 * angle[:N] / np.sqrt(self.M1**2 - 1)
   self.cp_lin[N:] = 2 * -angle[N:] / np.sqrt(self.M1**2 - 1)

and is called with:

chara.calc_cp_lin(airfoil.angle)

where airfoil.angle is a list of values

I'm keep adding the target DIV but fixing that. Let me know if you can help.

Could be a useful starting point for someone like a student to add to. Especially as they can edit it online.

Neon22 avatar Feb 04 '25 12:02 Neon22

For the error, you need to replace N = angle.size / 2 with N = angle.size // 2 to ensure the result is an integer.

ashwinvis avatar Feb 06 '25 04:02 ashwinvis

Thanks @ashwinvis. Pretty much got it all going now.

  • https://neon22.pyscriptapps.com/caeroc-test/latest/
  • Had to fix the // integer div in a few places.

Plots on the left - terminal in a slider on the right.

Neon22 avatar Feb 06 '25 11:02 Neon22

@Neon22 Very nice effort for such little time! To be honest, I don't recall if that script was right or wrong. Maybe you can check if you have training in aerospace engineering 😉. The technique was called Method of Characteristics.

Also feel free to submit a PR, so I can feature it in the README

ashwinvis avatar Feb 06 '25 18:02 ashwinvis

I will submit PR for fixed example and for link to pyscript example. Do you have any other code example, or a link to a person who has created an interesting code example. If so I will ask them if I can convert to webpage and publish. Can probably get something featured on that community and get some people coming your way maybe.

Alas I am not an aerospace engineer...

Neon22 avatar Feb 06 '25 20:02 Neon22

Do you have any other code example, or a link to a person who has created an interesting code example.

For the main calculator, the following is the class which generates the Qt GUI.

https://github.com/ashwinvis/caeroc/blob/main/src/caeroc/gui/runtime.py

If you are not familiar with Qt, it works on the concept of "Slots" which are essentially user events like pressing a button which does something to the output. I think it can be easily translated to Ltk also.

ashwinvis avatar Feb 07 '25 10:02 ashwinvis