Permalink
Browse files

Initial GUI

  • Loading branch information...
0 parents commit cf0b9f9f907b3160c34fe0810d5610780772671b Mihai Maruseac committed Apr 27, 2011
Showing with 179 additions and 0 deletions.
  1. +20 −0 bp.py
  2. BIN res/nn.png
  3. +8 −0 src/__init__.py
  4. +14 −0 src/globaldefs.py
  5. +137 −0 src/gui.py
20 bp.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# (c) Mihai Maruseac, 341C3 (2011), mihai.maruseac@rosedu.org
+#
+
+import sys
+
+import src.gui
+
+def usage():
+ print './bp.py : Backpropagation for predictions'
+
+if __name__ == '__main__':
+ if len(sys.argv) == 1:
+ src.gui.main()
+ else:
+ usage()
+
+
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+#
+# (c) Mihai Maruseac, 341C3 (2011), mihai.maruseac@rosedu.org
+#
+# Used to enable including the sources from a parent dir (doesn't clutter the
+# workdir with .pyc files).
+#
+
@@ -0,0 +1,14 @@
+# -*- coding: utf-8 -*-
+#
+# (c) Mihai Maruseac, 341C3 (2011), mihai.maruseac@rosedu.org
+#
+# This file contains only some global definitions to avoid their duplication.
+#
+# It is safe to do from globaldefs import *
+
+TITLE = "Backprogagation forecast"
+
+IMG_FOLDER = 'res/'
+
+ICON_FILE = IMG_FOLDER + "nn.png"
+
@@ -0,0 +1,137 @@
+# -*- coding: utf-8 -*-
+#
+# (c) Mihai Maruseac, 341C3 (2011), mihai.maruseac@rosedu.org
+#
+
+import gtk
+
+from globaldefs import *
+
+class MainWindow(gtk.Window):
+ """
+ Holds the definition for the main window from the GUI and all data
+ associated with it.
+ """
+
+ def __init__(self):
+ """
+ Builds the window. Connects all the signals and displays all the
+ widgets.
+ """
+ super(MainWindow, self).__init__()
+ self.set_size_request(800, 600)
+ self.set_resizable(False)
+ self.set_title(TITLE)
+ self.set_icon_from_file(ICON_FILE)
+ self.connect('delete_event', self.__on_exit)
+
+ self._build_gui()
+
+ self.show()
+ self.show_all()
+
+ def _build_gui(self):
+ """
+ Builds the interface of this window, the entire tree of widgets.
+ """
+ _vbox = gtk.VBox()
+ self.add(_vbox)
+
+ _toolbar = self._build_toolbar()
+ _vbox.pack_start(_toolbar, False, False, 5)
+
+ def _build_toolbar(self):
+ """
+ Builds the toolbar and the associated buttons used to control the
+ application.
+
+ return the Toolbar
+ """
+ _toolbar = gtk.Toolbar()
+ _toolbar.set_orientation(gtk.ORIENTATION_HORIZONTAL)
+ _toolbar.set_style(gtk.TOOLBAR_BOTH)
+ _toolbar.set_border_width(5)
+
+ _btnNew = self._build_toolbar_button(gtk.STOCK_NEW, "New",
+ "Starts a new prediction", self.__on_new)
+ _toolbar.insert(_btnNew, -1)
+
+# _toolbar.insert(gtk.SeparatorToolItem(), -1)
+# self._build_simulation_buttons(_toolbar)
+# _toolbar.insert(gtk.SeparatorToolItem(), -1)
+# self._build_simulation_informations(_toolbar)
+# _toolbar.insert(gtk.SeparatorToolItem(), -1)
+
+ _btnAbout = self._build_toolbar_button(gtk.STOCK_ABOUT, "About",
+ "About this program", self.__on_about)
+ _toolbar.insert(_btnAbout, -1)
+
+# self._switch_playstep_buttons(False)
+ return _toolbar
+
+ def _build_toolbar_button(self, img_stock, label, tooltip, callback):
+ """
+ Adds a new button to a toolbar.
+
+ img_stock stock image to use
+ label label of button
+ tooltip tooltip for the button
+ callback callback when button is clicked
+
+ return the button
+ """
+ img = gtk.Image()
+ img.set_from_stock(img_stock, gtk.ICON_SIZE_LARGE_TOOLBAR)
+ btn = gtk.ToolButton(img, label)
+ btn.set_tooltip_text(tooltip)
+ btn.connect('clicked', callback)
+ return btn
+
+ def __on_exit(self, widget, data=None):
+ """
+ Called when destroying the main window. Leave the gtk threads (and
+ finish application).
+ """
+ gtk.main_quit()
+
+ def __on_new(self, widget, data=None):
+ """
+ Called when the user issues a request for a new game.
+ """
+ pass
+
+ def __on_about(self, widget, data=None):
+ """
+ Called when the user issues a request for the About dialog.
+ """
+ aboutDialog = gtk.AboutDialog()
+ aboutDialog.set_name(TITLE)
+ aboutDialog.set_authors(["Mihai Maruseac <mihai.maruseac@rosedu.org>"])
+ aboutDialog.set_documenters(
+ ["Mihai Maruseac <mihai.maruseac@rosedu.org>"])
+ aboutDialog.set_artists(
+ ["Art taken from Public Domain pictures on the web"])
+ aboutDialog.set_comments(
+ "Use backpropagation to forecast."
+ "\nSee README and LICENSE for more information.")
+ aboutDialog.set_copyright(
+ "Copyright © 2011 - 2012 Mihai Maruseac <mihai.maruseac@rosedu.org>")
+ aboutDialog.set_logo(self.get_icon())
+ aboutDialog.set_icon(self.get_icon())
+ aboutDialog.set_version("0.1")
+ aboutDialog.run()
+ aboutDialog.destroy()
+
+def main():
+ """
+ Main function. Construct the windows and start all application threads.
+ """
+ w = MainWindow()
+ gtk.gdk.threads_init()
+ gtk.gdk.threads_enter()
+ gtk.main()
+ gtk.gdk.threads_leave()
+
+if __name__ == '__main__':
+ main()
+

0 comments on commit cf0b9f9

Please sign in to comment.