From: Sébastien CHAZALLET Date: Fri, 14 Jun 2013 08:36:20 +0000 (+0200) Subject: Mise en place de la structure de fichiers X-Git-Url: http://git.inspyration.org/?p=oegtk%2Feasy_starter.git;a=commitdiff_plain;h=7965b4b010cec0b6de5db69a3f0e0e71a3240638 Mise en place de la structure de fichiers --- diff --git a/test/__init__.py b/test/__init__.py index e69de29..9d16732 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -0,0 +1,12 @@ +from ihm import GladeWindowManager +from ihm import MainWindow + +from manager import test_action_on_start_button + +GladeWindowManager.append("OpenERPEasyStarter.glade") +appli = MainWindow() + +if __name__ == "__main__": + # Test de l'application. + appli.set_action_on_start_button(test_action_on_start_button) + appli.start() diff --git a/test/ihm.py b/test/ihm.py new file mode 100644 index 0000000..30b5684 --- /dev/null +++ b/test/ihm.py @@ -0,0 +1,84 @@ +#!/usr/bin/python3 +#-*- coding: utf-8 -*- + + +from gi.repository import Gtk + + +class GladeWindowManager: + builder = Gtk.Builder() + + @classmethod + def append(cls, glade_file): + cls.builder.add_from_file(glade_file) + + @classmethod + def initWindow(cls, window_name, window_instance): + cls.builder.connect_signals(window_instance) + return cls.builder.get_object(window_name) + + +class MainWindow: + + @staticmethod + def start(): + Gtk.main() + + def on_window_destroy(self, widget, data=None): + Gtk.main_quit() + + def __init__(self): + self.window = GladeWindowManager.initWindow("main_window", self) + self.window.show_all() + + def set_action_on_start_button(self, action): + self.action_on_start_button = action + + @staticmethod + def _get_all_textlines_from_buffer(buffer): + start, end = buffer.get_start_iter(), buffer.get_end_iter() + return buffer.get_text(start, end, True).splitlines() + + def on_start_button_clicked(self, widget, data=None): + # Récupération des widgets utiles à partir du widget général + grid = widget.get_children()[0].get_children()[1] + widgets = [e.get_children() for e in grid.get_children() + if type(e) != Gtk.Label] + # Récupération des valeurs dans "Scripts" + scripts = self._get_all_textlines_from_buffer( + widgets[0][0].get_buffer() + ) + # Récupération des valeurs dans "Bases" + bases = self._get_all_textlines_from_buffer( + widgets[1][0].get_buffer() + ) + # Récupération des valeurs dans "Modules" + modules = self._get_all_textlines_from_buffer( + widgets[2][0].get_buffer() + ) + # Récupération de la valeur dans "Actions" + action = [rb.get_label() for rb in widgets[3] if rb.get_active()][0] + + # Appel de l'action à réaliser lorsque l'on clique sur le bouton + self.action_on_start_button(action, modules, bases, scripts) + +if __name__ == "__main__": + GladeWindowManager.append("OpenERPEasyStarter.glade") + appli = MainWindow() + + # Définition d'une action de test + def test_action_on_start_button(action, modules, bases, scripts): + print("""Éléments récupérés : +modules : +%s +bases +%s +scripts +%s +action +%s""" % (modules, bases, scripts, action)) + + # Connection de l'action à l'IHM + appli.set_action_on_start_button(test_action_on_start_button) + # Lancement de l'IHM + appli.start() diff --git a/test/manager.py b/test/manager.py new file mode 100644 index 0000000..be7a746 --- /dev/null +++ b/test/manager.py @@ -0,0 +1,14 @@ +#!/usr/bin/python3 +#-*- coding: utf-8 -*- + + +def test_action_on_start_button(action, modules, bases, scripts): + print("""Éléments récupérés : +modules : +%s +bases +%s +scripts +%s +action +%s""" % (modules, bases, scripts, action)) diff --git a/test/test.py b/test/test.py deleted file mode 100644 index 60c5805..0000000 --- a/test/test.py +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/python3 -#-*- coding: utf-8 -*- - - -from gi.repository import Gtk - - -class GladeWindowManager: - builder = Gtk.Builder() - - @classmethod - def append(cls, glade_file): - cls.builder.add_from_file(glade_file) - - @classmethod - def initWindow(cls, window_name, window_instance): - cls.builder.connect_signals(window_instance) - return cls.builder.get_object(window_name) - - -class TestMainWindow: - - def on_window_destroy(self, widget, data=None): - Gtk.main_quit() - - def __init__(self): - self.window = GladeWindowManager.initWindow("main_window", self) - self.window.show_all() - - @staticmethod - def _get_all_textlines_from_buffer(buffer): - start, end = buffer.get_start_iter(), buffer.get_end_iter() - return buffer.get_text(start, end, True).splitlines() - - def on_start_button_clicked(self, widget, data=None): - # Récupération des widgets utiles à partir du widget général - grid = widget.get_children()[0].get_children()[1] - widgets = [e.get_children() for e in grid.get_children() - if type(e) != Gtk.Label] - # Récupération des valeurs dans "Scripts" - scripts = self._get_all_textlines_from_buffer( - widgets[0][0].get_buffer() - ) - # Récupération des valeurs dans "Bases" - bases = self._get_all_textlines_from_buffer( - widgets[1][0].get_buffer() - ) - # Récupération des valeurs dans "Modules" - modules = self._get_all_textlines_from_buffer( - widgets[2][0].get_buffer() - ) - # Récupération de la valeur dans "Actions" - action = [rb.get_label() for rb in widgets[3] if rb.get_active()][0] - print("""Éléments récupérés : -modules : -%s -bases -%s -scripts -%s -action -%s""" % (modules, bases, scripts, action)) - - -if __name__ == "__main__": - GladeWindowManager.append("OpenERPEasyStarter.glade") - appli = TestMainWindow() - Gtk.main() \ No newline at end of file