In [3]:
%%writefile RuslansCode.py
#!/usr/bin/env python
"""
Created on Thur Jan 19 13:20:10 2017
@author: Ruslan Brilenkov
"""
import os
import wx
import random
from numpy import *
#from numpy import arange, sin, pi
import numpy as np
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
#from Tkinter import Tk
class MainWindow(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(640,400))
#self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
self.CreateStatusBar() # A StatusBar in the bottom of the window
# Setting up the menu.
filemenu= wx.Menu()
# wx.ID_ABOUT and 11wx.ID_EXIT are standard ids provided by wxWidgets.
#menuOpen = filemenu.Append(wx.ID_OPEN, "&Open"," Open text file")
menuHelp = filemenu.Append(wx.ID_HELP, "&Help"," Get some help")
menuAbout = filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
menuExit = filemenu.Append(wx.ID_EXIT,"E&xit"," Terminate the program")
# Creating the menubar.
menuBar = wx.MenuBar()
menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content.
# Set events.
#self.Bind(wx.EVT_MENU, self.OnOpen, menuOpen)
self.Bind(wx.EVT_MENU, self.OnHelp, menuHelp)
self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
self.functionText = wx.TextCtrl(self, value = "", size = (200, -1))
#Let us plot the figure as an example
self.figure = Figure()
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self, -1, self.figure)
self.phasesList = ["Linear", "Polynomial", "Sinusoidal", "Exponential", "Logarythmic"]
#self.combo = wx.ComboBox(self, choices=phasesList)
self.combo = wx.ComboBox(self, choices=self.phasesList, style=wx.CB_DROPDOWN)
self.combo.Bind(wx.EVT_COMBOBOX, self.EvtComboBox)
self.sizer3 = wx.BoxSizer(wx.HORIZONTAL)
self.buttons = []
names = ["Plot","Definitely Not Exit"]
for i in range(0, 2):
self.buttons.append(wx.Button(self, -1, names[i]))
self.sizer3.Add(self.buttons[i], 1, wx.ALIGN_CENTER)
self.plotButton = self.buttons[0]
self.Bind(wx.EVT_BUTTON, self.OnClickPlot, self.plotButton)
self.Bind(wx.EVT_BUTTON, self.OnClickNoExit, self.buttons[1])
'''
self.colors = []
colorNames = ['Red','Green','Blue','Orange','Pink','Cyan','STEEL BLUE','Dark Olive Green', 'MEDIUM SPRING GREEN', 'DARK ORCHID']
for i in range(0, 10):
colors[i] = colorNames[i]
'''
#--------------------------------------------------------------------
#--------------------------------------------------------------------
# Radio Boxes for Color and Style
colorList = ['CYAN', 'NAVY', 'SALMON', 'ORCHID', 'FIREBRICK', 'GOLDENROD']
self.colorRadioBox = wx.RadioBox(self, label = "Color:", choices = colorList, majorDimension = 1,
style = wx.RA_SPECIFY_COLS)
styleList = ['Solid', 'Dotted', 'Dashed']
self.styleRadioBox = wx.RadioBox(self, label = "Style:", choices = styleList, majorDimension = 1,
style = wx.RA_SPECIFY_COLS)
# Addint the fourths line - Advanced settings
self.sizer5 = wx.BoxSizer(wx.HORIZONTAL)
self.colorSizer = wx.BoxSizer(wx.VERTICAL)
self.styleSizer = wx.BoxSizer(wx.VERTICAL)
# Adding the Advanced settings - Color, Style etc.
self.colorSizer.Add(self.colorRadioBox, proportion = 0, border = 2, flag=wx.ALL)
self.styleSizer.Add(self.styleRadioBox, proportion = 0, border = 2, flag=wx.ALL)
self.sizer5.Add(self.colorSizer, proportion = 0, border = 2, flag=wx.ALL)
self.sizer5.Add(self.styleSizer, proportion = 0, border = 2, flag=wx.ALL)
# Summoning methods from RadioBoxes
self.Bind(wx.EVT_RADIOBOX, self.EvtColorRadioBox, self.colorRadioBox)
self.Bind(wx.EVT_RADIOBOX, self.EvtStyleRadioBox, self.styleRadioBox)
#--------------------------------------------------------------------
#--------------------------------------------------------------------
self.sizer4 = wx.BoxSizer(wx.VERTICAL)
self.sizer4.Add(self.functionText, 0, wx.ALIGN_CENTER | wx.EXPAND)
self.sizer4.Add(self.combo, 0, wx.ALIGN_CENTER | wx.EXPAND)
self.sizer4.Add(self.sizer5, 0, wx.ALIGN_CENTER)
self.sizer4.Add(self.sizer3, 0, wx.ALIGN_CENTER | wx.ALIGN_RIGHT)
self.sizer = wx.BoxSizer(wx.HORIZONTAL)
self.sizer.Add(self.sizer4, 1, wx.ALIGN_CENTER)
self.sizer.Add(self.canvas, 1, wx.EXPAND)
self.SetSizer(self.sizer)
self.Show(True)
def EvtRadioBox(self, event):
# A message dialog box with an OK button.
dlg = wx.MessageDialog( self, "Welcome to my Final Project. \nHere you can plot the most commonnly used functions. \nMy final project for the Programming course. \nFor the collaboration or additional info wisit my We-site: https://github.com/Krayfer/Final-Final \nE-mail: ruslan.brilenkov@gmail.com \nPhone: +xxxxxxxxx \nRuslan Brilenkov. \n \n ------------------ \nAll rights reserved(c)",
"About Ruslan's Work", wx.OK)
dlg.ShowModal() # Show it
dlg.Destroy() # finally destroy it when finished.
def EvtComboBox(self, event):
#self.data = np.linspace(0,10,100)
if event.GetString() == self.phasesList[0]:
self.function = "2*x +3"
self.functionText.SetValue("2x +3")
elif event.GetString() == self.phasesList[1]:
self.function = "2*x**2 +3*x +4"
self.functionText.SetValue("2*x^2 +3*x +4")
elif event.GetString() == self.phasesList[2]:
self.function = "sin(2*x +3)"
self.functionText.SetValue("Sin[2x +3]")
elif event.GetString() == self.phasesList[3]:
self.function = "exp(2*x +3)"
self.functionText.SetValue("Exp[2x +3]")
elif event.GetString() == self.phasesList[4]:
self.function = "log(2*x +3)"
self.functionText.SetValue("Log[2x +3]")
else:
return()
def OnHelp(self,e):
# A message dialog box with an OK button.
dlg = wx.MessageDialog( self, "1. Chose the function; \n2. Press the button \"Plot\"; \n3. Enjoy the view.", "Help dialogue", wx.OK)
dlg.ShowModal() # Show it
dlg.Destroy() # finally destroy it when finished.
def OnAbout(self,e):
# A message dialog box with an OK button.
dlg = wx.MessageDialog( self, "Welcome to my Final Project. \nHere you can plot the most commonnly used functions. \nMy final project for the Programming course. \nFor collaboration or Additional Info visit: https://github.com/Krayfer/Final-Final/ \nE-mail. ruslan.brilenkov@gmail.com \nPhone: +3xxxxxxxxx \nRuslan Brilenkov. \n \n ------------------ \nAll rights reserved(c)",
"About Ruslan's Work", wx.OK)
dlg.ShowModal() # Show it
dlg.Destroy() # finally destroy it when finished.
def OnClickNoExit(self,e):
#self.Close(True) # Close the frame.
dlg = wx.MessageDialog( self, "There is no Exit.", "Fatal Error", wx.OK)
dlg.ShowModal() # Show it
dlg.Destroy() # finally destroy it when finished.
def OnExit(self,e):
self.Close(True) # Close the frame.
def OnClickPlot(self, e):
self.figure.set_canvas(self.canvas)
# Clearing the axes
self.axes.clear()
# Setting the axes values
x = np.arange(0, 5, 0.1)
# Converting what is written in our Box into formulas
self.axes.plot(x, eval(self.function), color = _color, linewidth = _style_width, linestyle = _style_shape)
#self.axes.plot(range(int(self.editFunction.GetValue())), color = 'green')
self.canvas.draw()
# Method for shosing color of your graph
def EvtColorRadioBox(self, event):
i = event.GetInt()
global _color
_color = 'orange'
#print i
if (i == 0):
_color = 'CYAN'
elif (i == 1):
_color = 'NAVY'
elif (i == 2):
_color = 'SALMON'
elif (i == 3):
_color = 'ORCHID'
elif (i == 4):
_color = 'FIREBRICK'
elif (i == 5):
_color = 'GOLDENROD'
else:
_color = 'green'
#print _color
return _color
# Method for chosing color of your graph
def EvtStyleRadioBox(self, event):
i = event.GetInt()
global _style_shape
global _style_width
if (i == 0):
_style_shape = 'solid'
_style_width = 2
elif (i == 1):
_style_shape = 'dotted'
_style_width = 5
elif (i == 2):
_style_shape = 'dashed'
_style_width = 3
return (style_shape, style_width)
app = wx.App(False)
frame = MainWindow(None, "Ruslan's Project")
app.MainLoop()
In [4]:
!python RuslansCode.py
In [ ]: