Skip to content
Extraits de code Groupes Projets
Valider 9b67942c rédigé par Philippe Roy's avatar Philippe Roy
Parcourir les fichiers

Mise en place de wxPython

parent a40d1963
Aucune branche associée trouvée
Étiquettes v1.1
Aucune requête de fusion associée trouvée
Pipeline #81180 réussi
......@@ -88,7 +88,8 @@ Les bibliothèques suivantes ne sont pas incluses par défaut dans l'environneme
- [**Matplotlib**](https://matplotlib.org) : grapheur (visualisation de données)
- [**SciPy**](https://scipy.org/) : calcul scientifique (algèbre linéaire, statistiques, traitement du signal, traitement d'image, ...)
- [**Robotics Toolbox for Python**](https://github.com/petercorke/robotics-toolbox-python) : solveur de cinématique inverse
- [**PyGObject**](https://pygobject.gnome.org/) : interface graphique utilisateur GTK+3
- [**PyGObject**](https://pygobject.gnome.org/) : interface graphique utilisateur GTK+3 pour GNU/Linux
- [**wxPython**](https://www.wxpython.org/) : interface graphique utilisateur pour Windows
Certaines bibliothèques ne peuvent pas être installées avec leur version la plus récente :
- **Pylint** : l'API n'est pas assez stable -> **version 3.1.0**
......@@ -106,12 +107,6 @@ Il faut donc les installer localement (dans UPBGE), les étapes sont :
- Installer Robotics Toolbox for Python version 1.1.0 : $ ./pip install roboticstoolbox-python==1.1.0
- Installer PyGObject : $ ./pip install PyGObject
<!-- - Installer Pylint : $ ./pip install pylint -t ~/UPBGE-0.30-linux-x86_64/3.0/python/lib/python3.9/site-packages -->
<!-- - Installer pySerial : $ ./pip install pyserial -t ~/UPBGE-0.30-linux-x86_64/3.0/python/lib/python3.9/site-packages -->
<!-- - Installer pyFirmata : $ ./pip install pyfirmata -t ~/UPBGE-0.30-linux-x86_64/3.0/python/lib/python3.9/site-packages -->
<!-- - Installer Matplotlib : $ ./pip install matplotlib -t ~/UPBGE-0.30-linux-x86_64/3.0/python/lib/python3.9/site-packages -->
<!-- - Installer PyQt6 : $ ./pip install PyQt6 -t ~/UPBGE-0.30-linux-x86_64/3.0/python/lib/python3.9/site-packages -->
- **Windows** : La configuration ici présente est UPBGE installé sur le bureau utilisateur (prenom.nom) :
- Ouvrir un terminal Powershell (éventuellement en passant par Anaconda Navigator)
- Aller dans le répertoire local de Python de UPBGE: cd C:\Users\prenom.nom\Desktop\upbge-0.36.1-windows-x86_64\3.6\python\bin
......@@ -122,7 +117,7 @@ Il faut donc les installer localement (dans UPBGE), les étapes sont :
- Installer pySerial : pip.exe install pyserial
- Installer SciPy version 1.11.1 : pip.exe install scipy==1.11.1
- Installer Robotics Toolbox for Python version 1.1.0 : pip.exe install roboticstoolbox-python==1.1.0
- Installer PyGObject : pip.exe install PyGObject
- Installer wxPython : pip.exe install wxpython
- Si l'installation des paquets Python ne se fait pas dans le bon répertoire ('site-packages' des bibliothèques du Python embarqué par UPBGE), il faut allors spécifier le répertoire cible avec
l'option '-t target' lors de la commande 'pip install'. Par exemple pour Pylint :
......
import os, sys
import gi # GTK+3
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from gi.repository import GdkPixbuf
###############################################################################
# about.py
# @title: Fenêtre A propos
# @project: Bras MKX3D
# @lang: fr
# @authors: Philippe Roy <phroy@phroy.org>
# @copyright: Copyright (C) 2024-2025 Philippe Roy
# @license: GNU GPL
###############################################################################
##
# Ce programme est un logiciel libre ; vous pouvez le redistribuer et/ou le modifier
# sous les termes de la licence publique générale GNU telle qu'elle est publiée par
# la Free Software Foundation ; soit la version 3 de la licence, ou
# (comme vous voulez) toute version ultérieure.
#
# Ce programme est distribué dans l'espoir qu'il sera utile,
# mais SANS AUCUNE GARANTIE ; même sans la garantie de
# COMMERCIALITÉ ou d'ADÉQUATION A UN BUT PARTICULIER. Voir la
# licence publique générale GNU pour plus de détails.
#
# Vous devriez avoir reçu une copie de la licence publique générale GNU
# avec ce programme. Si ce n'est pas le cas, voir <http://www.gnu.org/licenses/>.
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##
# Boucle principale
if __name__ == "__main__":
# Thème
theme = int(sys.argv[1])
if theme == 1:
Gtk.Settings.get_default().set_property("gtk-theme-name", "Adwaita-dark") # Thème dark
else:
Gtk.Settings.get_default().set_property("gtk-theme-name", "Adwaita") # Thème clair
# Fenêtre
dialog = Gtk.AboutDialog()
dialog.set_program_name("Bras MKX3D")
dialog.set_version("1.2")
dialog.set_title("Jumeau numérique du Bras MKX3D")
dialog.set_name("Jumeau numérique du Bras MKX3D")
dialog.set_comments("Jumeau numérique du bras MKX3D")
dialog.set_logo(GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.join(os.getcwd(),"asset","icons","app","bras_mkx3d.png"), 128, 128))
# Website
dialog.set_website_label("Dépôt Git - La Forge")
dialog.set_website("https://forge.apps.education.fr/bras-mkx3d/jumeau-numerique")
# Copyright
dialog.set_copyright("© 2024-2025 Philippe Roy - Licence GNU GPL 3.0")
# Licence
dialog.set_wrap_license(True)
dialog.set_license_type(Gtk.License.GPL_3_0_ONLY)
dialog.set_license("""Ce programme est un logiciel libre ; vous pouvez le redistribuer et/ou le modifier sous les termes de la licence publique générale GNU telle qu'elle est publiée par la Free Software Foundation ; soit la version 3 de la licence, ou (comme vous voulez) toute version ultérieure.
Ce programme est distribué dans l'espoir qu'il sera utile, mais SANS AUCUNE GARANTIE ; même sans la garantie de COMMERCIALITÉ ou d'ADÉQUATION A UN BUT PARTICULIER. Voir la licence publique générale GNU pour plus de détails.
Vous devriez avoir reçu une copie de la licence publique générale GNU avec ce programme. Si ce n'est pas le cas, voir http://www.gnu.org/licenses/ .""")
# # This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# # You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.""")
# # dialog.connect('response', lambda dialog, data: dialog.destroy())
# Crédits
dialog.set_authors(["Philippe Roy https://forge.apps.education.fr/phroy"])
dialog.add_credit_section(" ", [" "])
credits_description = {
'Modèle CAO du Bras' : ["Modèle CAO du Bras","Dépôt du modèle 3D","https://forge.apps.education.fr/bras-mkx3d/modele-3d/", "CC BY-NC-SA 4.0"],
'Blender' : ["Blender","Plateforme de modélisation et d\'animation 3D","https://blender.org", "GNU GPL"],
'UPBGE' : ["UPBGE","Moteur de jeu 3D","https://upbge.org", "GNU GPL"],
'Python' : ["Python","Langage de programmation","https://python.org", "PSFL"],
'Pylint' : ["Pylint","Bibliothèque de vérification d\'un code Python","https://pylint.pycqa.org", "GNU GPL"],
'pySerial' : ["pySerial","Bibliothèque de communication série","https://pyserial.readthedocs.io", "BSD-3-Clause"],
'Robotics Toolbox for Python' : ["Robotics Toolbox for Python","Solveur de cinématique inverse","https://github.com/petercorke/robotics-toolbox-python", "MIT Licence"],
'Matplotlib' : ["Matplotlib","Bibliothèque de visualisation graphique de données","https://matplotlib.org", "BSD"],
'GTK+3' : ["GTK+3","Bibliothèque GUI","https://www.gtk.org/", "GNU LGPL 2.1"],
'PyGObject' : ["PyGObject","API Python de GTK","https://pygobject.gnome.org/", "GNU LGPL 2.1"],
'Game-icons.net' : ["Game-icons.net","Icônes","https://game-icons.net/","CC BY 3.0"],
'Kenney' : ["Kenney","Icônes","https://www.kenney.nl/","CC0 1.0"],
'EspressoDolce' : ["Espresso Dolce","Police de caractères","https://www.dafont.com/fr/espresso-dolce.font", "OFL"],
'Sphinx' : ["Sphinx","Générateur de documentation","https://www.sphinx-doc.org/", "BSD"]}
credits_description_list=list(credits_description)
for i in range(len(credits_description_list)):
dialog.add_credit_section(credits_description[credits_description_list[i]][0],
[f"{credits_description[credits_description_list[i]][1]}"+
f"{credits_description[credits_description_list[i]][2]} - "+
f"{credits_description[credits_description_list[i]][3]}"])
# Affichage
dialog.show_all()
dialog.connect("destroy", Gtk.main_quit)
Gtk.main()
import sys
import gi # GTK+3
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk
###############################################################################
# config.py
# @title: Configurateur
# @project: Bras MKX3D
# @lang: fr
# @authors: Philippe Roy <phroy@phroy.org>
# @copyright: Copyright (C) 2024-2025 Philippe Roy
# @license: GNU GPL
###############################################################################
##
# Ce programme est un logiciel libre ; vous pouvez le redistribuer et/ou le modifier
# sous les termes de la licence publique générale GNU telle qu'elle est publiée par
# la Free Software Foundation ; soit la version 3 de la licence, ou
# (comme vous voulez) toute version ultérieure.
#
# Ce programme est distribué dans l'espoir qu'il sera utile,
# mais SANS AUCUNE GARANTIE ; même sans la garantie de
# COMMERCIALITÉ ou d'ADÉQUATION A UN BUT PARTICULIER. Voir la
# licence publique générale GNU pour plus de détails.
#
# Vous devriez avoir reçu une copie de la licence publique générale GNU
# avec ce programme. Si ce n'est pas le cas, voir <http://www.gnu.org/licenses/>.
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##
###############################################################################
# Fenêtre
###############################################################################
##
# Quitter
##
# Choisir une configuration
def ok_click(button, size_combo, qual_combo, theme_combo):
size= size_combo.get_active_text().split('x')
print(size[0]+","+size[1]+","+str(qual_combo.get_active())+","+str(theme_combo.get_active())) # stdout = "1280,720,1,1"
Gtk.main_quit()
# Fermer la fenêtre ou annuler
def end(win, data=None):
Gtk.main_quit()
# Sortir si ESC
def keypressed(button, event, data=None):
if event.keyval == Gdk.KEY_Escape:
Gtk.main_quit()
##
# Implantation
##
def layout(theme):
# Thème
if theme == 1:
Gtk.Settings.get_default().set_property("gtk-theme-name", "Adwaita-dark") # Thème dark
else:
Gtk.Settings.get_default().set_property("gtk-theme-name", "Adwaita") # Thème clair
# Fenêtre
win = Gtk.Window()
win.set_default_size(-1, -1)
win.set_border_width(0)
win.connect("destroy", end)
win.connect("key-release-event", keypressed)
# Barre de la fenêtre
hb = Gtk.HeaderBar()
hb.set_show_close_button(False)
hb.props.title = "Configuration du jumeau numérique du bras MKX3D"
win.set_titlebar(hb)
cancel_button = Gtk.Button(label="Annuler") # Bouton annulation
cancel_button.connect("clicked", end)
hb.pack_start(cancel_button)
ok_button = Gtk.Button(label="Sélectionner la configuration") # Bouton ok
hb.pack_end(ok_button)
# List box
win_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
win.add(win_box)
win_listbox = Gtk.ListBox()
# win_listbox.set_border_width(10)
win_listbox.set_selection_mode(Gtk.SelectionMode.NONE)
win_box.pack_start(win_listbox, True, True, 0)
# Taille de l'écran
size_row = Gtk.ListBoxRow()
win_listbox.add(size_row)
size_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
size_hbox.set_border_width(5)
size_row.add(size_hbox)
size_label = Gtk.Label(label="Taille de l'écran", xalign=0)
size_combo = Gtk.ComboBoxText()
size_combo.append("0", "640x360")
size_combo.append("1", "960x540")
size_combo.append("2", "1280x720")
size_combo.append("3", "1920x1080")
size_hbox.pack_start(size_label, True, True, 5)
size_hbox.pack_start(size_combo, False, True, 5)
# Qualité du rendu
qual_row = Gtk.ListBoxRow()
win_listbox.add(qual_row)
qual_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
qual_hbox.set_border_width(5)
qual_row.add(qual_hbox)
qual_label = Gtk.Label(label="Qualité (redémarrage nécessaire)", xalign=0)
qual_combo = Gtk.ComboBoxText()
qual_combo.append("0", "Inconvenant")
qual_combo.append("1", "Basse")
qual_combo.append("2", "Moyenne")
qual_combo.append("3", "Haute")
qual_combo.append("4", "Épique")
qual_hbox.pack_start(qual_label, True, True, 5)
qual_hbox.pack_start(qual_combo, False, True, 5)
# Thème
theme_row = Gtk.ListBoxRow()
win_listbox.add(theme_row)
theme_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
theme_hbox.set_border_width(5)
theme_row.add(theme_hbox)
theme_label = Gtk.Label(label="Thème", xalign=0)
theme_combo = Gtk.ComboBoxText()
theme_combo.append("0", "Clair")
theme_combo.append("1", "Foncé")
theme_hbox.pack_start(theme_label, True, True, 5)
theme_hbox.pack_start(theme_combo, False, True, 5)
return win, size_combo, qual_combo, theme_combo, ok_button
# Boucle principale
if __name__ == "__main__":
# Implantation de la fenêtre
twin_config = [int(i) for i in sys.argv[1].split(',')] # stdin = 1280,720,1,1
theme = twin_config[3]
win, size_combo, qual_combo, theme_combo, ok_button = layout(theme)
# Configuration courante
screen_width_mode = [640, 960, 1280, 1920]
screen_height_mode = [360, 540, 720, 1080]
screen_mode_txt=["640x360", "960x540", "1280x720", "1920x1080"]
if twin_config[0] in screen_width_mode and twin_config[1] in screen_height_mode:
size_combo.props.active = screen_width_mode.index(twin_config[0])
else:
for i in range(len(screen_width_mode)):
# print (i, int(twin_config[0][0].text), screen_width_mode[i])
if twin_config[0] < screen_width_mode[i]:
size_combo.insert(i, "10", str(twin_config[0])+"x"+str(twin_config[1]))
size_combo.props.active=i
break
qual_combo.props.active = twin_config[2]
theme_combo.props.active = theme
# Configuration sélectionnée
ok_button.connect("clicked", ok_click, size_combo, qual_combo, theme_combo)
# Go !
win.show_all()
Gtk.main()
import os, sys
import gi # GTK+3
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
###############################################################################
# file.py
# @title: Sélecteur de fichier
# @project: Bras MKX3D
# @lang: fr
# @authors: Philippe Roy <phroy@phroy.org>
# @copyright: Copyright (C) 2024-2025 Philippe Roy
# @license: GNU GPL
###############################################################################
##
# Ce programme est un logiciel libre ; vous pouvez le redistribuer et/ou le modifier
# sous les termes de la licence publique générale GNU telle qu'elle est publiée par
# la Free Software Foundation ; soit la version 3 de la licence, ou
# (comme vous voulez) toute version ultérieure.
#
# Ce programme est distribué dans l'espoir qu'il sera utile,
# mais SANS AUCUNE GARANTIE ; même sans la garantie de
# COMMERCIALITÉ ou d'ADÉQUATION A UN BUT PARTICULIER. Voir la
# licence publique générale GNU pour plus de détails.
#
# Vous devriez avoir reçu une copie de la licence publique générale GNU
# avec ce programme. Si ce n'est pas le cas, voir <http://www.gnu.org/licenses/>.
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##
# Sélection du script Python
def dialog_cmd():
dialog = Gtk.FileChooserDialog()
dialog.set_title("Sélection du fichier de commande")
filter_py = Gtk.FileFilter()
filter_py.set_name("Script Python")
filter_py.add_mime_type("text/x-python")
dialog.add_filter(filter_py)
dialog.set_current_folder(os.getcwd())
return dialog
# Sélection de la trajectoire
def dialog_traj():
dialog = Gtk.FileChooserDialog()
dialog.set_title("Sélection du fichier trajectoire")
filter_py = Gtk.FileFilter()
filter_py.set_name("Tableau CSV")
filter_py.add_mime_type("text/csv")
dialog.add_filter(filter_py)
dialog.set_current_folder(os.getcwd())
return dialog
# Boucle principale
if __name__ == "__main__":
# Thème
theme = int(sys.argv[1])
if theme == 1:
Gtk.Settings.get_default().set_property("gtk-theme-name", "Adwaita-dark") # Thème dark
else:
Gtk.Settings.get_default().set_property("gtk-theme-name", "Adwaita") # Thème clair
# Fenêtre
if sys.argv[2]=='cmd':
dialog=dialog_cmd()
if sys.argv[2]=='traj':
dialog=dialog_traj()
# Boutons
dialog.add_button("_Open", Gtk.ResponseType.OK)
dialog.add_button("_Cancel", Gtk.ResponseType.CANCEL)
dialog.set_default_response(Gtk.ResponseType.OK)
# Affichage
response = dialog.run()
if response == Gtk.ResponseType.OK:
print(dialog.get_filename())
dialog.destroy()
import wx # GUI wxPython
# if __name__ == "__main__":
# win = Gtk.Window()
# win.connect("destroy", Gtk.main_quit)
# win.show_all()
# Gtk.main()
if __name__ == "__main__":
app = wx.App()
frm = wx.Frame(None, title="Hello World")
frm.Show()
app.MainLoop()
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter