class GUI(object): def __init__(self, MainWindow): MainWindow.setObjectName("MainWindow") # Set size of window MainWindow.resize(800, 589) MainWindow.setFocusPolicy(QtCore.Qt.NoFocus) MainWindow.setWindowTitle("Text to Kill") self.centralwidget = QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.gridLayout = QGridLayout(self.centralwidget) self.gridLayout.setMargin(0) self.gridLayout.setObjectName("gridLayout") self.stackedWidget = QStackedWidget(self.centralwidget) self.stackedWidget.setEnabled(True) self.stackedWidget.setObjectName("stackedWidget") font = QFont() font.setFamily("Times New Roman") # Main menu page self.menuPage = QWidget() self.menuPage.setObjectName("menuPage") self.titleLabel = QLabel(self.menuPage) self.titleLabel.setGeometry(QtCore.QRect(250, 60, 300, 50)) font.setPointSize(45) self.titleLabel.setFont(font) self.titleLabel.setAlignment(QtCore.Qt.AlignCenter) self.titleLabel.setObjectName("titleLabel") self.titleLabel.setText("Text to Kill") self.subtitleLabel = QLabel(self.menuPage) self.subtitleLabel.setGeometry(QtCore.QRect(100, 140, 600, 40)) font.setPointSize(25) self.subtitleLabel.setFont(font) self.subtitleLabel.setAlignment(QtCore.Qt.AlignCenter) self.subtitleLabel.setObjectName("subtitleLabel") self.subtitleLabel.setText("The Murder Mystery Automation System") self.createButton = QPushButton(self.menuPage) self.createButton.setGeometry(QtCore.QRect(310, 260, 180, 60)) self.createButton.setObjectName("createButton") self.createButton.setText("Create Game") self.runButton = QPushButton(self.menuPage) self.runButton.setGeometry(QtCore.QRect(310, 350, 180, 60)) self.runButton.setObjectName("runButton") self.runButton.setText("Run Game") self.stackedWidget.addWidget(self.menuPage) # Create page self.createPage = QWidget() self.createPage.setObjectName("createPage") self.createTabWidget = QTabWidget(self.createPage) self.createTabWidget.setGeometry(QtCore.QRect(0, 0, 800, 600)) self.createTabWidget.setFocusPolicy(QtCore.Qt.NoFocus) self.createTabWidget.setObjectName("createTabWidget") # Create game tab self.createTab = QWidget() self.createTab.setObjectName("createTab") self.createDoneButton = QPushButton(self.createTab) self.createDoneButton.setGeometry(QtCore.QRect(580, 470, 180, 60)) self.createDoneButton.setObjectName("createDoneButton") self.createDoneButton.setText("Done") self.gameNameEdit = QLineEdit(self.createTab) self.gameNameEdit.setGeometry(QtCore.QRect(140, 20, 160, 30)) self.gameNameEdit.setObjectName("gameNameEdit") self.gameNameLabel = QLabel(self.createTab) self.gameNameLabel.setGeometry(QtCore.QRect(20, 25, 110, 20)) font.setPointSize(15) self.gameNameLabel.setFont(font) self.gameNameLabel.setAlignment(QtCore.Qt.AlignCenter) self.gameNameLabel.setObjectName("gameNameLabel") self.gameNameLabel.setText("Game name") self.line = QFrame(self.createTab) self.line.setGeometry(QtCore.QRect(20, 150, 311, 20)) self.line.setFrameShape(QFrame.HLine) self.line.setFrameShadow(QFrame.Sunken) self.line.setObjectName("line") self.addCharLabel = QLabel(self.createTab) self.addCharLabel.setGeometry(QtCore.QRect(20, 180, 160, 20)) font.setPointSize(20) self.addCharLabel.setFont(font) self.addCharLabel.setAlignment(QtCore.Qt.AlignCenter) self.addCharLabel.setObjectName("addCharLabel") self.addCharLabel.setText("Add Character") self.charNameLabel = QLabel(self.createTab) self.charNameLabel.setGeometry(QtCore.QRect(20, 230, 66, 20)) font.setPointSize(15) self.charNameLabel.setFont(font) self.charNameLabel.setAlignment(QtCore.Qt.AlignCenter) self.charNameLabel.setObjectName("charNameLabel") self.charNameLabel.setText("Name") self.charNameEdit = QLineEdit(self.createTab) self.charNameEdit.setGeometry(QtCore.QRect(140, 220, 160, 30)) self.charNameEdit.setObjectName("charNameEdit") self.charAbilScroll = QListWidget(self.createTab) self.charAbilScroll.setGeometry(QtCore.QRect(140, 260, 161, 51)) self.charAbilScroll.setObjectName("charAbilScroll") self.characterTable = QTableWidget(self.createTab) self.characterTable.setGeometry(QtCore.QRect(405, 20, 381, 401)) self.characterTable.setFocusPolicy(QtCore.Qt.NoFocus) self.characterTable.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers) self.characterTable.setRowCount(1) self.characterTable.setColumnCount(2) self.characterTable.setObjectName("characterTable") self.characterTable.horizontalHeader().setVisible(False) self.characterTable.horizontalHeader().setCascadingSectionResizes(False) self.characterTable.horizontalHeader().setMinimumSectionSize(50) self.characterTable.horizontalHeader().setStretchLastSection(True) self.characterTable.verticalHeader().setVisible(False) self.characterTable.verticalHeader().setDefaultSectionSize(30) self.scrollArea = QListWidget(self.createTab) self.scrollArea.setGeometry(QtCore.QRect(140, 60, 161, 71)) self.scrollArea.setObjectName("scrollArea") self.scrollArea.setSelectionMode(3) self.createSaveButton = QPushButton(self.createTab) self.createSaveButton.setGeometry(QtCore.QRect(380, 470, 180, 60)) self.createSaveButton.setObjectName("createSaveButton") self.createSaveButton.setText("Save") self.charAbilitiesLabel = QLabel(self.createTab) self.charAbilitiesLabel.setGeometry(QtCore.QRect(30, 280, 71, 20)) font.setPointSize(15) self.charAbilitiesLabel.setFont(font) self.charAbilitiesLabel.setObjectName("charAbilitiesLabel") self.charAbilitiesLabel.setText("Abilities") self.abilitiesDropdown = QComboBox(self.createTab) self.abilitiesDropdown.setGeometry(QtCore.QRect(140, 330, 151, 25)) self.abilitiesDropdown.setObjectName("abilitiesDropdown") self.addCharButton = QPushButton(self.createTab) self.addCharButton.setGeometry(QtCore.QRect(30, 370, 98, 27)) self.addCharButton.setObjectName("addCharButton") self.addCharButton.setText("Add") self.gameAbilitiesLabel = QLabel(self.createTab) self.gameAbilitiesLabel.setGeometry(QtCore.QRect(30, 80, 71, 20)) self.setGameAbilButton = QPushButton(self.createTab) self.setGameAbilButton.setGeometry(QtCore.QRect(30, 110, 71, 27)) self.setGameAbilButton.setObjectName("setGameAbilButton") self.setGameAbilButton.setText("Set") self.saveCharButton = QPushButton(self.createTab) self.saveCharButton.setGeometry(QtCore.QRect(70, 430, 180, 60)) self.saveCharButton.setObjectName("saveCharButton") self.saveCharButton.setText("Save Character") font.setPointSize(15) self.gameAbilitiesLabel.setFont(font) self.gameAbilitiesLabel.setObjectName("gameAbilitiesLabel") self.gameAbilitiesLabel.setText("Abilities") self.createTabWidget.addTab(self.createTab, "") # Setup tab widget self.setupTab = QWidget() self.setupTab.setObjectName("setupTab") self.setupDoneButton = QPushButton(self.setupTab) self.setupDoneButton.setGeometry(QtCore.QRect(580, 470, 180, 60)) self.setupDoneButton.setObjectName("setupDoneButton") self.setupDoneButton.setText("Done") self.setupTable = QTableWidget(self.setupTab) self.setupTable.setGeometry(QtCore.QRect(20, 20, 750, 400)) self.setupTable.setFocusPolicy(QtCore.Qt.TabFocus) self.setupTable.setRowCount(1) self.setupTable.setColumnCount(3) self.setupTable.setObjectName("setupTable") self.setupTable.horizontalHeader().setVisible(False) self.setupTable.horizontalHeader().setCascadingSectionResizes(False) self.setupTable.horizontalHeader().setDefaultSectionSize(187) self.setupTable.horizontalHeader().setHighlightSections(False) self.setupTable.horizontalHeader().setStretchLastSection(True) self.setupTable.verticalHeader().setVisible(False) self.setupTable.verticalHeader().setHighlightSections(False) self.setupSaveButton = QPushButton(self.setupTab) self.setupSaveButton.setGeometry(QtCore.QRect(380, 470, 180, 60)) self.setupSaveButton.setObjectName("setupSaveButton") self.setupSaveButton.setText("Save") self.createTabWidget.addTab(self.setupTab, "") self.createTabWidget.setTabText(self.createTabWidget.indexOf(self.createTab), "Create New Game") self.createTabWidget.setTabText(self.createTabWidget.indexOf(self.setupTab), "Set Up Game") self.stackedWidget.addWidget(self.createPage) # Game page self.gamePage = QWidget() self.gamePage.setObjectName("gamePage") self.gameTabWidget = QTabWidget(self.gamePage) self.gameTabWidget.setGeometry(QtCore.QRect(0, 0, 800, 600)) self.gameTabWidget.setFocusPolicy(QtCore.Qt.NoFocus) self.gameTabWidget.setObjectName("gameTabWidget") self.statusTab = QWidget() self.statusTab.setObjectName("statusTab") self.startGameButton = QPushButton(self.statusTab) self.startGameButton.setGeometry(QtCore.QRect(60, 180, 180, 60)) self.startGameButton.setObjectName("startGameButton") self.startGameButton.setText("Start Game") self.endGameButton = QPushButton(self.statusTab) self.endGameButton.setGeometry(QtCore.QRect(60, 260, 180, 60)) self.endGameButton.setObjectName("endGameButton") self.endGameButton.setText("End Game") self.loadGameLabel = QLabel(self.statusTab) self.loadGameLabel.setGeometry(QtCore.QRect(20, 65, 101, 21)) font.setPointSize(15) self.loadGameLabel.setFont(font) self.loadGameLabel.setObjectName("loadGameLabel") self.loadGameLabel.setText("Load Game") self.gameTabWidget.addTab(self.statusTab, "") self.logTab = QWidget() self.logTab.setObjectName("logTab") self.logList = QListWidget(self.logTab) self.logList.setGeometry(QtCore.QRect(30, 30, 730, 500)) self.logList.setObjectName("logList") self.gameTabWidget.addTab(self.logTab, "") self.inputTab = QWidget() self.inputTab.setObjectName("inputTab") self.gameTabWidget.addTab(self.inputTab, "") self.gameTabWidget.setTabText(self.gameTabWidget.indexOf(self.statusTab), "Game Status") self.gameTabWidget.setTabText(self.gameTabWidget.indexOf(self.logTab), "Game Log") self.gameTabWidget.setTabText(self.gameTabWidget.indexOf(self.inputTab), "Input") self.stackedWidget.addWidget(self.gamePage) self.gridLayout.addWidget(self.stackedWidget, 0, 0, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.retranslateUi(MainWindow) self.stackedWidget.setCurrentIndex(0) self.createTabWidget.setCurrentIndex(0) self.gameTabWidget.setCurrentIndex(0) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): pass
class ViewDataToolsHistory(QMainWindow): def __init__(self, parent=None): super(ViewDataToolsHistory, self).__init__(parent) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # DATATOOLS HISTORY WINDOWS: # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ self.setWindowTitle(ui_strings.DATATOOLS_HISTORY_TITLE) self._width = 700 self._height = 380 self._left_margin = 10 self.resize(self._width, self._height) size_policy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) size_policy.setHorizontalStretch(0) size_policy.setVerticalStretch(0) size_policy.setHeightForWidth(self.sizePolicy().hasHeightForWidth()) self.setSizePolicy(size_policy) self.setMinimumSize(QtCore.QSize(self._width, self._height)) self.setMaximumSize(QtCore.QSize(self._width, self._height)) self.setWindowIcon(QIcon(resources.ICON_LOGO)) # central widget self.central_widget = QWidget(self) # toolbar # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # add toolbar options self.export_action = QAction(QIcon(resources.ICON_EXPORT), 'Export (Ctrl+E)', self) self.export_action.setShortcut('Ctrl+E') self.print_action = QAction(QIcon(resources.ICON_PRINT), 'Print (Ctrl+P)', self) self.print_action.setShortcut('Ctrl+P') self.toolbar = self.addToolBar('Options') self.toolbar.addAction(self.export_action) self.toolbar.addAction(self.print_action) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # group input files self.group_period = QGroupBox(self.central_widget) self.group_period.setGeometry( QtCore.QRect(self._left_margin, 10, 250, 50)) self.group_period.setTitle(ui_strings.DATATOOLS_HISTORY_FILTER) # group by: self.group_group_by = QGroupBox(self.central_widget) self.group_group_by.setGeometry(QtCore.QRect(270, 10, 250, 50)) self.group_group_by.setTitle(ui_strings.DATATOOLS_HISTORY_GROUP) # group by: errors self.rbtn_by_errors = QRadioButton( ui_strings.DATATOOLS_HISTORY_GROUP_ERROR, self.group_group_by) self.rbtn_by_errors.setGeometry(QtCore.QRect(10, 10, 80, 50)) # group by: status #self.group_by_status = QRadioButton(ui_strings.DATATOOLS_HISTORY_GROUP_STATUS, self.group_group_by) #self.group_by_status.setGeometry(QtCore.QRect(100, 10, 80, 50)) # group by: no group #self.group_by_no = QRadioButton(ui_strings.DATATOOLS_HISTORY_GROUP_NO, self.group_group_by) #self.group_by_no.setGeometry(QtCore.QRect(190, 10, 80, 50)) # push button to update table #self.btn_view_group = QPushButton(self.group_group_by) #self.btn_view_group.setGeometry(QtCore.QRect(160, 20, 50, 20)) #self.btn_view_group.setText(ui_strings.DATATOOLS_HISTORY_VIEW) # combobox periods self.cbo_period = QComboBox(self.group_period) self.cbo_period.setGeometry( QtCore.QRect(self._left_margin, 20, 130, 20)) # push button to update table #self.btn_view = QPushButton(self.group_period) #self.btn_view.setGeometry(QtCore.QRect(160, 20, 50, 20)) #self.btn_view.setText(ui_strings.DATATOOLS_HISTORY_VIEW) # table history self.tbl_uploads = QTableWidget(self.central_widget) self.tbl_uploads.setGeometry( QtCore.QRect(self._left_margin, 70, 680, 120)) # chart self.plot_widget = PlotWidget(self.central_widget, 8, 2) self.plot_widget.setGeometry( QtCore.QRect(self._left_margin, 200, 680, 130)) # records - "x records found" self.setCentralWidget(self.central_widget)
def make_widget(main, show=True): id = main.persistant['id'] table = QTableWidget() table.controller = ROITableController(table, main) table.setGeometry(QRect(20, 33, 496, 296)) table.setWindowTitle('ceilingfaan - ROI Table - Work in progress') analysis = s.query(Analysis).order_by(Analysis.date.desc()).all() table.setRowCount(len(analysis)) table.setColumnCount(4) table.setHorizontalHeaderLabels( QString('CONTROL,DATE,MOUSE,FILENAME').split(',')) current_analysis = None on_render = table.controller.on('render') on_import = table.controller.on('import') for nrow, entity in enumerate(analysis): if entity.id == id: print 'Found matching analysis data', id, 'at nrow:', nrow current_analysis = entity current_nrow = nrow continue for ncol, attr in enumerate('date mouse_id filename'.split()): field = getattr(entity, attr) item = QTableWidgetItem(str(field)) item.setFlags(Qt.ItemIsEnabled) table.setItem(nrow, ncol + 1, item) render_btn = QPushButton('Render', checkable=True) render_btn.setStyleSheet('font-size: 9px; background-color: skyblue;') import_btn = QPushButton('Import') import_btn.setStyleSheet('font-size: 9px;') btn_layout = QHBoxLayout() btn_layout.setContentsMargins(5, 0, 5, 0) btn_layout.addWidget(render_btn) btn_layout.addWidget(import_btn) btn_widget = QWidget() btn_widget.nrow = nrow btn_widget.analysis_id = entity.id btn_widget.ext_roi_set = None btn_widget.setLayout(btn_layout) table.setCellWidget(nrow, 0, btn_widget) render_btn.clicked.connect(on_render) import_btn.clicked.connect(on_import) if current_analysis: table.removeRow(current_nrow) table.insertRow(0) item = QTableWidgetItem('Current Analysis') item.setFlags(Qt.ItemIsEnabled) item.setTextAlignment(Qt.AlignCenter) table.setItem(0, 0, item) for ncol, attr in enumerate('date mouse_id filename'.split()): field = getattr(current_analysis, attr) item = QTableWidgetItem(str(field)) item.setFlags(Qt.ItemIsEnabled) table.setItem(0, ncol + 1, item) # debug.enter() table.setSelectionBehavior(QTableWidget.SelectRows) table.setSelectionMode(QTableWidget.NoSelection) table.resizeColumnsToContents() table.horizontalHeader().setStretchLastSection(True) if show: table.show() return table
class ViewDataTools(QMainWindow): def __init__(self, parent=None): super(ViewDataTools, self).__init__(parent) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # DATATOOLS WINDOWS: # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ self.setWindowTitle(ui_strings.DATATOOLS_TITLE) self._width = 680 self._height = 560 self._left_margin = 10 self.resize(self._width, self._height) size_policy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) size_policy.setHorizontalStretch(0) size_policy.setVerticalStretch(0) size_policy.setHeightForWidth(self.sizePolicy().hasHeightForWidth()) self.setSizePolicy(size_policy) self.setMinimumSize(QtCore.QSize(self._width, self._height)) self.setMaximumSize(QtCore.QSize(self._width, self._height)) self.setWindowIcon(QIcon(resources.ICON_LOGO)) # central widget self.central_widget = QWidget(self) # DataTools description self.lbl_description = QLabel(self.central_widget) self.lbl_description.setGeometry(QtCore.QRect(0, 0, self._width, 30)) self.lbl_description.setAlignment(QtCore.Qt.AlignCenter) self.lbl_description.setText(ui_strings.DATATOOLS_DESCRIPTION) # group input files self.group_input_file = QGroupBox(self.central_widget) self.group_input_file.setGeometry(QtCore.QRect(self._left_margin, 30, 660, 80)) self.group_input_file.setTitle(ui_strings.DATATOOLS_GROUP_INPUT) # frame input files self.frame_inputs = QFrame(self.group_input_file) self.frame_inputs.setGeometry(QtCore.QRect(self._left_margin, 0, 270, 80)) self.frame_inputs.setFrameShape(QFrame.StyledPanel) self.frame_inputs.setFrameShadow(QFrame.Raised) # label input type self.lbl_input_type = QLabel(self.frame_inputs) self.lbl_input_type.setGeometry(QtCore.QRect(20, 20, 60, 15)) self.lbl_input_type.setText(ui_strings.DATATOOLS_INPUT_TYPE) # button xls self.btn_xls = QToolButton(self.frame_inputs) self.btn_xls.setGeometry(QtCore.QRect(20, 35, 35, 35)) icon_xls = QIcon() icon_xls.addPixmap(QPixmap(resources.ICON_XLS), QIcon.Normal, QIcon.Off) self.btn_xls.setIcon(icon_xls) self.btn_xls.setIconSize(QtCore.QSize(24, 24)) self.btn_xls.setCheckable(True) self.btn_xls.setAutoExclusive(True) self.btn_xls.setObjectName("xls_button") # button csv self.btn_csv = QToolButton(self.frame_inputs) self.btn_csv.setGeometry(QtCore.QRect(60, 35, 35, 35)) icon_csv = QIcon() icon_csv.addPixmap(QPixmap(resources.ICON_CSV), QIcon.Normal, QIcon.Off) self.btn_csv.setIcon(icon_csv) self.btn_csv.setIconSize(QtCore.QSize(24, 24)) self.btn_csv.setCheckable(True) self.btn_csv.setAutoExclusive(True) self.btn_csv.setObjectName("csv_button") # checkbox csv with headers self.chk_csv_headers = QCheckBox(ui_strings.DATATOOLS_WITH_HEADERS, self.frame_inputs) self.chk_csv_headers.setGeometry(QtCore.QRect(100, 45, 110, 15)) self.chk_csv_headers.setEnabled(False) # TextEdit + PushButton (FindFolder) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # lbl sheet name self.lbl_file_path = QLabel(self.group_input_file) self.lbl_file_path.setGeometry(QtCore.QRect(250, 20, 120, 15)) self.lbl_file_path.setText(ui_strings.DATATOOLS_SELECT_FILE) self.txt_file = QLineEdit(self.group_input_file) self.txt_file.setGeometry(QtCore.QRect(250, 35, 160, 20)) self.txt_file.setReadOnly(True) self.btn_path = QPushButton(self.group_input_file) self.btn_path.setGeometry(QtCore.QRect(410, 34, 50, 22)) self.btn_path.setText(ui_strings.DATATOOLS_SELECT_BUTTON) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # lbl sheet name self.lbl_sheet_name = QLabel(self.group_input_file) self.lbl_sheet_name.setGeometry(QtCore.QRect(500, 20, 120, 15)) self.lbl_sheet_name.setText(ui_strings.DATATOOLS_SHEET_NAME) # Combobox select sheet - initially does not contain values self.cbo_sheet = QComboBox(self.group_input_file) self.cbo_sheet.setGeometry(QtCore.QRect(500, 35, 130, 20)) # data grid to visualize error messages self.tbl_errors = QTableWidget(self.central_widget) self.tbl_errors.setGeometry(QtCore.QRect(self._left_margin, 420, 660, 100)) # data grid to visualize those records with errors. self.tbl_uploaded_data = QTableWidget(self.central_widget) self.tbl_uploaded_data.setGeometry(QtCore.QRect(self._left_margin, 120, 500, 220)) # group run options self.group_run_options = QGroupBox(self.central_widget) self.group_run_options.setGeometry(QtCore.QRect(520, 120, 150, 220)) self.group_run_options.setTitle(ui_strings.DATATOOLS_GROUP_RUN) # Errors summary: # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # group summary errors self.group_errors = QGroupBox(self.central_widget) self.group_errors.setGeometry(QtCore.QRect(self._left_margin, 350, 660, 60)) self.group_errors.setTitle(ui_strings.DATATOOLS_HEADER_ERRORS) # lbl records self.lbl_records = QLabel(self.group_errors) self.lbl_records.setGeometry(QtCore.QRect(165, 15, 80, 15)) self.lbl_records.setAlignment(QtCore.Qt.AlignCenter) self.lbl_records.setText(ui_strings.DATATOOLS_RECORDS) self.txt_records = QLineEdit(self.group_errors) self.txt_records.setGeometry(QtCore.QRect(165, 30, 80, 20)) self.txt_records.setAlignment(QtCore.Qt.AlignCenter) self.txt_records.setReadOnly(True) # lbl errors self.lbl_errors = QLabel(self.group_errors) self.lbl_errors.setGeometry(QtCore.QRect(275, 15, 80, 15)) self.lbl_errors.setAlignment(QtCore.Qt.AlignCenter) self.lbl_errors.setText(ui_strings.DATATOOLS_ERRORS) self.txt_errors = QLineEdit(self.group_errors) self.txt_errors.setGeometry(QtCore.QRect(275, 30, 80, 20)) self.txt_errors.setAlignment(QtCore.Qt.AlignCenter) self.txt_errors.setReadOnly(True) # lbl time self.lbl_time = QLabel(self.group_errors) self.lbl_time.setGeometry(QtCore.QRect(385, 15, 80, 15)) self.lbl_time.setAlignment(QtCore.Qt.AlignCenter) self.lbl_time.setText(ui_strings.DATATOOLS_TIME) self.txt_time = QLineEdit(self.group_errors) self.txt_time.setGeometry(QtCore.QRect(385, 30, 80, 20)) self.txt_time.setAlignment(QtCore.Qt.AlignCenter) self.txt_time.setReadOnly(True) # history button self.btn_history = QToolButton(self.group_errors) self.btn_history.setGeometry(QtCore.QRect(500, 25, 100, 25)) icon_history = QIcon() icon_history.addPixmap(QPixmap(resources.ICON_HISTORY), QIcon.Normal, QIcon.Off) self.btn_history.setIcon(icon_history) self.btn_history.setIconSize(QtCore.QSize(20, 20)) self.btn_history.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) self.btn_history.setText(ui_strings.DATATOOLS_HISTORY) self.btn_history.setCheckable(True) self.btn_history.setAutoExclusive(True) self.btn_history.setObjectName("history_button") # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # btn data uploader self.btn_data_uploader = QPushButton(ui_strings.DATATOOLS_DATA_UPLOADER, self.group_run_options) self.btn_data_uploader.setGeometry(QtCore.QRect(10, 120, 90, 25)) self.btn_data_uploader.setCheckable(True) self.btn_data_uploader.setAutoExclusive(True) self.btn_data_uploader.setFlat(False) # btn data testing self.btn_data_testing = QPushButton(ui_strings.DATATOOLS_DATA_TESTING, self.group_run_options) self.btn_data_testing.setEnabled(False) self.btn_data_testing.setGeometry(QtCore.QRect(10, 150, 90, 25)) self.btn_data_testing.setCheckable(True) self.btn_data_testing.setAutoExclusive(True) # btn data to database self.btn_data_db = QPushButton(ui_strings.DATATOOLS_DATA_DB, self.group_run_options) self.btn_data_db.setEnabled(False) self.btn_data_db.setGeometry(QtCore.QRect(10, 179, 91, 23)) self.btn_data_db.setCheckable(True) self.btn_data_db.setAutoExclusive(True) # frame run options self.frame_run = QFrame(self.group_run_options) self.frame_run.setGeometry(QtCore.QRect(10, 30, 130, 80)) self.frame_run.setFrameShape(QFrame.StyledPanel) self.frame_run.setFrameShadow(QFrame.Raised) # option process until first error self.rbtn_process_error = QRadioButton(ui_strings.DATATOOLS_PROCESS_ERROR, self.frame_run) self.rbtn_process_error.setGeometry(QtCore.QRect(0, 0, 150, 20)) # option process all data self.rbtn_process_all = QRadioButton(ui_strings.DATATOOLS_PROCESS_ALL, self.frame_run) self.rbtn_process_all.setGeometry(QtCore.QRect(0, 20, 150, 30)) # checkbox to filter by records with errors. #self.chk_filter_errors = QCheckBox(ui_strings.DATATOOLS_FILTER_ERRORS, self.frame_run) #self.chk_filter_errors.setGeometry(QtCore.QRect(0, 50, 100, 15)) #self.chk_filter_errors.setEnabled(False) # icons -> pass - error: Initially are empty labels # if not started -> ICON_MINI_WAIT # if error -> ICON_DELETE # if pass -> ICON_CHECK # state icon data uploader self.lbl_state_du = QLabel(self.group_run_options) self.lbl_state_du.setGeometry(QtCore.QRect(110, 120, 20, 20)) self.lbl_state_du.setPixmap(QPixmap(resources.ICON_MINI_WAIT)) self.lbl_state_du.setScaledContents(True) # state icon data to database self.lbl_state_dt = QLabel(self.group_run_options) self.lbl_state_dt.setGeometry(QtCore.QRect(110, 150, 20, 20)) self.lbl_state_dt.setPixmap(QPixmap(resources.ICON_MINI_WAIT)) self.lbl_state_dt.setScaledContents(True) # state icon data testing self.lbl_state_db = QLabel(self.group_run_options) self.lbl_state_db.setGeometry(QtCore.QRect(110, 180, 20, 20)) self.lbl_state_db.setPixmap(QPixmap(resources.ICON_MINI_WAIT)) self.lbl_state_db.setScaledContents(True) # progress bar self.progress_bar = QProgressBar(self.central_widget) self.progress_bar.setGeometry(QtCore.QRect(self._left_margin, 530, 660, 15)) self.progress_bar.setMaximum(100) self.progress_bar.setProperty("value", 0) self.progress_bar.setTextVisible(True) self.progress_bar.setOrientation(QtCore.Qt.Horizontal) self.progress_bar.setInvertedAppearance(False) self.progress_bar.setTextDirection(QProgressBar.TopToBottom) self.setCentralWidget(self.central_widget)
class RemoveSentencesDlg(QDialog): def __init__(self): super(RemoveSentencesDlg, self).__init__() self.removeList = {} self.initUI() def initUI(self): ## create a font type for the label fontLabel = QFont('SansSerif', 14) ## create a label self.label = QLabel(self) self.label.setAutoFillBackground(True) self.label.setAlignment(Qt.AlignCenter) self.label.setGeometry(QRect(200, 10, 400, 40)) self.label.setFont(fontLabel) ## set the text for the Label self.label.setText('Remove the Sentences') ## Create a Table to hold all the sentences self.sentenceTable = QTableWidget(self) ## set the size and the position of the table self.sentenceTable.setGeometry(QRect(10, 60, 800, 400)) ## set the column count for the table self.sentenceTable.setColumnCount(1) sentenceHeaderList = ['Sentences From Table'] self.sentenceTable.setHorizontalHeaderLabels(sentenceHeaderList) self.sentenceTable.resizeColumnsToContents() self.sentenceTable.horizontalHeader().setStretchLastSection(True) self.sentenceTable.verticalHeader().setStretchLastSection(True) # Create a Remove button self.removeButton = QPushButton('Remove', self) self.removeButton.move(350, 600) # Create a close button self.closeButton = QPushButton('Close', self) self.closeButton.move(450, 600) ## Create signal for the remove button self.connect(self.removeButton, SIGNAL("clicked()"), self.onRemoveClicked) ## Create signal for the close button self.connect(self.closeButton, SIGNAL("clicked()"), self.closeClicked) ## Create signal for the sentence table self.connect(self.sentenceTable, SIGNAL('cellClicked(int, int)'), self.sentenceStateChanged) ## Get sentences from the database table self.getSentencesFromDatabase() self.setGeometry(800, 800, 900, 650) def getSentencesFromDatabase(self): ## returns the sentence and the corresponding word associated with it self.twoTypeList = data.Data().getSentencesFromDatabase() if len(self.twoTypeList) == 2: self.sentenceList = self.twoTypeList[0] ## load the sentences in the Table Widget self.loadSentencesInTable() def loadSentencesInTable(self): self.col = 0 if len(self.sentenceList) > 0: self.sentenceTable.setRowCount(len(self.sentenceList)) cellList = [] ## Create QTableWidgetItems from the sentence list for sentence in self.sentenceList: item = QTableWidgetItem(QString(sentence)) item.setFlags(Qt.ItemFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)) item.setCheckState(Qt.Unchecked) cellList.append(item) cellList.reverse() # set the widget items in the table for item in range(0, len(self.sentenceList)): self.sentenceTable.setItem(item, self.col, cellList.pop()) for index in range(0, len(self.sentenceList)): self.sentenceTable.verticalHeader().resizeSection(index, 100) if len(self.sentenceList) == 5: self.sentenceTable.setFixedHeight(500) if len(self.sentenceList) == 4: self.sentenceTable.setFixedHeight(400) elif len(self.sentenceList) == 3: self.sentenceTable.setFixedHeight(300) elif len(self.sentenceList) == 2: self.sentenceTable.setFixedHeight(200) elif len(self.sentenceList) == 1: self.sentenceTable.setFixedHeight(100) else: self.sentenceTable.clearContents() def sentenceStateChanged(self, row, col): if (self.sentenceTable.item(row, col).checkState() == 2): self.removeList[row] = self.sentenceTable.item(row, col).text() self.sentenceTable.item(row, col).setFlags(Qt.ItemFlags(Qt.ItemIsEditable | Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)) else: self.sentenceTable.item(row,col).setFlags(Qt.ItemFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)) del self.removeList[row] def onRemoveClicked(self): if len(self.removeList) == 0: QMessageBox.information(self, 'Remove Sentences', 'Select the Sentences to Delete') else: reply = QMessageBox.question(self, 'Remove Sentences', 'You want to delete the selected sentences', QMessageBox.Yes | QMessageBox.No) if reply == QMessageBox.Yes: for sentence in self.removeList: if sentence in self.sentenceList: self.sentenceList.remove(sentence) ## clear the contents of the Table self.sentenceTable.clearContents() cellList = [] ## Add the new entries into the table for sentence in self.sentenceList: item = QTableWidgetItem(QString(sentence)) item.setFlags(Qt.ItemFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)) item.setCheckState(Qt.Unchecked) cellList.append(item) cellList.reverse() for index in range(0, len(self.sentenceList)): self.sentenceTable.setItem(index, self.col, cellList.pop()) self.sentenceTable.setRowCount(len(self.sentenceList)) deleteSentences = [] for sentence in self.removeList.values(): deleteSentences.append(sentence) rowsDeletec = data.Data().deleteSentencesFromDatabase(deleteSentences) self.getSentencesFromDatabase() self.removeList = {} def closeClicked(self): reply = QMessageBox.question(self, "Remove Sentences", "Do you want to close the application", QMessageBox.Yes | QMessageBox.No) if reply == QMessageBox.Yes: self.reject()
class ViewDataToolsHistory(QMainWindow): def __init__(self, parent=None): super(ViewDataToolsHistory, self).__init__(parent) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # DATATOOLS HISTORY WINDOWS: # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ self.setWindowTitle(ui_strings.DATATOOLS_HISTORY_TITLE) self._width = 700 self._height = 380 self._left_margin = 10 self.resize(self._width, self._height) size_policy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) size_policy.setHorizontalStretch(0) size_policy.setVerticalStretch(0) size_policy.setHeightForWidth(self.sizePolicy().hasHeightForWidth()) self.setSizePolicy(size_policy) self.setMinimumSize(QtCore.QSize(self._width, self._height)) self.setMaximumSize(QtCore.QSize(self._width, self._height)) self.setWindowIcon(QIcon(resources.ICON_LOGO)) # central widget self.central_widget = QWidget(self) # toolbar # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # add toolbar options self.export_action = QAction(QIcon(resources.ICON_EXPORT), 'Export (Ctrl+E)', self) self.export_action.setShortcut('Ctrl+E') self.print_action = QAction(QIcon(resources.ICON_PRINT), 'Print (Ctrl+P)', self) self.print_action.setShortcut('Ctrl+P') self.toolbar = self.addToolBar('Options') self.toolbar.addAction(self.export_action) self.toolbar.addAction(self.print_action) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # group input files self.group_period = QGroupBox(self.central_widget) self.group_period.setGeometry(QtCore.QRect(self._left_margin, 10, 250, 50)) self.group_period.setTitle(ui_strings.DATATOOLS_HISTORY_FILTER) # group by: self.group_group_by = QGroupBox(self.central_widget) self.group_group_by.setGeometry(QtCore.QRect(270, 10, 250, 50)) self.group_group_by.setTitle(ui_strings.DATATOOLS_HISTORY_GROUP) # group by: errors self.rbtn_by_errors = QRadioButton(ui_strings.DATATOOLS_HISTORY_GROUP_ERROR, self.group_group_by) self.rbtn_by_errors.setGeometry(QtCore.QRect(10, 10, 80, 50)) # group by: status #self.group_by_status = QRadioButton(ui_strings.DATATOOLS_HISTORY_GROUP_STATUS, self.group_group_by) #self.group_by_status.setGeometry(QtCore.QRect(100, 10, 80, 50)) # group by: no group #self.group_by_no = QRadioButton(ui_strings.DATATOOLS_HISTORY_GROUP_NO, self.group_group_by) #self.group_by_no.setGeometry(QtCore.QRect(190, 10, 80, 50)) # push button to update table #self.btn_view_group = QPushButton(self.group_group_by) #self.btn_view_group.setGeometry(QtCore.QRect(160, 20, 50, 20)) #self.btn_view_group.setText(ui_strings.DATATOOLS_HISTORY_VIEW) # combobox periods self.cbo_period = QComboBox(self.group_period) self.cbo_period.setGeometry(QtCore.QRect(self._left_margin, 20, 130, 20)) # push button to update table #self.btn_view = QPushButton(self.group_period) #self.btn_view.setGeometry(QtCore.QRect(160, 20, 50, 20)) #self.btn_view.setText(ui_strings.DATATOOLS_HISTORY_VIEW) # table history self.tbl_uploads = QTableWidget(self.central_widget) self.tbl_uploads.setGeometry(QtCore.QRect(self._left_margin, 70, 680, 120)) # chart self.plot_widget = PlotWidget(self.central_widget, 8, 2) self.plot_widget.setGeometry(QtCore.QRect(self._left_margin, 200, 680, 130)) # records - "x records found" self.setCentralWidget(self.central_widget)
class ViewDataTools(QMainWindow): def __init__(self, parent=None): super(ViewDataTools, self).__init__(parent) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # DATATOOLS WINDOWS: # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ self.setWindowTitle(ui_strings.DATATOOLS_TITLE) self._width = 680 self._height = 560 self._left_margin = 10 self.resize(self._width, self._height) size_policy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) size_policy.setHorizontalStretch(0) size_policy.setVerticalStretch(0) size_policy.setHeightForWidth(self.sizePolicy().hasHeightForWidth()) self.setSizePolicy(size_policy) self.setMinimumSize(QtCore.QSize(self._width, self._height)) self.setMaximumSize(QtCore.QSize(self._width, self._height)) self.setWindowIcon(QIcon(resources.ICON_LOGO)) # central widget self.central_widget = QWidget(self) # DataTools description self.lbl_description = QLabel(self.central_widget) self.lbl_description.setGeometry(QtCore.QRect(0, 0, self._width, 30)) self.lbl_description.setAlignment(QtCore.Qt.AlignCenter) self.lbl_description.setText(ui_strings.DATATOOLS_DESCRIPTION) # group input files self.group_input_file = QGroupBox(self.central_widget) self.group_input_file.setGeometry( QtCore.QRect(self._left_margin, 30, 660, 80)) self.group_input_file.setTitle(ui_strings.DATATOOLS_GROUP_INPUT) # frame input files self.frame_inputs = QFrame(self.group_input_file) self.frame_inputs.setGeometry( QtCore.QRect(self._left_margin, 0, 270, 80)) self.frame_inputs.setFrameShape(QFrame.StyledPanel) self.frame_inputs.setFrameShadow(QFrame.Raised) # label input type self.lbl_input_type = QLabel(self.frame_inputs) self.lbl_input_type.setGeometry(QtCore.QRect(20, 20, 60, 15)) self.lbl_input_type.setText(ui_strings.DATATOOLS_INPUT_TYPE) # button xls self.btn_xls = QToolButton(self.frame_inputs) self.btn_xls.setGeometry(QtCore.QRect(20, 35, 35, 35)) icon_xls = QIcon() icon_xls.addPixmap(QPixmap(resources.ICON_XLS), QIcon.Normal, QIcon.Off) self.btn_xls.setIcon(icon_xls) self.btn_xls.setIconSize(QtCore.QSize(24, 24)) self.btn_xls.setCheckable(True) self.btn_xls.setAutoExclusive(True) self.btn_xls.setObjectName("xls_button") # button csv self.btn_csv = QToolButton(self.frame_inputs) self.btn_csv.setGeometry(QtCore.QRect(60, 35, 35, 35)) icon_csv = QIcon() icon_csv.addPixmap(QPixmap(resources.ICON_CSV), QIcon.Normal, QIcon.Off) self.btn_csv.setIcon(icon_csv) self.btn_csv.setIconSize(QtCore.QSize(24, 24)) self.btn_csv.setCheckable(True) self.btn_csv.setAutoExclusive(True) self.btn_csv.setObjectName("csv_button") # checkbox csv with headers self.chk_csv_headers = QCheckBox(ui_strings.DATATOOLS_WITH_HEADERS, self.frame_inputs) self.chk_csv_headers.setGeometry(QtCore.QRect(100, 45, 110, 15)) self.chk_csv_headers.setEnabled(False) # TextEdit + PushButton (FindFolder) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # lbl sheet name self.lbl_file_path = QLabel(self.group_input_file) self.lbl_file_path.setGeometry(QtCore.QRect(250, 20, 120, 15)) self.lbl_file_path.setText(ui_strings.DATATOOLS_SELECT_FILE) self.txt_file = QLineEdit(self.group_input_file) self.txt_file.setGeometry(QtCore.QRect(250, 35, 160, 20)) self.txt_file.setReadOnly(True) self.btn_path = QPushButton(self.group_input_file) self.btn_path.setGeometry(QtCore.QRect(410, 34, 50, 22)) self.btn_path.setText(ui_strings.DATATOOLS_SELECT_BUTTON) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # lbl sheet name self.lbl_sheet_name = QLabel(self.group_input_file) self.lbl_sheet_name.setGeometry(QtCore.QRect(500, 20, 120, 15)) self.lbl_sheet_name.setText(ui_strings.DATATOOLS_SHEET_NAME) # Combobox select sheet - initially does not contain values self.cbo_sheet = QComboBox(self.group_input_file) self.cbo_sheet.setGeometry(QtCore.QRect(500, 35, 130, 20)) # data grid to visualize error messages self.tbl_errors = QTableWidget(self.central_widget) self.tbl_errors.setGeometry( QtCore.QRect(self._left_margin, 420, 660, 100)) # data grid to visualize those records with errors. self.tbl_uploaded_data = QTableWidget(self.central_widget) self.tbl_uploaded_data.setGeometry( QtCore.QRect(self._left_margin, 120, 500, 220)) # group run options self.group_run_options = QGroupBox(self.central_widget) self.group_run_options.setGeometry(QtCore.QRect(520, 120, 150, 220)) self.group_run_options.setTitle(ui_strings.DATATOOLS_GROUP_RUN) # Errors summary: # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # group summary errors self.group_errors = QGroupBox(self.central_widget) self.group_errors.setGeometry( QtCore.QRect(self._left_margin, 350, 660, 60)) self.group_errors.setTitle(ui_strings.DATATOOLS_HEADER_ERRORS) # lbl records self.lbl_records = QLabel(self.group_errors) self.lbl_records.setGeometry(QtCore.QRect(165, 15, 80, 15)) self.lbl_records.setAlignment(QtCore.Qt.AlignCenter) self.lbl_records.setText(ui_strings.DATATOOLS_RECORDS) self.txt_records = QLineEdit(self.group_errors) self.txt_records.setGeometry(QtCore.QRect(165, 30, 80, 20)) self.txt_records.setAlignment(QtCore.Qt.AlignCenter) self.txt_records.setReadOnly(True) # lbl errors self.lbl_errors = QLabel(self.group_errors) self.lbl_errors.setGeometry(QtCore.QRect(275, 15, 80, 15)) self.lbl_errors.setAlignment(QtCore.Qt.AlignCenter) self.lbl_errors.setText(ui_strings.DATATOOLS_ERRORS) self.txt_errors = QLineEdit(self.group_errors) self.txt_errors.setGeometry(QtCore.QRect(275, 30, 80, 20)) self.txt_errors.setAlignment(QtCore.Qt.AlignCenter) self.txt_errors.setReadOnly(True) # lbl time self.lbl_time = QLabel(self.group_errors) self.lbl_time.setGeometry(QtCore.QRect(385, 15, 80, 15)) self.lbl_time.setAlignment(QtCore.Qt.AlignCenter) self.lbl_time.setText(ui_strings.DATATOOLS_TIME) self.txt_time = QLineEdit(self.group_errors) self.txt_time.setGeometry(QtCore.QRect(385, 30, 80, 20)) self.txt_time.setAlignment(QtCore.Qt.AlignCenter) self.txt_time.setReadOnly(True) # history button self.btn_history = QToolButton(self.group_errors) self.btn_history.setGeometry(QtCore.QRect(500, 25, 100, 25)) icon_history = QIcon() icon_history.addPixmap(QPixmap(resources.ICON_HISTORY), QIcon.Normal, QIcon.Off) self.btn_history.setIcon(icon_history) self.btn_history.setIconSize(QtCore.QSize(20, 20)) self.btn_history.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) self.btn_history.setText(ui_strings.DATATOOLS_HISTORY) self.btn_history.setCheckable(True) self.btn_history.setAutoExclusive(True) self.btn_history.setObjectName("history_button") # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # btn data uploader self.btn_data_uploader = QPushButton( ui_strings.DATATOOLS_DATA_UPLOADER, self.group_run_options) self.btn_data_uploader.setGeometry(QtCore.QRect(10, 120, 90, 25)) self.btn_data_uploader.setCheckable(True) self.btn_data_uploader.setAutoExclusive(True) self.btn_data_uploader.setFlat(False) # btn data testing self.btn_data_testing = QPushButton(ui_strings.DATATOOLS_DATA_TESTING, self.group_run_options) self.btn_data_testing.setEnabled(False) self.btn_data_testing.setGeometry(QtCore.QRect(10, 150, 90, 25)) self.btn_data_testing.setCheckable(True) self.btn_data_testing.setAutoExclusive(True) # btn data to database self.btn_data_db = QPushButton(ui_strings.DATATOOLS_DATA_DB, self.group_run_options) self.btn_data_db.setEnabled(False) self.btn_data_db.setGeometry(QtCore.QRect(10, 179, 91, 23)) self.btn_data_db.setCheckable(True) self.btn_data_db.setAutoExclusive(True) # frame run options self.frame_run = QFrame(self.group_run_options) self.frame_run.setGeometry(QtCore.QRect(10, 30, 130, 80)) self.frame_run.setFrameShape(QFrame.StyledPanel) self.frame_run.setFrameShadow(QFrame.Raised) # option process until first error self.rbtn_process_error = QRadioButton( ui_strings.DATATOOLS_PROCESS_ERROR, self.frame_run) self.rbtn_process_error.setGeometry(QtCore.QRect(0, 0, 150, 20)) # option process all data self.rbtn_process_all = QRadioButton(ui_strings.DATATOOLS_PROCESS_ALL, self.frame_run) self.rbtn_process_all.setGeometry(QtCore.QRect(0, 20, 150, 30)) # checkbox to filter by records with errors. #self.chk_filter_errors = QCheckBox(ui_strings.DATATOOLS_FILTER_ERRORS, self.frame_run) #self.chk_filter_errors.setGeometry(QtCore.QRect(0, 50, 100, 15)) #self.chk_filter_errors.setEnabled(False) # icons -> pass - error: Initially are empty labels # if not started -> ICON_MINI_WAIT # if error -> ICON_DELETE # if pass -> ICON_CHECK # state icon data uploader self.lbl_state_du = QLabel(self.group_run_options) self.lbl_state_du.setGeometry(QtCore.QRect(110, 120, 20, 20)) self.lbl_state_du.setPixmap(QPixmap(resources.ICON_MINI_WAIT)) self.lbl_state_du.setScaledContents(True) # state icon data to database self.lbl_state_dt = QLabel(self.group_run_options) self.lbl_state_dt.setGeometry(QtCore.QRect(110, 150, 20, 20)) self.lbl_state_dt.setPixmap(QPixmap(resources.ICON_MINI_WAIT)) self.lbl_state_dt.setScaledContents(True) # state icon data testing self.lbl_state_db = QLabel(self.group_run_options) self.lbl_state_db.setGeometry(QtCore.QRect(110, 180, 20, 20)) self.lbl_state_db.setPixmap(QPixmap(resources.ICON_MINI_WAIT)) self.lbl_state_db.setScaledContents(True) # progress bar self.progress_bar = QProgressBar(self.central_widget) self.progress_bar.setGeometry( QtCore.QRect(self._left_margin, 530, 660, 15)) self.progress_bar.setMaximum(100) self.progress_bar.setProperty("value", 0) self.progress_bar.setTextVisible(True) self.progress_bar.setOrientation(QtCore.Qt.Horizontal) self.progress_bar.setInvertedAppearance(False) self.progress_bar.setTextDirection(QProgressBar.TopToBottom) self.setCentralWidget(self.central_widget)
class SentenceFillDlg(QDialog, ui_sentencefilldlg.Ui_SentenceFillDlg): def __init__(self, tableName, rangeValues, parent=None): super(SentenceFillDlg, self).__init__(parent) self.tableName = tableName self.rangeValues = rangeValues self.setupUi(self) self.initUI() def initUI(self): fontLabel = QFont('SansSerif', 14) self.setMinimumSize(1200, 600) self.resize(1200, 600) self.sentenceToFillTable = QTableWidget(5, 1, self) self.sentenceToFillTable.setGeometry(QRect(70, 60, 800, 400)) self.sentenceToFillTable.setColumnCount(1) item = QTableWidgetItem() item.setText('Sentences To Match') font = QFont() font.setBold(True) font.setWeight(75) item.setFont(font) self.sentenceToFillTable.setHorizontalHeaderItem(0, item) self.sentenceToFillTable.resizeColumnsToContents() self.sentenceToFillTable.horizontalHeader().setStretchLastSection(True) self.sentenceToFillTable.verticalHeader().setStretchLastSection(True) self.sentenceList = [] self.getSentencesFromDatabase() # split the sentences into chunks of 5 # Map to hold the anwers self.rightWordList = {} self.iteration = 0 self.sentenceMasterList = [] self.sentenceSlaveList = [] if len(self.sentenceList) > 0: for sentence in self.sentenceList: if len(self.sentenceSlaveList) < 5: self.sentenceSlaveList.append(sentence) else: self.sentenceMasterList.append(self.sentenceSlaveList) self.sentenceSlaveList = [] self.sentenceSlaveList.append(sentence) if len(self.sentenceSlaveList) <= 5: self.sentenceMasterList.append(self.sentenceSlaveList) self.maxIteration = len(self.sentenceMasterList) ## set the row height self.tableHeightSize = 0 ## Only if there is atleast one sentence fetched from the database if len(self.sentenceList) > 0: for index in range(0, 5): if len(self.sentenceList[index]) < 150: self.sentenceToFillTable.verticalHeader().resizeSection(index, 80) self.tableHeightSize = self.tableHeightSize + 90 elif len(self.sentenceList[index]) < 200: self.sentenceToFillTable.verticalHeader().resizeSection(index, 100) self.tableHeightSize = self.tableHeightSize + 100 else: self.sentenceToFillTable.verticalHeader().resizeSection(index, 120) self.tableHeightSize = self.tableHeightSize + 120 # split words from databse into chunks of 5 self.refIteration = 0 self.refWordMasterList = [] self.refWordSlaveList = [] for wordList in self.wordMap.values(): if len(self.refWordSlaveList) < 5: self.refWordSlaveList.append(wordList) else: self.refWordMasterList.append(self.refWordSlaveList) self.refWordSlaveList = [] self.refWordSlaveList.append(wordList) if len(self.refWordSlaveList) <= 5: self.refWordMasterList.append(self.refWordSlaveList) self.refMaxIteration = len(self.refWordMasterList) self.insertSentencesInTable() self.connect(self.sentenceToFillTable, SIGNAL("cellClicked(int, int)"), self.itemSelect) # create next, submit and close buttons self.nextButton = QPushButton('Next', self) self.nextButton.move(170, 520) self.nextButton.setEnabled(False) self.submitButton = QPushButton('Submit', self) self.submitButton.move(380, 520) self.closeButton = QPushButton('Close', self) self.closeButton.move(600, 520) self.connect(self.closeButton, SIGNAL('clicked()'), self.closeClicked) self.connect(self.submitButton, SIGNAL('clicked()'), self.onSubmitClicked) self.connect(self.nextButton, SIGNAL('clicked()'), self.onNextClicked) self.setWindowTitle('Sentence Fill') #self.setGeometry(10, 80, 1100, 750) def getSentencesFromDatabase(self): self.twoTypeList = data.Data().getSentencesFromDatabase(self.tableName, self.rangeValues) if len(self.twoTypeList) == 2: self.sentenceList = self.twoTypeList[0] self.wordMap = self.twoTypeList[1] def closeClicked(self): reply = QMessageBox.question(self, "Fill the Sentences", "You want to close the application", QMessageBox.Yes | QMessageBox.No) if reply == QMessageBox.Yes: self.reject() def onNextClicked(self): if not self.iteration < self.maxIteration: QMessageBox.information(self, "Fill the Sentences", "All Sentences are matched", QMessageBox.Ok) else: self.sentenceToFillTable.clearContents() ## Fetch the next records self.refIteration = self.refIteration + 1 self.rightWordList = {} ## clear the contents of the combo box self.wordListComboBox.clear() self.insertSentencesInTable() # validate whether the user has matched the blanks with a value during next and submit button clicks def onNextSubmitValidation(self): self.textNotFilled = False for row in range(0, len(self.currentSentenceListInTable)): if self.sentenceToFillTable.item(row, 0).text() == self.currentSentenceListInTable[row]: self.textNotFilled = True if self.textNotFilled: QMessageBox.information(self, "Fill the sentences", "Match all the sentences in the table", QMessageBox.Ok) self.nextButton.setEnabled(False) def onSubmitClicked(self): self.wordsMatched = True self.allWordsMatched = True brushRed = QBrush(QColor(255,0,0)) brushRed.setStyle(Qt.SolidPattern) brushGreen = QBrush(QColor(0,255,0)) brushGreen.setStyle(Qt.SolidPattern) # validate whether the user all matched the blanks with a value #self.onNextSubmitValidation() textNotFilled = False for row in range(0, len(self.currentSentenceListInTable)): if self.sentenceToFillTable.item(row, 0).text() == self.currentSentenceListInTable[row]: textNotFilled = True if textNotFilled: QMessageBox.information(self, "Fill the sentences", "Match all the sentences in the table", QMessageBox.Ok) else: splittedSentence = [] foundWordInSentence = "" self.rightWordListCopy = self.rightWordList for row in range(0, len(self.currentSentenceListInTable)): sentenceFilled = str(self.sentenceToFillTable.item(row, 0).text()) newSplittedSentence = [word.strip() for word in sentenceFilled.split()] splittedSentence = [] for word in newSplittedSentence: match = re.search(r'\w+', word) if match: splittedSentence.append(str(match.group())) wordList = self.rightWordListCopy[row] if len(wordList) > 1: firstWord = wordList[0].strip() secondWord = wordList[1].strip() if ' ' in firstWord: for word in firstWord.split(): if word not in splittedSentence: self.wordsMatched = False else: if firstWord not in splittedSentence: self.wordsMatched = False if self.wordsMatched: ## check is valid only if the first word is matched if ' ' in secondWord: for word in secondWord.split(): if word not in splittedSentence: self.wordsMatched = False else: if secondWord not in splittedSentence: self.wordsMatched = False elif len(wordList) == 1: word = wordList[0].strip() if word not in splittedSentence: self.wordsMatched = False if self.wordsMatched: self.sentenceToFillTable.item(row, 0).setBackground(brushGreen) else: self.sentenceToFillTable.item(row, 0).setBackground(brushRed) self.allWordsMatched = False self.wordsMatched = True if self.allWordsMatched: self.nextButton.setEnabled(True) QMessageBox.information(self, "Fill the sentences", "All sentences are matched", QMessageBox.Ok) def insertSentencesInTable(self): if self.iteration < self.maxIteration: cellList = [] self.col = 0 self.currentSentenceListInTable = self.sentenceMasterList[self.iteration] for sentence in self.currentSentenceListInTable: item = QTableWidgetItem(QString(sentence)) item.setFlags(Qt.ItemFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)) cellList.append(item) cellList.reverse() for index in range(0, len(self.currentSentenceListInTable)): self.sentenceToFillTable.setItem(index, self.col, cellList.pop()) self.sentenceToFillTable.setRowCount(len(self.sentenceMasterList[self.iteration])) self.sentenceToFillTable.setFixedHeight(self.tableHeightSize) # increment the count for the next button click self.iteration = self.iteration + 1 def createComboBox(self, rowIndex): self.xAxis = 1000 self.yAxis = 80 if self.refIteration < self.refMaxIteration: wordListWithFiveArrays = self.refWordMasterList[self.refIteration] requiredWordList = wordListWithFiveArrays[rowIndex] ## Create a combo box self.wordListComboBox = QComboBox(self) self.wordListComboBox.setGeometry(900, 80, 100, 20) self.connect(self.wordListComboBox, SIGNAL("currentIndexChanged(int)"), self.wordSelected) self.wordListComboBox.show() ## save the right word if len(requiredWordList) > 0: if rowIndex not in self.rightWordList.keys(): if len(requiredWordList) > 0: wordList = requiredWordList[0].split('&') self.rightWordList[rowIndex] = wordList ## insert words in the combo box random.shuffle(requiredWordList) random.shuffle(requiredWordList) self.wordListComboBox.addItem(' ') self.wordListComboBox.addItems(requiredWordList) def wordSelected(self): ## Avoid the blank option if len(str(self.wordListComboBox.currentText()).strip()) > 0: sentence = self.currentSentenceListInTable[self.selectedSentenceIndex] splittedText = sentence.split('-') if len(splittedText) == 2: item = QTableWidgetItem(QString(splittedText[0] + str(self.wordListComboBox.currentText()) + ' ' + splittedText[1].strip())) item.setFlags(Qt.ItemFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)) self.sentenceToFillTable.setItem(self.selectedSentenceIndex, 0, item) elif len(splittedText) > 2: wordsFromCombobox = str(self.wordListComboBox.currentText()).split('&') item = QTableWidgetItem(QString(splittedText[0] + wordsFromCombobox[0] + splittedText[1] + wordsFromCombobox[1] + ' ' + splittedText[2].strip())) item.setFlags(Qt.ItemFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)) self.sentenceToFillTable.setItem(self.selectedSentenceIndex, 0, item) def createIndexForWords(self): self.indexForWords = {} self.nextIndex = 0 for word in self.refWordListForIndex: if self.nextIndex == 5: break self.indexForWords[word] = self.nextIndex self.nextIndex = self.nextIndex + 1 def itemSelect(self,rowIndex): self.createComboBox(rowIndex) self.selectedSentenceIndex = rowIndex