def createEditor(self, parent, option, index): m = index.model() col = m.column_map[index.column()] if m.custom_columns[col]['datatype'] == 'int': editor = QSpinBox(parent) editor.setRange(-1000000, 100000000) editor.setSpecialValueText(_('Undefined')) editor.setSingleStep(1) else: editor = QDoubleSpinBox(parent) editor.setSpecialValueText(_('Undefined')) editor.setRange(-1000000., 100000000) editor.setDecimals(2) return editor
class AddEmptyBookDialog(QDialog): def __init__(self, parent, db, author, series=None): QDialog.__init__(self, parent) self.db = db self.setWindowTitle(_('How many empty books?')) self._layout = QGridLayout(self) self.setLayout(self._layout) self.qty_label = QLabel(_('How many empty books should be added?')) self._layout.addWidget(self.qty_label, 0, 0, 1, 2) self.qty_spinbox = QSpinBox(self) self.qty_spinbox.setRange(1, 10000) self.qty_spinbox.setValue(1) self._layout.addWidget(self.qty_spinbox, 1, 0, 1, 2) self.author_label = QLabel(_('Set the author of the new books to:')) self._layout.addWidget(self.author_label, 2, 0, 1, 2) self.authors_combo = EditWithComplete(self) self.authors_combo.setSizeAdjustPolicy( self.authors_combo.AdjustToMinimumContentsLengthWithIcon) self.authors_combo.setEditable(True) self._layout.addWidget(self.authors_combo, 3, 0, 1, 1) self.initialize_authors(db, author) self.clear_button = QToolButton(self) self.clear_button.setIcon(QIcon(I('trash.png'))) self.clear_button.setToolTip(_('Reset author to Unknown')) self.clear_button.clicked.connect(self.reset_author) self._layout.addWidget(self.clear_button, 3, 1, 1, 1) self.series_label = QLabel(_('Set the series of the new books to:')) self._layout.addWidget(self.series_label, 4, 0, 1, 2) self.series_combo = EditWithComplete(self) self.authors_combo.setSizeAdjustPolicy( self.authors_combo.AdjustToMinimumContentsLengthWithIcon) self.series_combo.setEditable(True) self._layout.addWidget(self.series_combo, 5, 0, 1, 1) self.initialize_series(db, series) self.sclear_button = QToolButton(self) self.sclear_button.setIcon(QIcon(I('trash.png'))) self.sclear_button.setToolTip(_('Reset series')) self.sclear_button.clicked.connect(self.reset_series) self._layout.addWidget(self.sclear_button, 5, 1, 1, 1) self.create_epub = c = QCheckBox( _('Create an empty EPUB file as well')) c.setChecked(gprefs.get('create_empty_epub_file', False)) c.setToolTip( _('Also create an empty EPUB file that you can subsequently edit')) self._layout.addWidget(c, 6, 0, 1, -1) button_box = self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) button_box.accepted.connect(self.accept) button_box.rejected.connect(self.reject) self._layout.addWidget(button_box, 7, 0, 1, -1) self.resize(self.sizeHint()) def accept(self): oval = gprefs.get('create_empty_epub_file', False) if self.create_epub.isChecked() != oval: gprefs['create_empty_epub_file'] = self.create_epub.isChecked() return QDialog.accept(self) def reset_author(self, *args): self.authors_combo.setEditText(_('Unknown')) def reset_series(self): self.series_combo.setEditText('') def initialize_authors(self, db, author): au = author if not au: au = _('Unknown') self.authors_combo.show_initial_value(au.replace('|', ',')) self.authors_combo.set_separator('&') self.authors_combo.set_space_before_sep(True) self.authors_combo.set_add_separator( tweaks['authors_completer_append_separator']) self.authors_combo.update_items_cache(db.all_author_names()) def initialize_series(self, db, series): self.series_combo.show_initial_value(series or '') self.series_combo.update_items_cache(db.all_series_names()) self.series_combo.set_separator(None) @property def qty_to_add(self): return self.qty_spinbox.value() @property def selected_authors(self): return string_to_authors(unicode(self.authors_combo.text())) @property def selected_series(self): return unicode(self.series_combo.text())
class AddEmptyBookDialog(QDialog): def __init__(self, parent, db, author, series=None): QDialog.__init__(self, parent) self.db = db self.setWindowTitle(_('How many empty books?')) self._layout = QGridLayout(self) self.setLayout(self._layout) self.qty_label = QLabel(_('How many empty books should be added?')) self._layout.addWidget(self.qty_label, 0, 0, 1, 2) self.qty_spinbox = QSpinBox(self) self.qty_spinbox.setRange(1, 10000) self.qty_spinbox.setValue(1) self._layout.addWidget(self.qty_spinbox, 1, 0, 1, 2) self.author_label = QLabel(_('Set the author of the new books to:')) self._layout.addWidget(self.author_label, 2, 0, 1, 2) self.authors_combo = EditWithComplete(self) self.authors_combo.setSizeAdjustPolicy( self.authors_combo.AdjustToMinimumContentsLengthWithIcon) self.authors_combo.setEditable(True) self._layout.addWidget(self.authors_combo, 3, 0, 1, 1) self.initialize_authors(db, author) self.clear_button = QToolButton(self) self.clear_button.setIcon(QIcon(I('trash.png'))) self.clear_button.setToolTip(_('Reset author to Unknown')) self.clear_button.clicked.connect(self.reset_author) self._layout.addWidget(self.clear_button, 3, 1, 1, 1) self.series_label = QLabel(_('Set the series of the new books to:')) self._layout.addWidget(self.series_label, 4, 0, 1, 2) self.series_combo = EditWithComplete(self) self.authors_combo.setSizeAdjustPolicy( self.authors_combo.AdjustToMinimumContentsLengthWithIcon) self.series_combo.setEditable(True) self._layout.addWidget(self.series_combo, 5, 0, 1, 1) self.initialize_series(db, series) self.sclear_button = QToolButton(self) self.sclear_button.setIcon(QIcon(I('trash.png'))) self.sclear_button.setToolTip(_('Reset series')) self.sclear_button.clicked.connect(self.reset_series) self._layout.addWidget(self.sclear_button, 5, 1, 1, 1) button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) button_box.accepted.connect(self.accept) button_box.rejected.connect(self.reject) self._layout.addWidget(button_box) self.resize(self.sizeHint()) def reset_author(self, *args): self.authors_combo.setEditText(_('Unknown')) def reset_series(self): self.series_combo.setEditText('') def initialize_authors(self, db, author): au = author if not au: au = _('Unknown') self.authors_combo.show_initial_value(au.replace('|', ',')) self.authors_combo.set_separator('&') self.authors_combo.set_space_before_sep(True) self.authors_combo.set_add_separator(tweaks['authors_completer_append_separator']) self.authors_combo.update_items_cache(db.all_author_names()) def initialize_series(self, db, series): self.series_combo.show_initial_value(series or '') self.series_combo.update_items_cache(db.all_series_names()) self.series_combo.set_separator(None) @property def qty_to_add(self): return self.qty_spinbox.value() @property def selected_authors(self): return string_to_authors(unicode(self.authors_combo.text())) @property def selected_series(self): return unicode(self.series_combo.text())
class DeviceTable(QtGui.QDialog): def __init__(self, parent=None): super(DeviceTable, self).__init__(parent) self.logger = logging.getLogger('console') self.records = {} self.resize(800,800) self.label_a = QLabel() self.label_a.setText("A: ") self.spinbox_a = QSpinBox() self.spinbox_a.setRange(-103,-38) self.spinbox_a.setValue(-41) self.spinbox_a.valueChanged.connect(self.spinboxChanged) self.spinboxChanged(self.spinbox_a.value()) self.slider_label = QLabel() self.slider_label.setText(" n:") self.slider = QSlider() self.slider.setOrientation(QtCore.Qt.Horizontal) self.slider.setRange(0, 40) self.slider.setValue(22) self.slider.setTickInterval(1) self.slider.valueChanged.connect(self.sliderChanged) self.sliderChanged(self.slider.value()) self.button_reset = QPushButton() self.button_reset.setText("Reset") self.button_reset.clicked.connect(self.reset) self.horizontalLayout = QtGui.QHBoxLayout() self.horizontalLayout.addWidget(self.label_a) self.horizontalLayout.addWidget(self.spinbox_a) self.horizontalLayout.addWidget(self.slider_label) self.horizontalLayout.addWidget(self.slider) self.horizontalLayout.addWidget(self.button_reset) self.table = QTableWidget() self.table.setColumnCount(8) self.table.setHorizontalHeaderLabels(['MAC','Count','RSSI','RSSI','Distance','RSSI_F', 'DIST_F','Battery']) # matplotlib stuff self.figure = plt.figure() self.canvas = FigureCanvas(self.figure) self.toolbar = NavigationToolbar(self.canvas, self) self.buttonPlot = QPushButton('Plot') self.buttonPlot.clicked.connect(self.plot) self.plot_layout = QtGui.QVBoxLayout() self.plot_layout.addWidget(self.toolbar) self.plot_layout.addWidget(self.canvas) self.plot_layout.addWidget(self.buttonPlot) self.ax = self.figure.add_subplot(111) self.ax.hold(False) self.statusbar = QStatusBar() self.statusbar.showMessage('Opening log file') self.verticalLayout = QtGui.QVBoxLayout() self.verticalLayout.addWidget(self.table) self.verticalLayout.addLayout(self.plot_layout) self.verticalLayout.addWidget(self.statusbar) self.mainLayout = QtGui.QVBoxLayout(self) self.mainLayout.addLayout(self.horizontalLayout) self.mainLayout.addLayout(self.verticalLayout) self.is_recording = False self.data = [-50] self.data_f = [-50] self.data_y = [0] def showEvent(self, *args, **kwargs): self.parent().ble_ascii_received.connect(self.bleAsciiReceived) return QtGui.QDialog.showEvent(self, *args, **kwargs) def closeEvent(self, *args, **kwargs): self.reset() self.parent().ble_ascii_received.disconnect(self.bleAsciiReceived) return QtGui.QDialog.closeEvent(self, *args, **kwargs) def spinboxChanged(self, value): self.distance_A = value; def sliderChanged(self, value): self.distance_n = value / 10.0; self.slider_label.setText("n [{0:.1f}]: ".format(self.distance_n)) def reset(self): self.table.setRowCount(0) self.records = {} try: self.file.close() except Exception: pass self.file = None self.is_recording = False def plot(self): data = [random.random() for i in range(10)] self.ax = self.figure.add_subplot(111) self.ax.hold(False) self.ax.plot(data, '*-') self.canvas.draw() def startRecording(self): self.filename = "./logs/" + time.strftime("%y%m%d-%H%M%S") + ".txt" try: if not os.path.exists("./logs"): os.makedirs("./logs") self.file = open(self.filename, "w") self.statusbar.showMessage("Recording to " + self.filename) self.is_recording = True except Exception, e: self.file = None self.is_recording = True self.logger.error(e) self.statusbar.showMessage("NOT RECORDING - check console log for errors")
class AddEmptyBookDialog(QDialog): def __init__(self, parent, db, author): QDialog.__init__(self, parent) self.db = db self.setWindowTitle(_('How many empty books?')) self._layout = QGridLayout(self) self.setLayout(self._layout) self.qty_label = QLabel(_('How many empty books should be added?')) self._layout.addWidget(self.qty_label, 0, 0, 1, 2) self.qty_spinbox = QSpinBox(self) self.qty_spinbox.setRange(1, 10000) self.qty_spinbox.setValue(1) self._layout.addWidget(self.qty_spinbox, 1, 0, 1, 2) self.author_label = QLabel(_('Set the author of the new books to:')) self._layout.addWidget(self.author_label, 2, 0, 1, 2) self.authors_combo = EditWithComplete(self) self.authors_combo.setSizeAdjustPolicy( self.authors_combo.AdjustToMinimumContentsLengthWithIcon) self.authors_combo.setEditable(True) self._layout.addWidget(self.authors_combo, 3, 0, 1, 1) self.initialize_authors(db, author) self.clear_button = QToolButton(self) self.clear_button.setIcon(QIcon(I('trash.png'))) self.clear_button.setToolTip(_('Reset author to Unknown')) self.clear_button.clicked.connect(self.reset_author) self._layout.addWidget(self.clear_button, 3, 1, 1, 1) button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) button_box.accepted.connect(self.accept) button_box.rejected.connect(self.reject) self._layout.addWidget(button_box) self.resize(self.sizeHint()) def reset_author(self, *args): self.authors_combo.setEditText(_('Unknown')) def initialize_authors(self, db, author): au = author if not au: au = _('Unknown') self.authors_combo.show_initial_value(au.replace('|', ',')) self.authors_combo.set_separator('&') self.authors_combo.set_space_before_sep(True) self.authors_combo.set_add_separator(tweaks['authors_completer_append_separator']) self.authors_combo.update_items_cache(db.all_author_names()) @property def qty_to_add(self): return self.qty_spinbox.value() @property def selected_authors(self): return string_to_authors(unicode(self.authors_combo.text()))