Graphics/UMLDialog.py

changeset 3190
a9a94491c4fd
parent 3160
209a07d7e401
child 3345
071afe8be2a1
equal deleted inserted replaced
3189:9a21c547de5f 3190:a9a94491c4fd
72 """ 72 """
73 Private slot to initialize the actions. 73 Private slot to initialize the actions.
74 """ 74 """
75 self.closeAct = \ 75 self.closeAct = \
76 QAction(UI.PixmapCache.getIcon("close.png"), 76 QAction(UI.PixmapCache.getIcon("close.png"),
77 self.trUtf8("Close"), self) 77 self.tr("Close"), self)
78 self.closeAct.triggered[()].connect(self.close) 78 self.closeAct.triggered[()].connect(self.close)
79 79
80 self.openAct = \ 80 self.openAct = \
81 QAction(UI.PixmapCache.getIcon("open.png"), 81 QAction(UI.PixmapCache.getIcon("open.png"),
82 self.trUtf8("Load"), self) 82 self.tr("Load"), self)
83 self.openAct.triggered[()].connect(self.load) 83 self.openAct.triggered[()].connect(self.load)
84 84
85 self.saveAct = \ 85 self.saveAct = \
86 QAction(UI.PixmapCache.getIcon("fileSave.png"), 86 QAction(UI.PixmapCache.getIcon("fileSave.png"),
87 self.trUtf8("Save"), self) 87 self.tr("Save"), self)
88 self.saveAct.triggered[()].connect(self.__save) 88 self.saveAct.triggered[()].connect(self.__save)
89 89
90 self.saveAsAct = \ 90 self.saveAsAct = \
91 QAction(UI.PixmapCache.getIcon("fileSaveAs.png"), 91 QAction(UI.PixmapCache.getIcon("fileSaveAs.png"),
92 self.trUtf8("Save As..."), self) 92 self.tr("Save As..."), self)
93 self.saveAsAct.triggered[()].connect(self.__saveAs) 93 self.saveAsAct.triggered[()].connect(self.__saveAs)
94 94
95 self.saveImageAct = \ 95 self.saveImageAct = \
96 QAction(UI.PixmapCache.getIcon("fileSavePixmap.png"), 96 QAction(UI.PixmapCache.getIcon("fileSavePixmap.png"),
97 self.trUtf8("Save as Image"), self) 97 self.tr("Save as Image"), self)
98 self.saveImageAct.triggered[()].connect(self.umlView.saveImage) 98 self.saveImageAct.triggered[()].connect(self.umlView.saveImage)
99 99
100 self.printAct = \ 100 self.printAct = \
101 QAction(UI.PixmapCache.getIcon("print.png"), 101 QAction(UI.PixmapCache.getIcon("print.png"),
102 self.trUtf8("Print"), self) 102 self.tr("Print"), self)
103 self.printAct.triggered[()].connect(self.umlView.printDiagram) 103 self.printAct.triggered[()].connect(self.umlView.printDiagram)
104 104
105 self.printPreviewAct = \ 105 self.printPreviewAct = \
106 QAction(UI.PixmapCache.getIcon("printPreview.png"), 106 QAction(UI.PixmapCache.getIcon("printPreview.png"),
107 self.trUtf8("Print Preview"), self) 107 self.tr("Print Preview"), self)
108 self.printPreviewAct.triggered[()].connect( 108 self.printPreviewAct.triggered[()].connect(
109 self.umlView.printPreviewDiagram) 109 self.umlView.printPreviewDiagram)
110 110
111 def __initToolBars(self): 111 def __initToolBars(self):
112 """ 112 """
113 Private slot to initialize the toolbars. 113 Private slot to initialize the toolbars.
114 """ 114 """
115 self.windowToolBar = QToolBar(self.trUtf8("Window"), self) 115 self.windowToolBar = QToolBar(self.tr("Window"), self)
116 self.windowToolBar.setIconSize(UI.Config.ToolBarIconSize) 116 self.windowToolBar.setIconSize(UI.Config.ToolBarIconSize)
117 self.windowToolBar.addAction(self.closeAct) 117 self.windowToolBar.addAction(self.closeAct)
118 118
119 self.fileToolBar = QToolBar(self.trUtf8("File"), self) 119 self.fileToolBar = QToolBar(self.tr("File"), self)
120 self.fileToolBar.setIconSize(UI.Config.ToolBarIconSize) 120 self.fileToolBar.setIconSize(UI.Config.ToolBarIconSize)
121 self.fileToolBar.addAction(self.openAct) 121 self.fileToolBar.addAction(self.openAct)
122 self.fileToolBar.addSeparator() 122 self.fileToolBar.addSeparator()
123 self.fileToolBar.addAction(self.saveAct) 123 self.fileToolBar.addAction(self.saveAct)
124 self.fileToolBar.addAction(self.saveAsAct) 124 self.fileToolBar.addAction(self.saveAsAct)
180 return ApplicationDiagramBuilder( 180 return ApplicationDiagramBuilder(
181 self, self.umlView, self.__project, **kwargs) 181 self, self.umlView, self.__project, **kwargs)
182 elif diagramType == UMLDialog.NoDiagram: 182 elif diagramType == UMLDialog.NoDiagram:
183 return None 183 return None
184 else: 184 else:
185 raise ValueError(self.trUtf8( 185 raise ValueError(self.tr(
186 "Illegal diagram type '{0}' given.").format(diagramType)) 186 "Illegal diagram type '{0}' given.").format(diagramType))
187 187
188 def __diagramTypeString(self): 188 def __diagramTypeString(self):
189 """ 189 """
190 Private method to generate a readable string for the diagram type. 190 Private method to generate a readable string for the diagram type.
215 @param filename name of the file to write to (string) 215 @param filename name of the file to write to (string)
216 """ 216 """
217 if not filename: 217 if not filename:
218 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( 218 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter(
219 self, 219 self,
220 self.trUtf8("Save Diagram"), 220 self.tr("Save Diagram"),
221 "", 221 "",
222 self.trUtf8("Eric5 Graphics File (*.e5g);;All Files (*)"), 222 self.tr("Eric5 Graphics File (*.e5g);;All Files (*)"),
223 "", 223 "",
224 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) 224 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite))
225 if not fname: 225 if not fname:
226 return 226 return
227 ext = QFileInfo(fname).suffix() 227 ext = QFileInfo(fname).suffix()
230 if ex: 230 if ex:
231 fname += ex 231 fname += ex
232 if QFileInfo(fname).exists(): 232 if QFileInfo(fname).exists():
233 res = E5MessageBox.yesNo( 233 res = E5MessageBox.yesNo(
234 self, 234 self,
235 self.trUtf8("Save Diagram"), 235 self.tr("Save Diagram"),
236 self.trUtf8("<p>The file <b>{0}</b> already exists." 236 self.tr("<p>The file <b>{0}</b> already exists."
237 " Overwrite it?</p>").format(fname), 237 " Overwrite it?</p>").format(fname),
238 icon=E5MessageBox.Warning) 238 icon=E5MessageBox.Warning)
239 if not res: 239 if not res:
240 return 240 return
241 filename = fname 241 filename = fname
242 242
257 f.write("\n".join(lines)) 257 f.write("\n".join(lines))
258 f.close() 258 f.close()
259 except (IOError, OSError) as err: 259 except (IOError, OSError) as err:
260 E5MessageBox.critical( 260 E5MessageBox.critical(
261 self, 261 self,
262 self.trUtf8("Save Diagram"), 262 self.tr("Save Diagram"),
263 self.trUtf8( 263 self.tr(
264 """<p>The file <b>{0}</b> could not be saved.</p>""" 264 """<p>The file <b>{0}</b> could not be saved.</p>"""
265 """<p>Reason: {1}</p>""").format(filename, str(err))) 265 """<p>Reason: {1}</p>""").format(filename, str(err)))
266 return 266 return
267 267
268 self.__fileName = filename 268 self.__fileName = filename
273 273
274 @return flag indicating success (boolean) 274 @return flag indicating success (boolean)
275 """ 275 """
276 filename = E5FileDialog.getOpenFileName( 276 filename = E5FileDialog.getOpenFileName(
277 self, 277 self,
278 self.trUtf8("Load Diagram"), 278 self.tr("Load Diagram"),
279 "", 279 "",
280 self.trUtf8("Eric5 Graphics File (*.e5g);;All Files (*)")) 280 self.tr("Eric5 Graphics File (*.e5g);;All Files (*)"))
281 if not filename: 281 if not filename:
282 # Cancelled by user 282 # Cancelled by user
283 return False 283 return False
284 284
285 try: 285 try:
287 data = f.read() 287 data = f.read()
288 f.close() 288 f.close()
289 except (IOError, OSError) as err: 289 except (IOError, OSError) as err:
290 E5MessageBox.critical( 290 E5MessageBox.critical(
291 self, 291 self,
292 self.trUtf8("Load Diagram"), 292 self.tr("Load Diagram"),
293 self.trUtf8( 293 self.tr(
294 """<p>The file <b>{0}</b> could not be read.</p>""" 294 """<p>The file <b>{0}</b> could not be read.</p>"""
295 """<p>Reason: {1}</p>""").format(filename, str(err))) 295 """<p>Reason: {1}</p>""").format(filename, str(err)))
296 return False 296 return False
297 297
298 lines = data.splitlines() 298 lines = data.splitlines()
369 369
370 @param filename name of the file containing the invalid data (string) 370 @param filename name of the file containing the invalid data (string)
371 @param linenum number of the invalid line (integer) 371 @param linenum number of the invalid line (integer)
372 """ 372 """
373 if linenum < 0: 373 if linenum < 0:
374 msg = self.trUtf8("""<p>The file <b>{0}</b> does not contain""" 374 msg = self.tr("""<p>The file <b>{0}</b> does not contain"""
375 """ valid data.</p>""").format(filename) 375 """ valid data.</p>""").format(filename)
376 else: 376 else:
377 msg = self.trUtf8("""<p>The file <b>{0}</b> does not contain""" 377 msg = self.tr("""<p>The file <b>{0}</b> does not contain"""
378 """ valid data.</p><p>Invalid line: {1}</p>""" 378 """ valid data.</p><p>Invalid line: {1}</p>"""
379 ).format(filename, linenum + 1) 379 ).format(filename, linenum + 1)
380 E5MessageBox.critical(self, self.trUtf8("Load Diagram"), msg) 380 E5MessageBox.critical(self, self.tr("Load Diagram"), msg)

eric ide

mercurial