Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tkinter alternative backend for GUI #4

Open
ashwinvis opened this issue Nov 13, 2017 · 12 comments
Open

Tkinter alternative backend for GUI #4

ashwinvis opened this issue Nov 13, 2017 · 12 comments

Comments

@ashwinvis
Copy link
Owner

As of now PyQt5 and PySide are supported.

@Neon22
Copy link
Contributor

Neon22 commented Jan 30, 2025

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

@ashwinvis
Copy link
Owner Author

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.

@Neon22
Copy link
Contributor

Neon22 commented Feb 3, 2025

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
Copy link
Contributor

Neon22 commented Feb 3, 2025

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":

@ashwinvis
Copy link
Owner Author

  • 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.
    self.keys = [
    "M",
    "p_p0",
    "rho_rho0",
    "T_T0",
    "Mt",
    "p_pt",
    "rho_rhot",
    "T_Tt",
    "A_Astar",
    ]
    super().__init__(gamma=gamma)

@Neon22
Copy link
Contributor

Neon22 commented Feb 3, 2025

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:

@Neon22
Copy link
Contributor

Neon22 commented Feb 4, 2025

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

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.

@ashwinvis
Copy link
Owner Author

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

@Neon22
Copy link
Contributor

Neon22 commented Feb 6, 2025

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

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

@ashwinvis
Copy link
Owner Author

@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

@Neon22
Copy link
Contributor

Neon22 commented Feb 6, 2025

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...

@ashwinvis
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants