<commit_before>from PyQt4 import QtCore, QtGui

import ReactionMaker.inversion as inversion
import ReactionMaker.duplicate as duplicate
import ReactionMaker.increment as increment
import ReactionMaker.decrement as decrement
import ReactionMaker.multiply as multiply
import ReactionMaker.logarithm as logarithm
import ReactionMaker.power as power

import Simulator.XMLParser as XMLParser
import Simulator.plot as plot

def getHistoryFileName(xmlFileName):
	y = xmlFileName[:-3]
	return 'history_' + y + 'txt'

class MainWindow(QtGui.QMainWindow):

    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.central_widget = QtGui.QStackedWidget()
        self.setCentralWidget(self.central_widget)
        self.addWidgets()

    def addWidgets(self):
		mainMenu=self.menuBar()
		mainMenu.setNativeMenuBar(False)

		# Creating main menus of GUI
		examples=mainMenu.addMenu('Examples')
		simulate= mainMenu.addMenu('Simulate')

		# Creating sub menus of examples menu
		examples.addAction("Basic Examples")
		examples.addAction("Advanced Examples")
		examples.triggered[QtGui.QAction].connect(self.exampletrigger)

		# Creating sub menus of simulate menu
		simulate.addAction("Import XML")
		simulate.addAction("Import txt")
		simulate.triggered[QtGui.QAction].connect(self.simulatetrigger)


		# Adding main welcome widget to the screen 
		welcome_widget = WelcomeScreen(self)
		self.central_widget.addWidget(welcome_widget)
		self.central_widget.setCurrentWidget(welcome_widget)

 	# Function for executuing any sub menu choosen from examples menu
    def exampletrigger(self,q):
	    if q.text() == "Basic Examples":
			print q.text()
			basic_widget = BasicWidget(self)
			self.central_widget.addWidget(basic_widget)
			self.central_widget.setCurrentWidget(basic_widget)
	    else:
			print q.text()
			advanced_widget = AdvancedWidget(self)
			self.central_widget.addWidget(advanced_widget)
			self.central_widget.setCurrentWidget(advanced_widget)		

	# Function for executuing any sub menu choosen from simulate menu
    def simulatetrigger(self,q):
		if q.text() == "Import XML":
			fname = QtGui.QFileDialog.getOpenFileName(self, 'Select XML to Import','/home')
			print fname
		else:
			fname = QtGui.QFileDialog.getOpenFileName(self, 'Select Text file to simulate','/home')
			print fname

		simulationtime, ok = QtGui.QInputDialog.getText(self, 'Input Dialog','Enter Simulation time:')
	    
		if ok:
			print simulationtime
		else:
			return

		reactantslist, ok = QtGui.QInputDialog.getText(self, 'Input Dialog','Enter Reactants to be plotted seperated by , for eg A,B,C')	    
	    
		if ok:
			if "," in str(reactantslist):
				reactantslist = str(reactantslist)
				reactantslist = reactantslist.split(",")
				print reactantslist
			else:
				c=[]
				c.append(str(reactantslist))
				reactantslist = c 
				print reactantslist
		else:
			return

		if q.text() == "Import XML":
			print "Plotting From XML File"	
			plot.plotFromXML(fname,int(simulationtime),reactantslist)
		else:
			print "Plotting From Text File"
			plot.plotFromTxt(fname,int(simulationtime),reactantslist)
	    		
class WelcomeScreen(QtGui.QWidget):
    def __init__(self,parent=None):
		super(WelcomeScreen,self).__init__(parent)
		layout=QtGui.QHBoxLayout()
		self.label=QtGui.QLabel('WELCOME!')
		layout.addWidget(self.label)
		self.setLayout(layout)

class BasicWidget(QtGui.QWidget):
    def __init__(self, parent=None):
		super(BasicWidget, self).__init__(parent)
		layout = QtGui.QHBoxLayout()

		self.inversion = QtGui.QPushButton('1) Inversion')
		layout.addWidget(self.inversion)

		self.duplication = QtGui.QPushButton('2) Duplication/Copy')
		layout.addWidget(self.duplication)

		self.decrementation = QtGui.QPushButton('3) Decrementation')
		layout.addWidget(self.decrementation)

		self.incrementation = QtGui.QPushButton('4) Incrementation')<commit_msg>Add GUI element for expression solver<commit_after>from PyQt4 import QtCore, QtGui

import ReactionMaker.inversion as inversion
import ReactionMaker.duplicate as duplicate
import ReactionMaker.increment as increment
import ReactionMaker.decrement as decrement
import ReactionMaker.multiply as multiply
import ReactionMaker.logarithm as logarithm
import ReactionMaker.power as power

import Simulator.XMLParser as XMLParser
import Simulator.plot as plot

from ExpressionSolver.solver import *

def getHistoryFileName(xmlFileName):
	y = xmlFileName[:-3]
	return 'history_' + y + 'txt'

class MainWindow(QtGui.QMainWindow):

    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.central_widget = QtGui.QStackedWidget()
        self.setCentralWidget(self.central_widget)
        self.addWidgets()

    def addWidgets(self):
		mainMenu=self.menuBar()
		mainMenu.setNativeMenuBar(False)

		# Creating main menus of GUI
		examples=mainMenu.addMenu('Examples')
		simulate= mainMenu.addMenu('Simulate')

		# Creating sub menus of examples menu
		examples.addAction("Basic Examples")
		examples.addAction("Advanced Examples")
		examples.triggered[QtGui.QAction].connect(self.exampletrigger)

		# Creating sub menus of simulate menu
		simulate.addAction("Import XML")
		simulate.addAction("Import txt")
		simulate.addAction("Expression Solver")
		simulate.triggered[QtGui.QAction].connect(self.simulatetrigger)


		# Adding main welcome widget to the screen 
		welcome_widget = WelcomeScreen(self)
		self.central_widget.addWidget(welcome_widget)
		self.central_widget.setCurrentWidget(welcome_widget)

 	# Function for executuing any sub menu choosen from examples menu
    def exampletrigger(self,q):
	    if q.text() == "Basic Examples":
			print q.text()
			basic_widget = BasicWidget(self)
			self.central_widget.addWidget(basic_widget)
			self.central_widget.setCurrentWidget(basic_widget)
	    else:
			print q.text()
			advanced_widget = AdvancedWidget(self)
			self.central_widget.addWidget(advanced_widget)
			self.central_widget.setCurrentWidget(advanced_widget)		

	# Function for executuing any sub menu choosen from simulate menu
    def simulatetrigger(self,q):
		if q.text() =="Expression Solver":

			expression, ok = QtGui.QInputDialog.getText(self, 'Input Dialog','Enter Expression :')
		    
			if ok:
				expression=str(expression)
				expression=expression.replace(" ","")
				op_out = []    #This holds the operators that are found in the string (left to right)
				num_out = []   #this holds the non-operators that are found in the string (left to right)
				operators = set('+-*/')
				buff = []
				for c in expression:  #examine 1 character at a time
				    if c in operators:  
				        #found an operator.  Everything we've accumulated in `buff` is 
				        #a single "number". Join it together and put it in `num_out`.
				        num_out.append(''.join(buff))
				        buff = []
				        op_out.append(c)
				    else:
				        #not an operator.  Just accumulate this character in buff.
				        buff.append(c)
				num_out.append(''.join(buff))   
				af=[]
				for i in range(0,len(num_out)):
					af.append(num_out[i])
					if i==len(num_out)-1:
						break   
					af.append(op_out[i])
				for i in range(0,len(af)):
				    if i==0:
				        solver = Solver(int(af[i]))
				    else:
				        if af[i]=="+":
				            solver.add(int(af[i+1]))
				        elif af[i]=="*":
				            solver.multiply(int(af[i+1]))

				solver.printTxt('expression.txt')
				print 'Expression.txt created'
			else:
				return

		if q.text() == "Import XML":
			fname = QtGui.QFileDialog.getOpenFileName(self, 'Select XML to Import','/home')
			print fname
		elif q.text() == "Import txt":
			fname = QtGui.QFileDialog.getOpenFileName(self, 'Select Text file to simulate','/home')
			print fname
		else:
			fname = "expression.txt"

		if q.text() != "Expression Solver":
			simulationtime, ok = QtGui.QInputDialog.getText(self, 'Input Dialog','Enter Simulation time:')
		else:
			simulationtime = solver.getEstimatedTimeForCompletion()
			ok = True

		if ok:
			print simulationtime
		else:
			return

		if q.text() != "Expression Solver":
			reactantslist, ok = QtGui.QInputDialog.getText(self, 'Input Dialog','Enter Reactants to be plotted seperated by , for eg A,B,C')
			if ok:
				if "," in str(reactantslist):
					reactantslist = str(reactantslist)
					reactantslist = reactantslist.split(",")
					print reactantslist
				else:
					c=[]
					c.append(str(reactantslist))
					reactantslist = c 
					print reactantslist
			else:
				return	    
		else:
			reactantslist = solver.getListOfReactionsToPlot()

		if q.text() == "Import XML":
			print "Plotting From XML File"	
			plot.plotFromXML(fname,int(simulationtime),reactantslist)
		else:
			print "Plotting From Text File"
			plot.plotFromTxt(fname,int(simulationtime),reactantslist)
	    		
class WelcomeScreen(QtGui.QWidget):
    def __init__(self,parent=None):
		super(WelcomeScreen,self).__init__(parent)
		layout=QtGui.QHBoxLayout()
		self.label=QtGui.QLabel('WELCOME!')
		layout.addWidget(self.label)
		self.setLayout(layout)

class BasicWidget(QtGui.QWidget):
    def __init__(self, parent=None):
		super(BasicWidget, self).__init__(parent)
		layout = QtGui.QHBoxLayout()

		self.inversion = QtGui.QPushButton('1) Inversion')
		layout.addWidget(self.inversion)

		self.duplication = QtGui.QPushButton('2) Duplication/Copy')
		layout.addWidget(self.duplication)

		self.decrementation = QtGui.QPushButton('3) Decrementation')
		layout.addWidget(self.decrementation)

		self.incrementation = QtGui.QPushButton('4) Incrementation')
{'fraction_non_alphanumeric': 0.10575216619688903, 'fraction_numerical': 0.0019835055851341477, 'mean_word_length': 4.047418335089568, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2150874', 'n_tokens_mistral': 3504, 'n_tokens_neox': 2982, 'n_words': 686}