# -*- coding: utf-8 -*-
#Ege Öz

from PyQt4 import QtCore, QtGui
import sys,os

try:
	_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
	def _fromUtf8(s):
		return s

try:
	_encoding = QtGui.QApplication.UnicodeUTF8
	def _translate(context, text, disambig):
		return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
	def _translate(context, text, disambig):
		return QtGui.QApplication.translate(context, text, disambig)

class Ui_MainWindow(object):
	def setupUi(self, MainWindow):
		MainWindow.setObjectName(_fromUtf8("MainWindow"))
		MainWindow.resize(661, 440)
		icon = QtGui.QIcon.fromTheme(_fromUtf8("text"))
		MainWindow.setWindowIcon(icon)
		self.centralwidget = QtGui.QWidget(MainWindow)
		self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
		self.gridLayout = QtGui.QGridLayout(self.centralwidget)
		self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
		self.textEdit = QtGui.QTextEdit(self.centralwidget)
		self.textEdit.setObjectName(_fromUtf8("textEdit"))
		font = QtGui.QFont()
		font.setFamily(_fromUtf8("Monospace"))
		self.textEdit.setFont(font)
		self.gridLayout.addWidget(self.textEdit, 0, 0, 1, 1)
		MainWindow.setCentralWidget(self.centralwidget)
		self.menubar = QtGui.QMenuBar(MainWindow)
		self.menubar.setGeometry(QtCore.QRect(0, 0, 661, 20))
		self.menubar.setObjectName(_fromUtf8("menubar"))
		self.menuFile = QtGui.QMenu(self.menubar)
		self.menuFile.setObjectName(_fromUtf8("menuFile"))
		self.menuHelp = QtGui.QMenu(self.menubar)
		self.menuHelp.setObjectName(_fromUtf8("menuHelp"))
		MainWindow.setMenuBar(self.menubar)
		self.statusbar = QtGui.QStatusBar(MainWindow)
		self.statusbar.setObjectName(_fromUtf8("statusbar"))
		MainWindow.setStatusBar(self.statusbar)
		self.actionNew = QtGui.QAction(MainWindow)
		self.actionNew.setObjectName(_fromUtf8("actionNew"))
		self.actionOpen = QtGui.QAction(MainWindow)
		self.actionOpen.setObjectName(_fromUtf8("actionOpen"))
		self.actionSave = QtGui.QAction(MainWindow)
		self.actionSave.setObjectName(_fromUtf8("actionSave"))
		self.actionSaveAs = QtGui.QAction(MainWindow)
		self.actionSaveAs.setObjectName(_fromUtf8("actionSaveAs"))
		self.actionExit = QtGui.QAction(MainWindow)
		self.actionExit.setObjectName(_fromUtf8("actionExit"))
		self.actionAbout = QtGui.QAction(MainWindow)
		self.actionAbout.setObjectName(_fromUtf8("actionAbout"))
		self.menuFile.addAction(self.actionNew)
		self.menuFile.addAction(self.actionOpen)
		self.menuFile.addAction(self.actionSave)
		self.menuFile.addAction(self.actionSaveAs)
		self.menuFile.addSeparator()
		self.menuFile.addAction(self.actionExit)
		self.menuHelp.addAction(self.actionAbout)
		self.menubar.addAction(self.menuFile.menuAction())
		self.menubar.addAction(self.menuHelp.menuAction())

		self.actionExit.triggered.connect(self.exitt)
		self.actionSave.triggered.connect(self.kaydet)
		self.actionSaveAs.triggered.connect(self.fkaydet)
		self.actionOpen.triggered.connect(self.ac)
		self.actionAbout.triggered.connect(self.hakkinda)
		self.actionNew.triggered.connect(self.yeni)
		
		self.retranslateUi(MainWindow)
		QtCore.QMetaObject.connectSlotsByName(MainWindow)

	def hakkinda(self):
		QtGui.QMessageBox.about(None, "About", "Ege Öz 2014")
		
	def yeni(self):
		self.textEdit.clear()
		
	def ac(self):
		self.afilename = QtGui.QFileDialog.getOpenFileName(None, "Open File", "",os.getenv("USER"))
		f=open (self.afilename,"r")
		data=f.read()
		self.textEdit.setText(data)
		f.close()
		self.statusbar.showMessage("File opened.")
		
	def kaydet(self):
		f=open (self.afilename,"w")
		f.write(self.textEdit.toPlainText())
		f.close()
		self.statusbar.showMessage("File saved.")

	def fkaydet(self):
		filename = QtGui.QFileDialog.getSaveFileName(None, "Save File", "",os.getenv("USER"))
		data=self.textEdit.toPlainText()
		f= open (filename,"w")
		f.write(data)
		f.close()
		self.statusbar.showMessage("File saved.")
	def exitt(self):
		sys.exit()
		
	def retranslateUi(self, MainWindow):
		MainWindow.setWindowTitle(_translate("MainWindow", "TextPad", None))
		self.menuFile.setTitle(_translate("MainWindow", "File", None))
		self.menuHelp.setTitle(_translate("MainWindow", "Help", None))
		self.actionNew.setText(_translate("MainWindow", "New", None))
		self.actionOpen.setText(_translate("MainWindow", "Open", None))
		self.actionSave.setText(_translate("MainWindow", "Save", None))
		self.actionSaveAs.setText(_translate("MainWindow", "Save As", None))
		self.actionExit.setText(_translate("MainWindow", "Exit", None))
		self.actionAbout.setText(_translate("MainWindow", "About", None))

if __name__ == "__main__":
	import sys
	app = QtGui.QApplication(sys.argv)
	MainWindow = QtGui.QMainWindow()
	ui = Ui_MainWindow()
	ui.setupUi(MainWindow)
	MainWindow.show()
	sys.exit(app.exec_())
