Mercurial > projects > dil
changeset 437:7ac9f94ca7ff
Translator: added NewProjectDialog.
Added methods to MainWindow for reading and writing application settings.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Fri, 12 Oct 2007 11:12:10 +0200 |
parents | 0dba4c0e5234 |
children | 2c177053cd15 |
files | trunk/src/translator/new_project.ui trunk/src/translator/translator.py trunk/src/translator/translator.ui trunk/src/translator/ui_new_project.py trunk/src/translator/ui_translator.py |
diffstat | 5 files changed, 384 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/translator/new_project.ui Fri Oct 12 11:12:10 2007 +0200 @@ -0,0 +1,127 @@ +<ui version="4.0" > + <class>NewProjectDialog</class> + <widget class="QDialog" name="NewProjectDialog" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>401</width> + <height>131</height> + </rect> + </property> + <property name="windowTitle" > + <string>Create New Project</string> + </property> + <layout class="QVBoxLayout" > + <item> + <layout class="QGridLayout" > + <item row="0" column="0" > + <layout class="QGridLayout" > + <item row="0" column="0" > + <widget class="QLabel" name="label" > + <property name="text" > + <string>Project name:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + <property name="buddy" > + <cstring>projectName</cstring> + </property> + </widget> + </item> + <item row="0" column="1" > + <widget class="QLineEdit" name="projectName" /> + </item> + <item row="1" column="0" > + <widget class="QLabel" name="label_2" > + <property name="text" > + <string>Project file:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + <property name="buddy" > + <cstring>projectFilePath</cstring> + </property> + </widget> + </item> + <item row="1" column="1" > + <layout class="QHBoxLayout" > + <item> + <widget class="QLineEdit" name="projectFilePath" /> + </item> + <item> + <widget class="QToolButton" name="pickFileButton" > + <property name="text" > + <string>...</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + <item row="1" column="0" > + <spacer> + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" > + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + <item row="2" column="0" > + <widget class="QDialogButtonBox" name="buttonBox" > + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons" > + <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>NewProjectDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel" > + <x>228</x> + <y>108</y> + </hint> + <hint type="destinationlabel" > + <x>157</x> + <y>130</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>NewProjectDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel" > + <x>296</x> + <y>114</y> + </hint> + <hint type="destinationlabel" > + <x>286</x> + <y>130</y> + </hint> + </hints> + </connection> + </connections> +</ui>
--- a/trunk/src/translator/translator.py Thu Oct 11 16:34:22 2007 +0200 +++ b/trunk/src/translator/translator.py Fri Oct 12 11:12:10 2007 +0200 @@ -1,12 +1,19 @@ -#! /bin/python +#! /usr/bin/python # -*- coding: utf-8 -*- # Author: Aziz Köksal # License: GPL2 -import sys +import sys, os +import yaml from PyQt4 import QtCore, QtGui - +# User interface modules from ui_translator import Ui_MainWindow from ui_about import Ui_AboutDialog +from ui_new_project import Ui_NewProjectDialog + +g_scriptDir = sys.path[0] +g_CWD = os.getcwd() +g_settingsFile = os.path.join(g_scriptDir, "settings.yaml") +g_settings = {} class MainWindow(QtGui.QMainWindow, Ui_MainWindow): def __init__(self): @@ -16,13 +23,102 @@ # Modifications # Custom connections - QtCore.QObject.connect(self.actionAbout, QtCore.SIGNAL("triggered()"), self.aboutDialog) + QtCore.QObject.connect(self.action_About, QtCore.SIGNAL("triggered()"), self.showAboutDialog) + QtCore.QObject.connect(self.action_New_Project, QtCore.SIGNAL("triggered()"), self.createNewProject) - def aboutDialog(self): + self.readSettings() + + def showAboutDialog(self): about = QtGui.QDialog() Ui_AboutDialog().setupUi(about) about.exec_() + def createNewProject(self): + NewProjectDialog().exec_() + + def closeEvent(self, event): + self.writeSettings() + + def moveToCenterOfDesktop(self): + rect = QtGui.QApplication.desktop().geometry() + self.move(rect.center() - self.rect().center()) + + def readSettings(self): + # Set default size + self.resize(QtCore.QSize(500, 400)) + + try: + doc = yaml.load(open(g_settingsFile, "r")) + except: + self.moveToCenterOfDesktop() + return + + if isinstance(doc, type({})): + g_settings = doc + else: + g_settings = {} + + try: + coord = doc["Window"] + size = QtCore.QSize(coord["Size"][0], coord["Size"][1]) + point = QtCore.QPoint(coord["Pos"][0], coord["Pos"][1]) + self.resize(size) + self.move(point) + except: + self.moveToCenterOfDesktop() + + def writeSettings(self): + # Save window coordinates + g_settings["Window"] = { + "Pos" : [self.pos().x(), self.pos().y()], + "Size" : [self.size().width(), self.size().height()] + } + yaml.dump(g_settings, open(g_settingsFile, "w")) #default_flow_style=False + + +class NewProjectDialog(QtGui.QDialog, Ui_NewProjectDialog): + def __init__(self): + QtGui.QDialog.__init__(self) + self.setupUi(self) + + QtCore.QObject.connect(self.pickFileButton, QtCore.SIGNAL("clicked()"), self.pickFilePath) + + def pickFilePath(self): + filePath = QtGui.QFileDialog.getSaveFileName(self, "Select Project File", g_CWD, "Translator Project (*.tproj)"); + filePath = str(filePath) # Convert QString + if os.path.splitext(filePath)[1] != ".tproj": + filePath += ".tproj" + self.projectFilePath.setText(filePath) + + def accept(self): + projectName = str(self.projectName.text()) + filePath = str(self.projectFilePath.text()) + + if projectName == "": + QtGui.QMessageBox.warning(self, "Warning", "Please, enter a name for the project.") + return + if filePath == "": + QtGui.QMessageBox.warning(self, "Warning", "Please, choose or enter a path for the project file.") + return + + projectData = { + "Name":projectName, + "LangFiles":[], + "SourceLangFile":'', + "MsgIDs":[] + } + + if os.path.splitext(filePath)[1] != ".tproj": + filePath += ".tproj" + + try: + yaml.dump(projectData, open(filePath, "w"), default_flow_style=False) + except Exception, e: + QtGui.QMessageBox.critical(self, "Error", str(e)) + return + + # Accept and close dialog. + QtGui.QDialog.accept(self) if __name__ == "__main__": app = QtGui.QApplication(sys.argv)
--- a/trunk/src/translator/translator.ui Thu Oct 11 16:34:22 2007 +0200 +++ b/trunk/src/translator/translator.ui Fri Oct 12 11:12:10 2007 +0200 @@ -80,31 +80,66 @@ <property name="title" > <string>&File</string> </property> - <addaction name="actionQuit" /> + <addaction name="action_New_Project" /> + <addaction name="separator" /> + <addaction name="action_Quit" /> </widget> <widget class="QMenu" name="menu_Help" > <property name="title" > <string>&Help</string> </property> - <addaction name="actionAbout" /> + <addaction name="action_About" /> + </widget> + <widget class="QMenu" name="menu_Project" > + <property name="title" > + <string>&Project</string> + </property> + <addaction name="action_Add_catalogue" /> + <addaction name="action_Build_Project" /> + <addaction name="separator" /> + <addaction name="action_Properties" /> </widget> <addaction name="menu_File" /> + <addaction name="menu_Project" /> <addaction name="menu_Help" /> </widget> <widget class="QStatusBar" name="statusbar" /> - <action name="actionQuit" > + <action name="action_Quit" > <property name="text" > - <string>Quit</string> + <string>&Quit</string> </property> <property name="shortcut" > <string>Ctrl+Q</string> </property> </action> - <action name="actionAbout" > + <action name="action_About" > <property name="text" > <string>&About</string> </property> </action> + <action name="action_New_Project" > + <property name="text" > + <string>&New Project</string> + </property> + <property name="shortcut" > + <string>Ctrl+N</string> + </property> + </action> + <action name="action_Add_catalogue" > + <property name="text" > + <string>&Add catalogue</string> + </property> + </action> + <action name="action_Properties" > + <property name="text" > + <string>&Properties</string> + </property> + </action> + <action name="action_Build_Project" > + <property name="text" > + <string>Build Project</string> + </property> + </action> </widget> <tabstops> <tabstop>listView</tabstop> @@ -131,7 +166,7 @@ </hints> </connection> <connection> - <sender>actionQuit</sender> + <sender>action_Quit</sender> <signal>triggered()</signal> <receiver>MainWindow</receiver> <slot>close()</slot>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/translator/ui_new_project.py Fri Oct 12 11:12:10 2007 +0200 @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'new_project.ui' +# +# Created: Thu Oct 11 21:16:07 2007 +# by: PyQt4 UI code generator 4.1 +# +# WARNING! All changes made in this file will be lost! + +import sys +from PyQt4 import QtCore, QtGui + +class Ui_NewProjectDialog(object): + def setupUi(self, NewProjectDialog): + NewProjectDialog.setObjectName("NewProjectDialog") + NewProjectDialog.resize(QtCore.QSize(QtCore.QRect(0,0,401,131).size()).expandedTo(NewProjectDialog.minimumSizeHint())) + + self.vboxlayout = QtGui.QVBoxLayout(NewProjectDialog) + self.vboxlayout.setObjectName("vboxlayout") + + self.gridlayout = QtGui.QGridLayout() + self.gridlayout.setObjectName("gridlayout") + + self.gridlayout1 = QtGui.QGridLayout() + self.gridlayout1.setObjectName("gridlayout1") + + self.label = QtGui.QLabel(NewProjectDialog) + self.label.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.label.setObjectName("label") + self.gridlayout1.addWidget(self.label,0,0,1,1) + + self.projectName = QtGui.QLineEdit(NewProjectDialog) + self.projectName.setObjectName("projectName") + self.gridlayout1.addWidget(self.projectName,0,1,1,1) + + self.label_2 = QtGui.QLabel(NewProjectDialog) + self.label_2.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.label_2.setObjectName("label_2") + self.gridlayout1.addWidget(self.label_2,1,0,1,1) + + self.hboxlayout = QtGui.QHBoxLayout() + self.hboxlayout.setObjectName("hboxlayout") + + self.projectFilePath = QtGui.QLineEdit(NewProjectDialog) + self.projectFilePath.setObjectName("projectFilePath") + self.hboxlayout.addWidget(self.projectFilePath) + + self.pickFileButton = QtGui.QToolButton(NewProjectDialog) + self.pickFileButton.setObjectName("pickFileButton") + self.hboxlayout.addWidget(self.pickFileButton) + self.gridlayout1.addLayout(self.hboxlayout,1,1,1,1) + self.gridlayout.addLayout(self.gridlayout1,0,0,1,1) + + spacerItem = QtGui.QSpacerItem(20,40,QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Expanding) + self.gridlayout.addItem(spacerItem,1,0,1,1) + + self.buttonBox = QtGui.QDialogButtonBox(NewProjectDialog) + self.buttonBox.setOrientation(QtCore.Qt.Horizontal) + self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.NoButton|QtGui.QDialogButtonBox.Ok) + self.buttonBox.setObjectName("buttonBox") + self.gridlayout.addWidget(self.buttonBox,2,0,1,1) + self.vboxlayout.addLayout(self.gridlayout) + self.label.setBuddy(self.projectName) + self.label_2.setBuddy(self.projectFilePath) + + self.retranslateUi(NewProjectDialog) + QtCore.QObject.connect(self.buttonBox,QtCore.SIGNAL("accepted()"),NewProjectDialog.accept) + QtCore.QObject.connect(self.buttonBox,QtCore.SIGNAL("rejected()"),NewProjectDialog.reject) + QtCore.QMetaObject.connectSlotsByName(NewProjectDialog) + + def retranslateUi(self, NewProjectDialog): + NewProjectDialog.setWindowTitle(QtGui.QApplication.translate("NewProjectDialog", "Create New Project", None, QtGui.QApplication.UnicodeUTF8)) + self.label.setText(QtGui.QApplication.translate("NewProjectDialog", "Project name:", None, QtGui.QApplication.UnicodeUTF8)) + self.label_2.setText(QtGui.QApplication.translate("NewProjectDialog", "Project file:", None, QtGui.QApplication.UnicodeUTF8)) + self.pickFileButton.setText(QtGui.QApplication.translate("NewProjectDialog", "...", None, QtGui.QApplication.UnicodeUTF8)) +
--- a/trunk/src/translator/ui_translator.py Thu Oct 11 16:34:22 2007 +0200 +++ b/trunk/src/translator/ui_translator.py Fri Oct 12 11:12:10 2007 +0200 @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'translator.ui' # -# Created: Wed Oct 10 22:04:31 2007 +# Created: Fri Oct 12 10:58:49 2007 # by: PyQt4 UI code generator 4.1 # # WARNING! All changes made in this file will be lost! @@ -66,25 +66,47 @@ self.menu_Help = QtGui.QMenu(self.menubar) self.menu_Help.setObjectName("menu_Help") + + self.menu_Project = QtGui.QMenu(self.menubar) + self.menu_Project.setObjectName("menu_Project") MainWindow.setMenuBar(self.menubar) self.statusbar = QtGui.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) - self.actionQuit = QtGui.QAction(MainWindow) - self.actionQuit.setObjectName("actionQuit") + self.action_Quit = QtGui.QAction(MainWindow) + self.action_Quit.setObjectName("action_Quit") + + self.action_About = QtGui.QAction(MainWindow) + self.action_About.setObjectName("action_About") + + self.action_New_Project = QtGui.QAction(MainWindow) + self.action_New_Project.setObjectName("action_New_Project") + + self.action_Add_catalogue = QtGui.QAction(MainWindow) + self.action_Add_catalogue.setObjectName("action_Add_catalogue") - self.actionAbout = QtGui.QAction(MainWindow) - self.actionAbout.setObjectName("actionAbout") - self.menu_File.addAction(self.actionQuit) - self.menu_Help.addAction(self.actionAbout) + self.action_Properties = QtGui.QAction(MainWindow) + self.action_Properties.setObjectName("action_Properties") + + self.action_Build_Project = QtGui.QAction(MainWindow) + self.action_Build_Project.setObjectName("action_Build_Project") + self.menu_File.addAction(self.action_New_Project) + self.menu_File.addSeparator() + self.menu_File.addAction(self.action_Quit) + self.menu_Help.addAction(self.action_About) + self.menu_Project.addAction(self.action_Add_catalogue) + self.menu_Project.addAction(self.action_Build_Project) + self.menu_Project.addSeparator() + self.menu_Project.addAction(self.action_Properties) self.menubar.addAction(self.menu_File.menuAction()) + self.menubar.addAction(self.menu_Project.menuAction()) self.menubar.addAction(self.menu_Help.menuAction()) self.retranslateUi(MainWindow) QtCore.QObject.connect(self.pushButton,QtCore.SIGNAL("clicked()"),MainWindow.close) - QtCore.QObject.connect(self.actionQuit,QtCore.SIGNAL("triggered()"),MainWindow.close) + QtCore.QObject.connect(self.action_Quit,QtCore.SIGNAL("triggered()"),MainWindow.close) QtCore.QMetaObject.connectSlotsByName(MainWindow) MainWindow.setTabOrder(self.listView,self.textEdit) MainWindow.setTabOrder(self.textEdit,self.textEdit_2) @@ -95,7 +117,13 @@ self.pushButton.setText(QtGui.QApplication.translate("MainWindow", "Exit", None, QtGui.QApplication.UnicodeUTF8)) self.menu_File.setTitle(QtGui.QApplication.translate("MainWindow", "&File", None, QtGui.QApplication.UnicodeUTF8)) self.menu_Help.setTitle(QtGui.QApplication.translate("MainWindow", "&Help", None, QtGui.QApplication.UnicodeUTF8)) - self.actionQuit.setText(QtGui.QApplication.translate("MainWindow", "Quit", None, QtGui.QApplication.UnicodeUTF8)) - self.actionQuit.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+Q", None, QtGui.QApplication.UnicodeUTF8)) - self.actionAbout.setText(QtGui.QApplication.translate("MainWindow", "&About", None, QtGui.QApplication.UnicodeUTF8)) + self.menu_Project.setTitle(QtGui.QApplication.translate("MainWindow", "&Project", None, QtGui.QApplication.UnicodeUTF8)) + self.action_Quit.setText(QtGui.QApplication.translate("MainWindow", "&Quit", None, QtGui.QApplication.UnicodeUTF8)) + self.action_Quit.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+Q", None, QtGui.QApplication.UnicodeUTF8)) + self.action_About.setText(QtGui.QApplication.translate("MainWindow", "&About", None, QtGui.QApplication.UnicodeUTF8)) + self.action_New_Project.setText(QtGui.QApplication.translate("MainWindow", "&New Project", None, QtGui.QApplication.UnicodeUTF8)) + self.action_New_Project.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+N", None, QtGui.QApplication.UnicodeUTF8)) + self.action_Add_catalogue.setText(QtGui.QApplication.translate("MainWindow", "&Add catalogue", None, QtGui.QApplication.UnicodeUTF8)) + self.action_Properties.setText(QtGui.QApplication.translate("MainWindow", "&Properties", None, QtGui.QApplication.UnicodeUTF8)) + self.action_Build_Project.setText(QtGui.QApplication.translate("MainWindow", "Build Project", None, QtGui.QApplication.UnicodeUTF8))