25 from datetime
import datetime
26 from PyQt4
import QtCore, QtGui
28 from loader_list_model
import LoaderListModel
29 from file_loader
import GenericLoader
35 QtGui.QDialog.__init__(self, parent)
46 self.list_view_.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
48 loader_label = QtGui.QLabel(self.
text_)
49 font = loader_label.font()
53 self.add_action.setIcon(QtGui.QIcon(LoaderManagerWidget.ICONS_DIR+
"add_icon.png"))
55 QtCore.QObject.connect(self.
add_action, QtCore.SIGNAL(
"triggered()"), self.
Add)
58 self.add_button_.setIconSize(QtCore.QSize(20,20))
59 self.add_button_.setDefaultAction(self.
add_action)
61 grid = QtGui.QGridLayout()
62 grid.setContentsMargins(0,5,0,0)
63 grid.addWidget(loader_label, 0, 0, 1, 1)
64 qhbox = QtGui.QHBoxLayout()
69 self.list_view_.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
73 QtCore.QObject.connect(self.
list_view_, QtCore.SIGNAL(
"doubleClicked(const QModelIndex)"), self.
Edit)
80 self.contextMenu_.addAction(self.
remove_)
81 self.contextMenu_.addAction(self.
rename_)
82 self.contextMenu_.addAction(self.
edit_)
84 QtCore.QObject.connect(self.
remove_, QtCore.SIGNAL(
"triggered()"), self.
Remove)
85 QtCore.QObject.connect(self.
rename_, QtCore.SIGNAL(
"triggered()"), self.
Rename)
86 QtCore.QObject.connect(self.
edit_, QtCore.SIGNAL(
"triggered()"), self.
Edit)
90 index = self.list_view_.indexAt(pos)
92 if self.list_model_.IsEditable(index.row()):
93 self.contextMenu_.popup(QtGui.QCursor.pos())
96 row = self.list_model_.GetLastRow()
99 if edit_widget.exec_()
and self.list_model_.AddItem(datetime.now().isoformat(
' '), edit_widget.GetLoader(), row,
True,
True):
100 index = self.list_model_.index(row)
101 self.list_view_.setCurrentIndex(index)
105 current_index = self.list_view_.currentIndex()
106 loader = self.list_model_.GetLoader(current_index)
108 edit_widget.SetLoader(loader)
109 if edit_widget.exec_():
110 self.list_model_.SetItem(current_index, edit_widget.GetLoader())
114 if(self.list_view_.currentIndex().isValid()):
115 ret = QtGui.QMessageBox.warning(self,
"Delete File Loader",
116 "Delete File Loader?",
117 QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
118 if ret == QtGui.QMessageBox.Yes:
119 self.list_model_.RemoveItem(self.list_view_.currentIndex().row())
122 if(self.list_view_.currentIndex().isValid()):
123 self.list_view_.edit(self.list_view_.currentIndex())
133 QtGui.QDialog.__init__(self, parent)
134 name_ext_label = QtGui.QLabel(
"Name Extension")
137 url_label = QtGui.QLabel(
"Url")
140 self.add_id_button_.setDefaultAction(QtGui.QAction(
"ID",self))
142 file_ext_label = QtGui.QLabel(
"File Type")
150 self.hbox_.addStretch()
153 grid = QtGui.QGridLayout()
154 grid.setContentsMargins(0,5,0,0)
155 grid.addWidget(name_ext_label, 0, 0, 1, 1)
157 grid.addWidget(url_label, 1, 0, 1, 1)
158 grid.addWidget(self.
url_edit_, 1, 1, 1, 3)
160 grid.addWidget(file_ext_label, 2, 0, 1, 1)
163 grid.addLayout(self.
hbox_,3,0,1,2)
164 grid.setRowStretch(2, 1)
169 QtCore.QObject.connect(self.
ok_button_, QtCore.SIGNAL(
"clicked()"), self.
Ok)
173 name_ext = str(self.name_ext_edit_.text())
174 url = str(self.url_edit_.text())
176 if not self.file_ext_auto_.isChecked():
177 file_ext = str(self.file_ext_edit_.text())
179 return GenericLoader(name_ext, url,
False, file_ext)
182 self.name_ext_edit_.setText(loader.name_)
183 self.url_edit_.setText(loader.url_)
184 if loader.file_type_
is not None:
185 self.file_ext_edit_.setText(loader.file_type_)
186 self.file_ext_auto_.setChecked(
False)
188 self.file_ext_auto_.setChecked(
True)
190 self.url_edit_.setText(self.url_edit_.text()+
"${ID}")
193 self.file_ext_edit_.setEnabled(
not self.file_ext_auto_.isChecked())