5 from python_qt_binding
import QtWidgets, QtCore, QtGui
11 super(ProjectPlugin, self).
__init__(context)
15 self.editor.undo_stack.cleanChanged.connect(self.
clean_changed)
19 context.add_widget(self.
widget)
25 self.
settings = QtCore.QSettings(
'rqt_frame_editor',
'frame_editor')
32 raise NotImplementedError
35 raise NotImplementedError
41 newAction = QtWidgets.QAction(
"&New", self)
42 newAction.setShortcuts(QtGui.QKeySequence.New)
43 newAction.setStatusTip(
"Create a new file")
44 newAction.setIcon(QtGui.QIcon.fromTheme(
"document-new"))
45 newAction.triggered.connect(self.
new_file)
47 openAction = QtWidgets.QAction(
"&Open", self)
48 openAction.setShortcuts(QtGui.QKeySequence.Open)
49 openAction.setStatusTip(
"Open a file")
50 openAction.setIcon(QtGui.QIcon.fromTheme(
"document-open"))
51 openAction.triggered.connect(self.
open)
53 saveAction = QtWidgets.QAction(
"&Save", self)
54 saveAction.setShortcuts(QtGui.QKeySequence.Save)
55 saveAction.setStatusTip(
"Save file")
56 saveAction.setIcon(QtGui.QIcon.fromTheme(
"document-save"))
57 saveAction.triggered.connect(self.
save)
59 saveAsAction = QtWidgets.QAction(
"Save_&As", self)
60 saveAsAction.setShortcuts(QtGui.QKeySequence.SaveAs)
61 saveAsAction.setStatusTip(
"Save file as...")
62 saveAsAction.setIcon(QtGui.QIcon.fromTheme(
"document-save-as"))
63 saveAsAction.triggered.connect(self.
save_as)
65 undoAction = self.editor.undo_stack.createUndoAction(self, self.tr(
"&Undo"))
66 undoAction.setShortcuts(QtGui.QKeySequence.Undo)
67 undoAction.setIcon(QtGui.QIcon.fromTheme(
"edit-undo"))
68 redoAction = self.editor.undo_stack.createRedoAction(self, self.tr(
"&Redo"))
69 redoAction.setShortcuts(QtGui.QKeySequence.Redo)
70 redoAction.setIcon(QtGui.QIcon.fromTheme(
"edit-redo"))
86 tool_bar = self.widget.mainToolBar
88 undoButton = QtWidgets.QToolButton()
89 undoButton.setDefaultAction(undoAction)
90 redoButton = QtWidgets.QToolButton()
91 redoButton.setDefaultAction(redoAction)
93 tool_bar.addAction(newAction)
94 tool_bar.addAction(openAction)
95 tool_bar.addAction(saveAction)
96 tool_bar.addAction(saveAsAction)
97 tool_bar.addSeparator()
98 tool_bar.addWidget(undoButton)
99 tool_bar.addWidget(redoButton)
115 file_name, stuff = QtWidgets.QFileDialog.getOpenFileName(self.
widget,
116 "Select a file to open", self.settings.value(
'last_folder',
''), self.file_type)
118 if not file_name ==
"":
119 if self.editor.get_file_name() ==
"":
124 print(
"current filename '{}'".format(self.editor.get_file_name()))
125 choice = QtWidgets.QMessageBox.question(self.
widget,
126 "Keep current frames?",
127 "Do you want to keep frames in your list, which are not in the currently loaded file?",
128 QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.Yes)
129 if choice == QtWidgets.QMessageBox.Yes:
137 if not self.editor.load_file(file_name):
138 print(
"ERROR LOADING FILE")
144 self.settings.setValue(
'last_folder', os.path.dirname(file_name))
149 """If the file has been modified, the user is asked, whether he wants to save it first or not. 150 Returns True when the file has been saved or was unmodified. 151 Returns False when the user reconsiders in case of an unmodified file. 153 if self.widget.isWindowModified():
154 reply = QtWidgets.QMessageBox.warning(self.
widget,
"frame editor",
155 "The file has been modified.\nDo you want to save your changes?",
156 QtWidgets.QMessageBox.Yes |
157 QtWidgets.QMessageBox.No |
158 QtWidgets.QMessageBox.Cancel |
159 QtWidgets.QMessageBox.Escape,
160 QtWidgets.QMessageBox.Yes)
162 if reply == QtWidgets.QMessageBox.Yes:
164 elif reply == QtWidgets.QMessageBox.Cancel:
170 """Calls save_as or save_file 172 if self.editor.get_file_name() ==
"":
175 return self.
save_file(self.editor.get_full_file_path())
180 file_name, stuff = QtWidgets.QFileDialog.getSaveFileName(
None,
"Save File", self.editor.get_full_file_path(), self.file_type)
184 if not file_name.endswith(
".yaml"):
190 print(
"Saving canceled")
198 raise NotImplementedError
202 self.editor.undo_stack.setClean()
203 self.widget.setWindowModified(
False)
205 file_name = self.editor.get_file_name()
208 shown_name =
"Untitled" 209 if not file_name ==
"":
210 shown_name = file_name
213 self.widget.lab_file_name.setText(self.tr(
'{} [*] - {}'.format(shown_name,
"frame editor")))
216 return QtCore.QFileInfo(full_name).fileName()
219 self.widget.setWindowModified(
not is_clean)
229 if self.widget.isWindowModified():
230 reply = QtWidgets.QMessageBox.warning(self.
widget,
"frame editor",
231 "The file has been modified.\nDo you want to save your changes before exiting (Save As...)?",
232 QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.Default,
233 QtWidgets.QMessageBox.No)
235 if reply == QtWidgets.QMessageBox.Yes:
def save_file(self, file_name)
def load_file(self, file_name)
def stripped_name(self, full_name)
def write_file(self, file_name)
def save_settings(self, plugin_settings, instance_settings)
def restore_settings(self, plugin_settings, instance_settings)
def create_main_widget(self)
def update_current_filename(self)
def __init__(self, context)
def shutdown_plugin(self)
PLUGIN ##.
def clean_changed(self, is_clean)