Skip to content

Instantly share code, notes, and snippets.

@openp2pdesign openp2pdesign/template.py
Last active Aug 29, 2015

Embed
What would you like to do?
A wxGestalt template
# -*- coding: utf-8 -*-
# License: Public Domain (use it as you like!)
# Import main wxPython libraries
import wx
import wx.xrc
# Import the wxGestalt module for Gestalt Machines
import Machines.wxMachines as wxMachines
###########################################################################
## Class wxGestaltPanel
###########################################################################
class wxGestaltPanel(wx.Panel):
'''
This is the main class for the app that will be launched in the fifth tab.
Do not rename the class, or wxGestalt won't open it in the tab.
Please remember: if you print anything, it will go out to the second tab
(2. Identify the nodes). So please add a text widget and update its value
in order to show some text / values in the GUI.
'''
def __init__( self, parent ):
'''
This function initialize the interface. Add all your GUI elements here.
The self.myMachine object is the machine you initialized in the first two tabs.
Don't change it or it won't work. The self.launch_button will launch your
code, change only its position.
'''
# Initialize the panel that contains all the GUI elements
# Don't change this!
wx.Panel.__init__ ( self, parent, id = wx.ID_ANY,
pos = wx.DefaultPosition, size = wx.Size( 500,300 ),
style = wx.TAB_TRAVERSAL )
# Load the machine edited in the main app.
# Don't change this!
self.myMachine = self.GetParent().myMachine
# Create sizers for organizing the GUI elements here
self.mainSizer = wx.BoxSizer( wx.VERTICAL )
# ...
# Create GUI elements here
txt1 = "Just a text element to show you how to create GUI widgets..."
st1 = wx.StaticText(self, label=txt1, style=wx.ALIGN_CENTRE)
# ...
# Add GUI elements to the sizer here
self.mainSizer.Add(st1, flag=wx.ALL, border=5)
# ...
# Bind events to GUI widgets here
# ...
# Add a button for launching your app.
# You should only change the position of this!
self.launch_button = wx.Button( self, wx.ID_ANY, u"Run", wx.DefaultPosition, wx.DefaultSize, 0 )
self.mainSizer.Add( self.launch_button, 0, wx.ALL, 5 )
self.launch_button.Bind( wx.EVT_BUTTON, self.On_Run )
# Set up sizers and layout
# Don't change this!
self.SetSizer( self.mainSizer )
self.Layout()
def On_CalculateMoves(self):
'''
Add here the function for calculating the move instructions to be sent to the machine.
'''
# Add here your algorithm
# ...
# Store here the final moves from your algorithm
# The code below is just an example on how to structure the moves
# according to the number of nodes
if self.myMachine.nodesNumber == 1:
moves = [[10],[20],[10],[0]]
elif self.myMachine.nodesNumber == 2:
moves = [[10,10],[20,20],[10,10],[0,0]]
elif self.myMachine.nodesNumber == 3:
moves = [[10,10,10],[20,20,20],[10,10,10],[0,0,0]]
elif self.myMachine.nodesNumber == 4:
moves = [[10,10,10,10],[20,20,20,20],[10,10,10,10],[0,0,0,0]]
# Return the value
return moves
def On_Run(self, event):
'''
This function will finally control the machine after you press the "Run" button.
Do not change this function.
'''
# This will calculate the moves for your machine
moves = self.On_CalculateMoves()
# This will send the moves to the machine
self.myMachine.moveMachine(moves)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.