annotate trunk/src/translator/translator.py @ 471:b6fa41e6f0b4

Translator: implemented some functionality of MsgForm.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sun, 04 Nov 2007 14:06:04 +0100
parents 77c17bbe9d20
children 30925590f392
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
1 #! /usr/bin/python
435
156d6301d79e Added PyQt4 application for creating and managing translations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
156d6301d79e Added PyQt4 application for creating and managing translations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
3 # Author: Aziz Köksal
156d6301d79e Added PyQt4 application for creating and managing translations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
4 # License: GPL2
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
5 import sys, os
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
6 import yaml
438
2c177053cd15 Translator: added modules langfile and project.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 437
diff changeset
7
435
156d6301d79e Added PyQt4 application for creating and managing translations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
8 from PyQt4 import QtCore, QtGui
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
9 # User interface modules
435
156d6301d79e Added PyQt4 application for creating and managing translations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
10 from ui_translator import Ui_MainWindow
436
0dba4c0e5234 Added AboutDialog to translator.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 435
diff changeset
11 from ui_about import Ui_AboutDialog
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
12 from ui_new_project import Ui_NewProjectDialog
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
13 from ui_project_properties import Ui_ProjectProperties
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
14 from ui_msg_form import Ui_MsgForm
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
15
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
16 from project import Project, newProjectData
438
2c177053cd15 Translator: added modules langfile and project.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 437
diff changeset
17
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
18 g_scriptDir = sys.path[0]
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
19 g_CWD = os.getcwd()
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
20 g_projectExt = ".tproj"
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
21 g_catExt = ".cat"
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
22 g_settingsFile = os.path.join(g_scriptDir, "settings.yaml")
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
23 g_settings = {}
436
0dba4c0e5234 Added AboutDialog to translator.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 435
diff changeset
24
0dba4c0e5234 Added AboutDialog to translator.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 435
diff changeset
25 class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
0dba4c0e5234 Added AboutDialog to translator.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 435
diff changeset
26 def __init__(self):
0dba4c0e5234 Added AboutDialog to translator.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 435
diff changeset
27 QtGui.QMainWindow.__init__(self)
0dba4c0e5234 Added AboutDialog to translator.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 435
diff changeset
28 self.setupUi(self)
0dba4c0e5234 Added AboutDialog to translator.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 435
diff changeset
29
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
30 self.project = None
436
0dba4c0e5234 Added AboutDialog to translator.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 435
diff changeset
31 # Modifications
471
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
32 self.pages = QtGui.QStackedWidget()
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
33 self.setCentralWidget(self.pages)
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
34 self.disableMenuItems()
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
35 self.projectDock = QtGui.QDockWidget("Project", self)
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
36 self.projectTree = ProjectTree(self)
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
37 self.projectDock.setWidget(self.projectTree)
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
38 self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, self.projectDock)
436
0dba4c0e5234 Added AboutDialog to translator.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 435
diff changeset
39 # Custom connections
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
40 QtCore.QObject.connect(self.action_About, QtCore.SIGNAL("triggered()"), self.showAboutDialog)
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
41 QtCore.QObject.connect(self.action_New_Project, QtCore.SIGNAL("triggered()"), self.createNewProject)
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
42 QtCore.QObject.connect(self.action_Open_Project, QtCore.SIGNAL("triggered()"), self.openProjectAction)
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
43 QtCore.QObject.connect(self.action_Close_Project, QtCore.SIGNAL("triggered()"), self.closeProject)
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
44 QtCore.QObject.connect(self.action_Properties, QtCore.SIGNAL("triggered()"), self.showProjectProperties)
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
45 QtCore.QObject.connect(self.action_Add_Catalogue, QtCore.SIGNAL("triggered()"), self.addCatalogue)
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
46 QtCore.QObject.connect(self.action_Add_New_Catalogue, QtCore.SIGNAL("triggered()"), self.addNewCatalogue)
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
47 QtCore.QObject.connect(self.projectTree, QtCore.SIGNAL("currentItemChanged (QTreeWidgetItem *,QTreeWidgetItem *)"), self.projectTreeItemChanged)
436
0dba4c0e5234 Added AboutDialog to translator.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 435
diff changeset
48
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
49 self.readSettings()
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
50
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
51 def showAboutDialog(self):
436
0dba4c0e5234 Added AboutDialog to translator.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 435
diff changeset
52 about = QtGui.QDialog()
0dba4c0e5234 Added AboutDialog to translator.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 435
diff changeset
53 Ui_AboutDialog().setupUi(about)
0dba4c0e5234 Added AboutDialog to translator.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 435
diff changeset
54 about.exec_()
435
156d6301d79e Added PyQt4 application for creating and managing translations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
55
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
56 def showProjectProperties(self):
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
57 dialog = QtGui.QDialog()
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
58 Ui_ProjectProperties().setupUi(dialog)
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
59 dialog.exec_()
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
60
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
61 def createNewProject(self):
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
62 if self.cantCloseProjectIfOpen():
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
63 return
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
64 dialog = NewProjectDialog()
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
65 code = dialog.exec_()
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
66 if code == QtGui.QDialog.Accepted:
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
67 self.openProject(str(dialog.projectFilePath.text()))
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
68
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
69 def openProjectAction(self):
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
70 if self.cantCloseProjectIfOpen():
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
71 return
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
72 filePath = QtGui.QFileDialog.getOpenFileName(self, "Select Project File", g_CWD, "Translator Project (*%s)" % g_projectExt);
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
73 filePath = str(filePath)
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
74 if filePath:
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
75 self.openProject(filePath)
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
76
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
77 def openProject(self, filePath):
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
78 from errors import LoadingError
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
79 try:
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
80 self.project = Project(filePath)
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
81 except LoadingError, e:
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
82 QtGui.QMessageBox.critical(self, "Error", u"Couldn't load project file:\n\n"+str(e))
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
83 return
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
84 self.enableMenuItems()
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
85 self.projectTree.setProject(self.project)
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
86
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
87 def addCatalogue(self):
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
88 filePath = QtGui.QFileDialog.getOpenFileName(self, "Select Project File", g_CWD, "Catalogue (*%s)" % g_catExt);
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
89 filePath = str(filePath)
439
cdbb2bf6dd07 Translator: applied some fixes and made some additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 438
diff changeset
90
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
91 def addNewCatalogue(self):
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
92 pass
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
93
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
94 def cantCloseProjectIfOpen(self):
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
95 if self.project == None:
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
96 return False
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
97 return self.closeProject()
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
98
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
99 def closeProject(self):
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
100 if self.project == None:
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
101 return True
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
102
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
103 button = QtGui.QMessageBox.question(self, "Closing", "Close the current project?", QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Cancel)
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
104 if button == QtGui.QMessageBox.Cancel:
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
105 return False
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
106
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
107 del self.project
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
108 self.project = None
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
109 self.disableMenuItems()
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
110 self.projectTree.clear()
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
111 return True
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
112
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
113 def enableMenuItems(self):
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
114 self.action_Close_Project.setEnabled(True)
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
115 self.menubar.insertMenu(self.menu_Help.menuAction(), self.menu_Project)
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
116
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
117 def disableMenuItems(self):
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
118 self.action_Close_Project.setEnabled(False)
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
119 self.menubar.removeAction(self.menu_Project.menuAction())
439
cdbb2bf6dd07 Translator: applied some fixes and made some additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 438
diff changeset
120
471
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
121 def projectTreeItemChanged(self, current, previous):
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
122 if current == None:
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
123 return
471
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
124
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
125 if isinstance(current, LangFileItem):
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
126 index = self.pages.indexOf(current.msgForm)
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
127 if index == -1:
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
128 index = self.pages.addWidget(current.msgForm)
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
129 self.pages.setCurrentIndex(index)
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
130
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
131 def closeEvent(self, event):
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
132 if self.closeProject() == False:
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
133 event.ignore()
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
134 return
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
135 # Exitting
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
136 self.writeSettings()
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
137
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
138 def moveToCenterOfDesktop(self):
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
139 rect = QtGui.QApplication.desktop().geometry()
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
140 self.move(rect.center() - self.rect().center())
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
141
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
142 def readSettings(self):
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
143 # Set default size
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
144 self.resize(QtCore.QSize(500, 400))
438
2c177053cd15 Translator: added modules langfile and project.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 437
diff changeset
145 doc = {}
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
146 try:
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
147 doc = yaml.load(open(g_settingsFile, "r"))
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
148 except:
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
149 self.moveToCenterOfDesktop()
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
150 return
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
151
438
2c177053cd15 Translator: added modules langfile and project.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 437
diff changeset
152 g_settings = doc
2c177053cd15 Translator: added modules langfile and project.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 437
diff changeset
153 if not isinstance(doc, dict):
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
154 g_settings = {}
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
155
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
156 try:
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
157 coord = doc["Window"]
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
158 size = QtCore.QSize(coord["Size"][0], coord["Size"][1])
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
159 point = QtCore.QPoint(coord["Pos"][0], coord["Pos"][1])
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
160 self.resize(size)
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
161 self.move(point)
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
162 except:
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
163 self.moveToCenterOfDesktop()
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
164
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
165 def writeSettings(self):
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
166 # Save window coordinates
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
167 g_settings["Window"] = {
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
168 "Pos" : [self.pos().x(), self.pos().y()],
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
169 "Size" : [self.size().width(), self.size().height()]
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
170 }
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
171 yaml.dump(g_settings, open(g_settingsFile, "w")) #default_flow_style=False
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
172
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
173 class MsgForm(QtGui.QWidget, Ui_MsgForm):
471
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
174 def __init__(self, langFile):
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
175 QtGui.QWidget.__init__(self)
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
176 self.setupUi(self)
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
177
471
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
178 self.langFile = langFile
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
179 self.treeWidget.setColumnCount(2)
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
180 self.treeWidget.setHeaderLabels(["ID", "Text"])
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
181 for msg in self.langFile.messages:
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
182 item = QtGui.QTreeWidgetItem([str(msg["ID"]), msg["Text"]])
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
183 self.treeWidget.addTopLevelItem(item)
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
184
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
185 QtCore.QObject.connect(self.treeWidget, QtCore.SIGNAL("currentItemChanged (QTreeWidgetItem *,QTreeWidgetItem *)"), self.treeItemChanged)
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
186
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
187 def treeItemChanged(self, current, previous):
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
188 msg = self.langFile.getMsg(int(current.text(0)))
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
189 self.destEdit.setText(msg["Text"])
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
190 self.destAnnotEdit.setText(msg["Annot"])
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
191
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
192 class MsgIDItem(QtGui.QTreeWidgetItem):
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
193 def __init__(self, parent, text):
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
194 QtGui.QTreeWidgetItem.__init__(self, parent, [text])
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
195
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
196 class LangFileItem(QtGui.QTreeWidgetItem):
471
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
197 def __init__(self, parent, langFile):
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
198 QtGui.QTreeWidgetItem.__init__(self, parent, [langFile.langCode])
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
199 self.langFile = langFile
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
200 self.msgForm = MsgForm(langFile)
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
201
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
202 class ProjectItem(QtGui.QTreeWidgetItem):
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
203 def __init__(self, text):
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
204 QtGui.QTreeWidgetItem.__init__(self, [text])
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
205
439
cdbb2bf6dd07 Translator: applied some fixes and made some additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 438
diff changeset
206 class ProjectTree(QtGui.QTreeWidget):
cdbb2bf6dd07 Translator: applied some fixes and made some additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 438
diff changeset
207 def __init__(self, parent):
cdbb2bf6dd07 Translator: applied some fixes and made some additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 438
diff changeset
208 QtGui.QTreeWidget.__init__(self, parent)
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
209 self.topItem = None
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
210 self.msgIDsItem = None
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
211 self.headerItem().setHidden(True)
438
2c177053cd15 Translator: added modules langfile and project.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 437
diff changeset
212
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
213 def setProject(self, project):
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
214 self.project = project
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
215
471
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
216 self.topItem = ProjectItem(self.project.name)
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
217 self.addTopLevelItem(self.topItem)
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
218
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
219 for langFile in self.project.langFiles:
471
b6fa41e6f0b4 Translator: implemented some functionality of MsgForm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 460
diff changeset
220 langFileItem = LangFileItem(self.topItem, langFile)
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
221
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
222 self.msgIDsItem = QtGui.QTreeWidgetItem(self.topItem, ["Message IDs"])
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
223 for msgID in self.project.msgIDs:
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
224 MsgIDItem(self.msgIDsItem, msgID["Name"])
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
225
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
226 for x in [self.topItem, self.msgIDsItem]:
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
227 x.setExpanded(True)
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
228
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
229 def clear(self):
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
230 self.topItem = None
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
231 self.msgIDsItem = None
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
232 QtGui.QTreeWidget.clear(self)
438
2c177053cd15 Translator: added modules langfile and project.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 437
diff changeset
233
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
234 class NewProjectDialog(QtGui.QDialog, Ui_NewProjectDialog):
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
235 def __init__(self):
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
236 QtGui.QDialog.__init__(self)
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
237 self.setupUi(self)
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
238
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
239 QtCore.QObject.connect(self.pickFileButton, QtCore.SIGNAL("clicked()"), self.pickFilePath)
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
240
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
241 def pickFilePath(self):
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
242 filePath = QtGui.QFileDialog.getSaveFileName(self, "New Project File", g_CWD, "Translator Project (*%s)" % g_projectExt);
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
243 if not filePath:
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
244 return
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
245 filePath = str(filePath) # Convert QString
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
246 if os.path.splitext(filePath)[1] != g_projectExt:
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
247 filePath += g_projectExt
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
248 self.projectFilePath.setText(filePath)
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
249
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
250 def accept(self):
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
251 projectName = str(self.projectName.text())
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
252 filePath = str(self.projectFilePath.text())
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
253
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
254 if projectName == "":
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
255 QtGui.QMessageBox.warning(self, "Warning", "Please, enter a name for the project.")
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
256 return
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
257 if filePath == "":
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
258 QtGui.QMessageBox.warning(self, "Warning", "Please, choose or enter a path for the project file.")
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
259 return
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
260
460
77c17bbe9d20 Translator: added new modules; applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 442
diff changeset
261 projectData = newProjectData(projectName)
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
262
442
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
263 if os.path.splitext(filePath)[1] != g_projectExt:
5968e273449b Translator: added new modules; made fixes and many additions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 439
diff changeset
264 filePath += g_projectExt
437
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
265
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
266 try:
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
267 yaml.dump(projectData, open(filePath, "w"), default_flow_style=False)
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
268 except Exception, e:
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
269 QtGui.QMessageBox.critical(self, "Error", str(e))
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
270 return
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
271
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
272 # Accept and close dialog.
7ac9f94ca7ff Translator: added NewProjectDialog.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 436
diff changeset
273 QtGui.QDialog.accept(self)
435
156d6301d79e Added PyQt4 application for creating and managing translations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
274
156d6301d79e Added PyQt4 application for creating and managing translations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
275 if __name__ == "__main__":
436
0dba4c0e5234 Added AboutDialog to translator.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 435
diff changeset
276 app = QtGui.QApplication(sys.argv)
0dba4c0e5234 Added AboutDialog to translator.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 435
diff changeset
277 main = MainWindow()
0dba4c0e5234 Added AboutDialog to translator.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 435
diff changeset
278 main.show()
0dba4c0e5234 Added AboutDialog to translator.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 435
diff changeset
279 sys.exit(app.exec_())