def add_entry_row(self): row = self.ui.table_times.rowCount() self.ui.table_times.insertRow(row) qte = QTimeEdit(self.ui.table_times) qte.setFocus() self.ui.table_times.setCellWidget(row, E_START_TIME_COL, qte) self.ui.table_times.setCellWidget(row, E_END_TIME_COL, QTimeEdit(self.ui.table_times)) self.ui.table_times.resizeRowsToContents()
def __clean_and_load_entries__(self, working_date: str): """ Cleans entry table when switch working day. :param working_date: :return: """ row = 0 entries = self.time_capture_service.load_working_entries(working_date) clean_table(self.ui.table_times) for e in entries: self.ui.table_times.insertRow(row) qte = QTimeEdit(self.ui.table_times) qte.setTime(e[wek.START_TIME]) self.ui.table_times.setCellWidget(row, E_START_TIME_COL, qte) qte = QTimeEdit(self.ui.table_times) qte.setTime(e[wek.END_TIME]) self.ui.table_times.setCellWidget(row, E_END_TIME_COL, qte) self.ui.table_times.setItem(row, E_ORDER_COL, QTableWidgetItem(e[wek.ORDER])) self.ui.table_times.setItem(row, E_COMMENT_COL, QTableWidgetItem(e[wek.COMMENT])) row += 1 self.ui.table_times.resizeRowsToContents()
def _init_ui(self): # Widgets self._txt_title = TextAttributeLineEdit(attribute=self.CLASS.title) self._txt_author = TextAttributeLineEdit(attribute=self.CLASS.author) self._txt_owner = TextAttributeLineEdit(attribute=self.CLASS.owner) self._txt_date = QDateEdit() self._txt_date.setDisplayFormat('yyyy-MM-dd') self._txt_time = QTimeEdit() self._txt_time.setDisplayFormat('hh:mm:ss') self._txt_timezone = TextAttributeLineEdit(attribute=self.CLASS.timezone) self._txt_checksum = TextAttributeLineEdit(attribute=self.CLASS.checksum) self._txt_checksum.setReadOnly(True) # Layouts layout = ParameterWidget._init_ui(self) layout.addRow('Title', self._txt_title) layout.addRow('Author', self._txt_author) layout.addRow('Owner', self._txt_owner) layout.addRow('Date', self._txt_date) layout.addRow('Time', self._txt_time) layout.addRow('Timezone', self._txt_timezone) layout.addRow('Checksum', self._txt_checksum) # Signals self._txt_title.textEdited.connect(self.edited) self._txt_author.textEdited.connect(self.edited) self._txt_owner.textEdited.connect(self.edited) self._txt_date.dateChanged.connect(self.edited) self._txt_time.timeChanged.connect(self.edited) self._txt_timezone.textEdited.connect(self.edited) self._txt_checksum.textEdited.connect(self.edited) return layout
def __init__(self, theme='dark', emphasized=False): super().__init__(None) self.setProperty('emphasized', emphasized) self.setStyleSheet(template(raw_stylesheet, **palettes[theme])) lay = QVBoxLayout() self.setLayout(lay) lay.addWidget(QPushButton('push button')) box = QComboBox() box.addItems(['a', 'b', 'c', 'cd']) lay.addWidget(box) lay.addWidget(QFontComboBox()) hbox = QHBoxLayout() chk = QCheckBox('tristate') chk.setToolTip('I am a tooltip') chk.setTristate(True) chk.setCheckState(Qt.PartiallyChecked) chk3 = QCheckBox('checked') chk3.setChecked(True) hbox.addWidget(QCheckBox('unchecked')) hbox.addWidget(chk) hbox.addWidget(chk3) lay.addLayout(hbox) lay.addWidget(TabDemo(emphasized=emphasized)) sld = QSlider(Qt.Horizontal) sld.setValue(50) lay.addWidget(sld) scroll = QScrollBar(Qt.Horizontal) scroll.setValue(50) lay.addWidget(scroll) lay.addWidget(QHRangeSlider(parent=self)) text = QTextEdit() text.setMaximumHeight(100) text.setHtml(blurb) lay.addWidget(text) lay.addWidget(QTimeEdit()) edit = QLineEdit() edit.setPlaceholderText('LineEdit placeholder...') lay.addWidget(edit) lay.addWidget(QLabel('label')) prog = QProgressBar() prog.setValue(50) lay.addWidget(prog) groupBox = QGroupBox("Exclusive Radio Buttons") radio1 = QRadioButton("&Radio button 1") radio2 = QRadioButton("R&adio button 2") radio3 = QRadioButton("Ra&dio button 3") radio1.setChecked(True) hbox = QHBoxLayout() hbox.addWidget(radio1) hbox.addWidget(radio2) hbox.addWidget(radio3) hbox.addStretch(1) groupBox.setLayout(hbox) lay.addWidget(groupBox)
def switch_rows(table: QTableWidget, old_position, new_position): """ Helper function to switch a row in a table. Works for booking and entry table. :param table: :param old_position: :param new_position: :return: """ for col_index in range(table.columnCount()): old_item = table.item(old_position, col_index) new_item = table.item(new_position, col_index) if old_item is not None and new_item is not None: old_text = old_item.text() new_text = new_item.text() table.setItem(old_position, col_index, QTableWidgetItem(new_text)) table.setItem(new_position, col_index, QTableWidgetItem(old_text)) else: old_cell_widget = table.cellWidget(old_position, col_index) new_cell_widget = table.cellWidget(new_position, col_index) if old_cell_widget is not None and new_cell_widget is not None: if isinstance(old_cell_widget, QTimeEdit) and isinstance(new_cell_widget, QTimeEdit): qte = QTimeEdit(table) qte.setTime(new_cell_widget.time()) table.setCellWidget(old_position, col_index, qte) qte = QTimeEdit(table) qte.setTime(old_cell_widget.time()) table.setCellWidget(new_position, col_index, qte) if isinstance(old_cell_widget, QDoubleSpinBox) and isinstance(new_cell_widget, QDoubleSpinBox): qdsb = QDoubleSpinBox(table) qdsb.setValue(new_cell_widget.value()) table.setCellWidget(old_position, col_index, qdsb) qdsb = QDoubleSpinBox(table) qdsb.setValue(old_cell_widget.value()) table.setCellWidget(new_position, col_index, qdsb) if isinstance(old_cell_widget, QCheckBox) and isinstance(new_cell_widget, QCheckBox): qcb = QCheckBox(table) qcb.setChecked(new_cell_widget.isChecked()) table.setCellWidget(old_position, col_index, qcb) qcb = QCheckBox(table) qcb.setChecked(old_cell_widget.isChecked()) table.setCellWidget(new_position, col_index, qcb)
class HeaderWidget(ParameterWidget): def __init__(self, parent=None): ParameterWidget.__init__(self, Header, parent) def _init_ui(self): # Widgets self._txt_title = TextAttributeLineEdit(attribute=self.CLASS.title) self._txt_author = TextAttributeLineEdit(attribute=self.CLASS.author) self._txt_owner = TextAttributeLineEdit(attribute=self.CLASS.owner) self._txt_date = QDateEdit() self._txt_date.setDisplayFormat('yyyy-MM-dd') self._txt_time = QTimeEdit() self._txt_time.setDisplayFormat('hh:mm:ss') self._txt_timezone = TextAttributeLineEdit(attribute=self.CLASS.timezone) self._txt_checksum = TextAttributeLineEdit(attribute=self.CLASS.checksum) self._txt_checksum.setReadOnly(True) # Layouts layout = ParameterWidget._init_ui(self) layout.addRow('Title', self._txt_title) layout.addRow('Author', self._txt_author) layout.addRow('Owner', self._txt_owner) layout.addRow('Date', self._txt_date) layout.addRow('Time', self._txt_time) layout.addRow('Timezone', self._txt_timezone) layout.addRow('Checksum', self._txt_checksum) # Signals self._txt_title.textEdited.connect(self.edited) self._txt_author.textEdited.connect(self.edited) self._txt_owner.textEdited.connect(self.edited) self._txt_date.dateChanged.connect(self.edited) self._txt_time.timeChanged.connect(self.edited) self._txt_timezone.textEdited.connect(self.edited) self._txt_checksum.textEdited.connect(self.edited) return layout def parameter(self, parameter=None): parameter = ParameterWidget.parameter(self, parameter) parameter.title = self._txt_title.text() parameter.author = self._txt_author.text() parameter.owner = self._txt_owner.text() parameter.date = self._txt_date.date().toString('yyyy-MM-dd') parameter.time = self._txt_time.time().toString('hh:mm:ss') parameter.timezone = self._txt_timezone.text() return parameter def setParameter(self, header): ParameterWidget.setParameter(self, header) self._txt_title.setText(header.title) self._txt_author.setText(header.author) self._txt_owner.setText(header.owner) date = header.date if date is not None: self._txt_date.setDate(QDate(date.year, date.month, date.day)) time = header.time if time is not None: self._txt_time.setTime(QTime(time.hour, time.minute, time.second)) self._txt_timezone.setText(header.timezone) checksum = header.checksum if checksum is not None: self._txt_checksum.setText(checksum.value) def header(self, header=None): return self.parameter(header) def setHeader(self, header): self.setParameter(header) def setReadOnly(self, state): ParameterWidget.setReadOnly(self, state) self._txt_title.setReadOnly(state) self._txt_author.setReadOnly(state) self._txt_owner.setReadOnly(state) self._txt_date.setReadOnly(state) self._txt_time.setReadOnly(state) self._txt_timezone.setReadOnly(state) self._txt_checksum.setReadOnly(state) def isReadOnly(self): return ParameterWidget.isReadOnly(self) and \ self._txt_title.isReadOnly() and \ self._txt_author.isReadOnly() and \ self._txt_owner.isReadOnly() and \ self._txt_date.isReadOnly() and \ self._txt_time.isReadOnly() and \ self._txt_timezone.isReadOnly() and \ self._txt_checksum.isReadOnly() def hasAcceptableInput(self): return ParameterWidget.hasAcceptableInput(self) and \ self._txt_title.hasAcceptableInput() and \ self._txt_author.hasAcceptableInput() and \ self._txt_owner.hasAcceptableInput() and \ self._txt_date.hasAcceptableInput() and \ self._txt_time.hasAcceptableInput() and \ self._txt_timezone.hasAcceptableInput() and \ self._txt_checksum.hasAcceptableInput()