class MainWindow(QtGui.QMainWindow): def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.ui = Ui_main_window() self.ui.setupUi(self) self.ui.btnCheckin.clicked.connect(self.open_checkin) self.ui.btnCheckout.clicked.connect(self.open_checkout) self.checkin_window = self self.checkout_window = self self.felica_walker = FelicaWalker() style_prop_title_bar = settings.app['style']['title_bar'] style_prop_ok_button = settings.app['style']['ok_button'] self.ui.lblTitle.setStyleSheet("QLabel { " + style_prop_title_bar + " }") self.ui.btnCheckin.setStyleSheet("QPushButton { " + style_prop_ok_button + " }") self.ui.btnCheckout.setStyleSheet("QPushButton { " + style_prop_ok_button + " }") self.center() def center(self): frameGm = self.frameGeometry() screen = QtGui.QApplication.desktop().screenNumber( QtGui.QApplication.desktop().cursor().pos()) centerPoint = QtGui.QApplication.desktop().screenGeometry( screen).center() frameGm.moveCenter(centerPoint) self.move(frameGm.topLeft()) def goodShow(self): screen = QtGui.QApplication.desktop().screenNumber( QtGui.QApplication.desktop().cursor().pos()) brp = QtGui.QApplication.desktop().screenGeometry(screen).bottomRight() if brp.x() == (800 - 1) and brp.y() == (480 - 1): # for raspberry-pi 7inch touch-screen self.showFullScreen() else: self.show() def open_checkin(self): self.checkin_window = checkin_window.CheckinWindow() self.checkin_window.goodShow() def open_checkout(self): self.checkout_window = checkout_window.CheckoutWindow() self.checkout_window.walker.start() self.checkout_window.goodShow() def check_devices(self): try: clf = nfc.ContactlessFrontend('usb') clf.close() except IOError: logger.warn("Not find felica device (USB)") self.ui.lblStatus.setStyleSheet( "QLabel { background-color : red; color : blue; }") self.ui.lblStatus.setText(_fromUtf8("IDカードリーダーが見つかりません。"))
def __init__(self, app): QMainWindow.__init__(self) self.app = app self.ui = Ui_main_window() self.ui.setupUi(self) self.login_dialog = login_dialog() QtCore.QObject.connect(self.ui.actionLogin, QtCore.SIGNAL("triggered()"), self.login_action) QtCore.QObject.connect(self.ui.actionLogout, QtCore.SIGNAL("triggered()"), self.logout_action) QtCore.QObject.connect(self.ui.actionAbout, QtCore.SIGNAL("triggered()"), self.about_action) QtCore.QObject.connect(self.ui.table_assignments, QtCore.SIGNAL("cellDoubleClicked(int,int)"), self.assignment_chosen) QtCore.QObject.connect(self.ui.button_download, QtCore.SIGNAL("clicked()"), self.download_button_pressed) QtCore.QObject.connect(self.ui.button_submit, QtCore.SIGNAL("clicked()"), self.submit_button_pressed) QtCore.QObject.connect(self.ui.button_delete, QtCore.SIGNAL("clicked()"), self.delete_button_pressed) sb = QLabel() self.sb_perm = sb self.ui.statusbar.addPermanentWidget(sb) for i in range(1, self.ui.tabw_main.count()): self.ui.tabw_main.setTabEnabled(i, False) self.enter_step(0)
def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.ui = Ui_main_window() self.ui.setupUi(self) self.ui.btnCheckin.clicked.connect(self.open_checkin) self.ui.btnCheckout.clicked.connect(self.open_checkout) self.checkin_window = self self.checkout_window = self self.felica_walker = FelicaWalker() style_prop_title_bar = settings.app['style']['title_bar'] style_prop_ok_button = settings.app['style']['ok_button'] self.ui.lblTitle.setStyleSheet("QLabel { " + style_prop_title_bar + " }") self.ui.btnCheckin.setStyleSheet("QPushButton { " + style_prop_ok_button + " }") self.ui.btnCheckout.setStyleSheet("QPushButton { " + style_prop_ok_button + " }") self.center()
class main_window(QMainWindow): def __init__(self, app): QMainWindow.__init__(self) self.app = app self.ui = Ui_main_window() self.ui.setupUi(self) self.login_dialog = login_dialog() QtCore.QObject.connect(self.ui.actionLogin, QtCore.SIGNAL("triggered()"), self.login_action) QtCore.QObject.connect(self.ui.actionLogout, QtCore.SIGNAL("triggered()"), self.logout_action) QtCore.QObject.connect(self.ui.actionAbout, QtCore.SIGNAL("triggered()"), self.about_action) QtCore.QObject.connect(self.ui.table_assignments, QtCore.SIGNAL("cellDoubleClicked(int,int)"), self.assignment_chosen) QtCore.QObject.connect(self.ui.button_download, QtCore.SIGNAL("clicked()"), self.download_button_pressed) QtCore.QObject.connect(self.ui.button_submit, QtCore.SIGNAL("clicked()"), self.submit_button_pressed) QtCore.QObject.connect(self.ui.button_delete, QtCore.SIGNAL("clicked()"), self.delete_button_pressed) sb = QLabel() self.sb_perm = sb self.ui.statusbar.addPermanentWidget(sb) for i in range(1, self.ui.tabw_main.count()): self.ui.tabw_main.setTabEnabled(i, False) self.enter_step(0) def enable_tabs(self, tab): for i in range(tab + 1): self.ui.tabw_main.setTabEnabled(i, True) for i in range(tab + 1, self.ui.tabw_main.count()): self.ui.tabw_main.setTabEnabled(i, False) def enter_step(self, step): if 0 == step: self.enable_tabs(0) self.ui.actionLogin.setEnabled(True) self.ui.actionLogout.setEnabled(False) self.sb_perm.setText("Please log in.") self.assignment_list = None self.init_table_assignments() elif 1 == step: self.enable_tabs(1) self.ui.actionLogin.setEnabled(False) self.ui.actionLogout.setEnabled(True) self.init_text_details() elif 2 == step: self.enable_tabs(3) else: pass def login_action(self): opts = self.input_login_opts() if opts is None: return self.setEnabled(False) self.sb_perm.setText("Logging in ...") self.app.processEvents() server = pyhw.server.Server(opts["server"]) service = pyhw.service.Service(server) self.service = service try: r = service.login(opts["login"], opts["password"]) self.sb_perm.setText("Welcome, " + opts["login"]) self.enter_step(1) self.ui.tabw_main.setCurrentIndex(1) except Exception as e: self.exception_sb(e) finally: self.setEnabled(True) self.list_assignments() def logout_action(self): self.setEnabled(False) self.sb_perm.setText("Logging out ...") self.app.processEvents() self.service.logout() self.service = None self.enter_step(0) self.setEnabled(True) def list_assignments(self): try: r = self.service.get_assignment_list() except Exception as e: return self.exception_sb(e) self.ui.table_assignments.setRowCount(len(r)) self.assignment_list = r for i in range(len(r)): item = QTableWidgetItem(r[i][1]) item.setFlags(item.flags() & ~ QtCore.Qt.ItemIsEditable) self.ui.table_assignments.setItem(i, 0, item) item = QTableWidgetItem(r[i][2]) item.setFlags(item.flags() & ~ QtCore.Qt.ItemIsEditable) self.ui.table_assignments.setItem(i, 1, item) def assignment_chosen(self, row, col): name = self.assignment_list[row][0] self.setEnabled(False) self.enter_step(1) self.sb_perm.setText("Retrieving details ...") self.app.processEvents() try: r = self.service.get_assignment_details(name) self.sb_perm.setText(self.assignment_list[row][1]) self.ui.text_details.setPlainText(r["description"]) self.enter_step(2) self.ui.tabw_main.setCurrentIndex(2) self.row_chosen = row self.update_submission_status() except Exception as e: self.exception_sb(e) self.setEnabled(True) def exception_sb(self, e): ex = pyhw.exceptions sb = self.sb_perm if isinstance(e, ex.NetworkError): sb.setText("Network error.") elif isinstance(e, ex.UnauthorizedError): sb.setText("Login failed.") else: print(type(e)) print(e) sb.setText("BUG! REPORT THIS ISSUE PLEASE.") def input_login_opts(self): dialog = self.login_dialog dc = dialog.exec_() if dialog.Accepted == dc: server = str(dialog.ui.server_edit.text()) login = str(dialog.ui.login_edit.text()) password = str(dialog.ui.password_edit.text()) return {"server": server, "login": login, "password": password} else: return None def init_table_assignments(self): self.ui.table_assignments.clear() self.ui.table_assignments.setColumnCount(2) self.ui.table_assignments.setHorizontalHeaderItem(0, QTableWidgetItem("Assignment")) self.ui.table_assignments.setHorizontalHeaderItem(1, QTableWidgetItem("Deadline")) def init_text_details(self): self.ui.text_details.clear() def update_submission_status(self): try: status = self.service.get_submission_status(self.assignment_list[self.row_chosen][0]) self.submission_status = status s = "filename: " + status["filename"] + "\n" + "size: " + str(status["size"]) + " Bytes\n" + "Uploading time: " + status["ctime"] + "\n" self.ui.button_delete.setEnabled(True) self.ui.button_download.setEnabled(True) except pyhw.exceptions.NotFoundError: s = "You have not uploaded yet." self.ui.button_delete.setEnabled(False) self.ui.button_download.setEnabled(False) self.ui.text_submission.setPlainText(s) def download_button_pressed(self): save_filename=QFileDialog.getSaveFileName(self, "Save File", self.submission_status["filename"]) if sys.version_info >= (3, 0): save_filename = str(save_filename) else: save_filename = unicode(save_filename) if len(save_filename)==0: return try: fout = open(save_filename, "wb") except IOError: self.ui.sb_perm.setText("Unable to open file for saving.") return self.sb_perm.setText("Start downloading ...") self.setEnabled(False) self.app.processEvents() try: fin = self.service.download_submission(self.assignment_list[self.row_chosen][0]) fout.write(fin.read()) fin.close() fout.close() self.sb_perm.setText("Download succeeded.") except Exception as e: self.exception_sb(e) self.setEnabled(True) def submit_button_pressed(self): open_filename=QFileDialog.getOpenFileName(self, "Open File") if sys.version_info >= (3, 0): open_filename = str(open_filename) else: open_filename = unicode(open_filename) if len(open_filename)==0: return try: fin = open(open_filename, "rb") except IOError: self.ui.sb_perm.setText("Unable to open file for reading.") return self.sb_perm.setText("Start uploading ...") self.setEnabled(False) self.app.processEvents() try: self.service.submit_file(self.assignment_list[self.row_chosen][0], fin) fin.close() self.update_submission_status() self.sb_perm.setText("Uploading succeeded.") except Exception as e: self.exception_sb(e) self.setEnabled(True) def delete_button_pressed(self): reply = QMessageBox.question(self, "Confirm to delete", "Are you sure to delete submission of " + self.assignment_list[self.row_chosen][1] + "?", QMessageBox.Yes | QMessageBox.No) if reply != QMessageBox.Yes: return self.setEnabled(False) self.app.processEvents() try: self.service.delete_submission(self.assignment_list[self.row_chosen][0]) self.update_submission_status() self.sb_perm.setText("Deleted.") except Exception as e: self.exception_sb(e) self.setEnabled(True) def about_action(self): dialog = QMessageBox.about(self, "About", """ Client of PHPHW API. Copyright (C) 2015 Lv Zheng <*****@*****.**> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """)