class ItemWidget(Widget): key = "ItemWidget" def __init__(self, section, name="", parent=None): super(ItemWidget, self).__init__(parent) self.section = section self.item = Label({'txt': name}) self.setLayout( HBoxLayout({'setLayout': [self.item, Button({'txt' :"Edit", 'stt' :"Edit character name", 'cl' : self.setText})] }) ) def setText(self): text, ok = QInputDialog.getText(self, "Change To", "{0} name:".format(self.section), LineEdit.Normal, self.item.text()) if ok and text != "": self.item.setText(text)
class TaskInfo(GroupBox): key = 'TaskInfo' def __init__(self, task): super(TaskInfo, self).__init__() with open(task, 'r') as f: self._data = json.load(f) self.setTitle(self._data['id']) self.layout = VBoxLayout() self._id = self._data['id'] self.key = self._id self._name = self._data['name'] self._mode = self._data['mode'] self._type = self._data['type'] self._project = self._data['project'] self._organisation = self._data['organisation'] self._details = self._data['details'] self._hour = int(self._data['endtime'].split(':')[0]) self._minute = int(self._data['endtime'].split(':')[1]) self._second = int(self._data['endtime'].split(':')[2]) self._day = int(self._data['enddate'].split('/')[0]) self._month = int(self._data['enddate'].split('/')[1]) self._year = int(self._data['enddate'].split('/')[2]) self.duetime = duetime(self._hour, self._minute, self._second) self.duedate = duedate(self._day, self._month, self._year) self.task = Task(self._id, self._name, self._mode, self._type, self._project, self._organisation, self.duetime, self.duedate, self._details) self._countdown = '{0}:{1}:{2}'.format(self.task.hours, self.task.minutes, self.task.seconds) self.task.countdown.connect(self.update_countdown) self.task_status = Label({'txt': '{0}'.format(self.task.status)}) self.task_duedate = Label({'txt': '{0}'.format(self.task._enddate)}) self.task_duetime = Label({'txt': '{0}'.format(self.task._endtime)}) self.task_countdown = Label({'txt': '{0}'.format(self._countdown)}) self.layout.addWidget(self.task_status) self.layout.addWidget(self.task_duedate) self.layout.addWidget(self.task_duetime) self.layout.addWidget(self.task_countdown) self.setLayout(self.layout) self.setMaximumSize(100, 100) def update_countdown(self, val): if self.task.status == 'Overdued': self.task_status.setStyleSheet('color: red') elif self.task.status == 'Urgent': self.task_status.setStyleSheet('color: orange') else: self.task_status.setStyleSheet('color: green') return self.task_countdown.setText(val) @property def id(self): return self._id @property def mode(self): return self._mode @property def type(self): return self._type @property def project(self): return self._project @property def organisation(self): return self._organisation @property def hour(self): return self._hour @property def minute(self): return self._minute @property def second(self): return self._second @property def day(self): return self._day @property def month(self): return self._month @property def year(self): return self._year @id.setter def id(self, val): self._id = val @mode.setter def mode(self, val): self._mode = val @type.setter def type(self, val): self._type = val @project.setter def project(self, val): self._project = val @organisation.setter def organisation(self, val): self._organisation = val @hour.setter def hour(self, val): self._hour = val @minute.setter def minute(self, val): self._minute = val @second.setter def second(self, val): self._second = val @day.setter def day(self, val): self._day = val @month.setter def month(self, val): self._month = val @year.setter def year(self, val): self._year = val
class ForgotPassword(Widget): key = 'ForgotPassword' def __init__(self, parent=None): super(ForgotPassword, self).__init__(parent) self.layout = VBoxLayout() self.buildUI() self.setLayout(self.layout) def buildUI(self): self.step1_form = self.step1_layout() self.step2_form = self.step2_layout() self.step2_form.setVisible(False) self.layout.addWidget(self.step1_form) self.layout.addWidget(self.step2_form) def step1_layout(self): step1_groupBox = QGroupBox("Step 1") step1_layout = QFormLayout() step1_groupBox.setLayout(step1_layout) self.user_account = QLineEdit() self.user_email = QLineEdit() step1_btn_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) step1_btn_box.accepted.connect(self.on_step1_btn_clicked) step1_btn_box.rejected.connect(self.close) step1_layout.addRow(Label({'txt': "Username: "******"Email adress: "}), self.user_email) step1_layout.addRow(step1_btn_box) return step1_groupBox def step2_layout(self): step2_groupBox = GroupBox("Step 2") step2_layout = VBoxLayout() step2_groupBox.setLayout(step2_layout) self.question1 = Label({'txt': "Question 1"}) self.question2 = Label({'txt': "Question 2"}) self.answer1 = LineEdit() self.answer2 = LineEdit() step2_btn_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) step2_btn_box.accepted.connect(self.on_step2_btn_clicked) step2_btn_box.rejected.connect(self.close) step2_layout.addWidget(self.question1) step2_layout.addWidget(self.answer1) step2_layout.addWidget(self.question2) step2_layout.addWidget(self.answer2) step2_layout.addWidget(step2_btn_box) return step2_groupBox def on_step1_btn_clicked(self): question1 = "What is the question 1" question2 = "What is the question 2" self.question1.setText(question1) self.question2.setText(question2) self.step1_form.setDisabled(True) self.step2_form.setVisible(True) # username = self.user_account.text() # # if len(username) == 0: # QMessageBox.critical(self, 'Failed', mess.USER_BLANK) # else: # checkUserExists = usql.check_data_exists(username) # if not checkUserExists: # QMessageBox.critical(self, 'Failed', mess.USER_NOT_EXSIST) # question1, question2 = usql.query_user_security_question(username) # # self.question1.setText(question1) # self.question2.setText(question2) # # self.step1_form.setDisabled(True) # self.step2_form.setVisible(True) def on_step2_btn_clicked(self): pass def loginChanged(self, login): self._login = login @property def login(self): return self._login @login.setter def login(self, newVal): self._login = newVal
class ConnectStatus(GridLayout): key = 'ConnectStatus' _allowLocalMode = True _updatting = False _mode = None _server = None labels = DAMGLIST() def __init__(self, parent=None): super(ConnectStatus, self).__init__(parent) self.parent = parent self._server = self.getServer() self.serverStatus = Label({ 'wmax': 20, 'sst': 'Server Connection Status', }) self.internetStatus = Label({ 'wmax': 20, 'sst': 'Internet Connection Status', }) self.modeStatus = Label({ 'txt': self._mode, 'sst': 'Operating Mode Status' }) self.updateTimer = DAMGTIMER() self.updateTimer.setParent(self) self.updateTimer.timeout.connect(self.update_icon) self.server_status() self.internet_status() self.mode_status() self.addWidget(self.serverStatus, 0, 0, 1, 1) self.addWidget(self.internetStatus, 0, 1, 1, 1) self.addWidget(self.modeStatus, 0, 2, 1, 1) self.labels.appendList( [self.serverStatus, self.internetStatus, self.modeStatus]) if not self._updatting: self.updateTimer.stop() else: self.updateTimer.start(1000) def server_status(self): try: r = requests.get(__localServer__) except Exception: if not self._allowLocalMode: MessageBox(None, 'Connection Failed', 'critical', SERVER_CONNECT_FAIL, 'close') sys.exit() else: self.parent.signals.emit('sysNotify', 'Offline', 'Can not connect to Server', 'crit', 500) self.serverIcon = get_app_icon(16, 'Disconnected') else: if r.status_code == 200: self.serverIcon = get_app_icon(16, 'Connected') else: self.serverIcon = get_app_icon(16, 'Disconnected') self.serverStatus.setPixmap(QPixmap(self.serverIcon)) self.serverStatus.update() def internet_status(self): try: r = requests.get(__google__) except requests.ConnectionError: self.parent.signals.emit('sysNotify', 'Offline', 'Can not connect to Internet', 'crit', 500) self.internetIcon = get_app_icon(16, 'Disconnected') self.internetStatus.setToolTip('Disconnected') else: self.parent.signals.emit('sysNotify', 'Online', 'Internet connected', 'info', 500) self.internetIcon = get_app_icon(16, 'Connected') self.internetStatus.setStatusTip('Connected') self.internetStatus.setPixmap(QPixmap(self.internetIcon)) self.internetStatus.update() def mode_status(self): self.getServer() self.modeStatus.setText(self._mode) self.modeStatus.setToolTip(self._mode) self.modeStatus.update() def update_icon(self): # print('update Icon') self.internet_status() self.server_status() self.mode_status() def setMode(self, mode): self._mode = mode def getServer(self): try: r = requests.get(__globalServer__) except Exception: try: r = requests.get(__localServer__) except Exception: if not self._allowLocalMode: MessageBox(None, 'Connection Failed', 'critical', SERVER_CONNECT_FAIL, 'close') sys.exit() else: self.setMode('Offline') else: if r.status_code == 200: self._server = __localServer__ self.setMode('Local') else: self.setMode('Offline') else: if r.status_code == 200: self._server = __globalServer__ self.setMode('GLobal') else: self.setMode('Offline') return self._server @property def updatting(self): return self._updatting @property def allowOfflineMode(self): return self._allowLocalMode @property def mode(self): return self._mode @property def server(self): return self._server @server.setter def server(self, val): self._server = val @mode.setter def mode(self, val): self._mode = val @updatting.setter def updatting(self, val): self._updatting = val @allowOfflineMode.setter def allowOfflineMode(self, val): self._allowLocalMode = val # ------------------------------------------------------------------------------------------------------------- # Created by panda on 25/05/2018
class Notification(GridLayout): _currentTask = None _duedate = 'dd:MM:yy' _duetime = 'hh:mm:ss' _countdown = 'hh:mm:ss' labels = [] def __init__(self, threadManager, parent=None): super(Notification, self).__init__(parent) self.parent = parent self.threadManager = threadManager self.usage_cpu = Label({'txt': 'cpu: 0%'}) self.usage_ram = Label({'txt': 'ram: 0%'}) self.usage_gpu = Label({'txt': 'gpu: 0%'}) self.usage_disk = Label({'txt': 'dsk: 0%'}) self.timeClock = DigitalClock(self) self.dateClock = DigitalDate(self) d = self.dateClock.currentDate().day() m = self.dateClock.currentDate().month() y = self.dateClock.currentDate().year() dt = datetime.date(y, m, d) wk = dt.isocalendar()[1] self.weekNumber = Label({'txt': 'Weeknumber: {0}'.format(wk)}) worker = self.threadManager.serviceThread() worker.cpu.connect(self.update_cpu_useage) worker.ram.connect(self.update_ram_useage) worker.gpu.connect(self.update_gpu_useage) worker.disk.connect(self.update_disk_useage) worker.start() self.labels = [self.usage_cpu, self.usage_ram, self.usage_gpu, self.usage_disk, self.timeClock, self.dateClock] self.addWidget(self.usage_cpu, 0, 0, 1, 1) self.addWidget(self.usage_ram, 0, 1, 1, 1) self.addWidget(self.usage_gpu, 1, 0, 1, 1) self.addWidget(self.usage_disk, 1, 1, 1, 1) self.addWidget(self.weekNumber, 2, 0, 1, 2) self.addWidget(self.timeClock, 3, 0, 1, 1) self.addWidget(self.dateClock, 3, 1, 1, 1) def setcurrentTask(self, task): self._currentTask = task def update_cpu_useage(self, val): return self.usage_cpu.setText('cpu: {0}%'.format(val)) def update_ram_useage(self, val): return self.usage_ram.setText('ram: {0}%'.format(val)) def update_gpu_useage(self, val): return self.usage_gpu.setText('gpu: {0}%'.format(val)) def update_disk_useage(self, val): return self.usage_disk.setText('dsk: {0}%'.format(val)) def update_current_task(self, taskName): return self.task_name.setText(taskName) def update_task_duedate(self, date): return self.task_duedate.setText(date) def update_task_duetime(self, time): return self.task_duetime.setText(time) def update_countdown(self, val): return self.task_countdown.setText(val) @property def currentTask(self): return self._currentTask @property def duedate(self): return self._duedate @property def duetime(self): return self._duetime @duetime.setter def duetime(self, time): self._duetime = time @duedate.setter def duedate(self, date): self._duedate = date @currentTask.setter def currentTask(self, task): self._currentTask = task # ------------------------------------------------------------------------------------------------------------- # Created by panda on 16/11/2019 - 5:57 PM # © 2017 - 2018 DAMGteam. All rights reserved
class FindFiles(Widget): key = 'FindFiles' def __init__(self, parent=None): super(FindFiles, self).__init__(parent) self.setWindowIcon(AppIcon(32, "FindFiles")) central_widget = QWidget(self) self.layout = QGridLayout(self) central_widget.setLayout(self.layout) self.buildUI() def buildUI(self): browseButton = Button({'txt': "&Browse...", 'cl': self.browse}) findButton = Button({'txt': "&Find", 'cl': self.find}) self.fileComboBox = self.createComboBox("*") self.textComboBox = self.createComboBox() self.directoryComboBox = self.createComboBox(QDir.currentPath()) fileLabel = Label({'txt': "Named:"}) textLabel = Label({'txt': "Containing text: "}) directoryLabel = Label({'txt': "In directory: "}) self.filesFoundLabel = Label() self.createFilesTable() buttonsLayout = QHBoxLayout() buttonsLayout.addStretch() buttonsLayout.addWidget(findButton) self.layout = QGridLayout() self.layout.addWidget(fileLabel, 0, 0) self.layout.addWidget(self.fileComboBox, 0, 1, 1, 2) self.layout.addWidget(textLabel, 1, 0) self.layout.addWidget(self.textComboBox, 1, 1, 1, 2) self.layout.addWidget(directoryLabel, 2, 0) self.layout.addWidget(self.directoryComboBox, 2, 1) self.layout.addWidget(browseButton, 2, 2) self.layout.addWidget(self.filesTable, 3, 0, 1, 3) self.layout.addWidget(self.filesFoundLabel, 4, 0) self.layout.addLayout(buttonsLayout, 5, 0, 1, 3) self.setLayout(self.layout) self.resize(700, 300) def browse(self): directory = QFileDialog.getExistingDirectory(self, "Find Files", QDir.currentPath()) if directory: if self.directoryComboBox.findText(directory) == -1: self.directoryComboBox.addItem(directory) self.directoryComboBox.setCurrentIndex(self.directoryComboBox.findText(directory)) @staticmethod def updateComboBox(comboBox): if comboBox.findText(comboBox.currentText()) == -1: comboBox.addItem(comboBox.currentText()) def find(self): self.filesTable.setRowCount(0) fileName = self.fileComboBox.currentText() text = self.textComboBox.currentText() path = self.directoryComboBox.currentText() self.updateComboBox(self.fileComboBox) self.updateComboBox(self.textComboBox) self.updateComboBox(self.directoryComboBox) self.currentDir = QDir(path) if not fileName: fileName = "*" files = self.currentDir.entryList([fileName], QDir.Files | QDir.NoSymLinks) if text: files = self.findFiles(files, text) self.showFiles(files) def findFiles(self, files, text): progressDialog = QProgressDialog(self) progressDialog.setCancelButtonText("&Cancel") progressDialog.setRange(0, files.count()) progressDialog.setWindowTitle("Find Files") foundFiles = [] for i in range(files.count()): progressDialog.setValue(i) progressDialog.setLabelText("Searching file number %d of %d..." % (i, files.count())) QApplication.processEvents() if progressDialog.wasCanceled(): break inFile = QFile(self.currentDir.absoluteFilePath(files[i])) if inFile.open(QIODevice.ReadOnly): stream = QTextStream(inFile) while not stream.atEnd(): if progressDialog.wasCanceled(): break line = stream.readLine() if text in line: foundFiles.append(files[i]) break progressDialog.close() return foundFiles def showFiles(self, files): for fn in files: file = QFile(self.currentDir.absoluteFilePath(fn)) size = QFileInfo(file).size() fileNameItem = QTableWidgetItem(fn) fileNameItem.setFlags(fileNameItem.flags() ^ Qt.ItemIsEditable) sizeItem = QTableWidgetItem("%d KB" % (int((size + 1023) / 1024))) sizeItem.setTextAlignment(Qt.AlignVCenter | Qt.AlignRight) sizeItem.setFlags(sizeItem.flags() ^ Qt.ItemIsEditable) row = self.filesTable.rowCount() self.filesTable.insertRow(row) self.filesTable.setItem(row, 0, fileNameItem) self.filesTable.setItem(row, 1, sizeItem) self.filesFoundLabel.setText("%d file(s) found (Double click on a file to open it)" % len(files)) def createComboBox(self, text=""): comboBox = QComboBox() comboBox.setEditable(True) comboBox.addItem(text) comboBox.setSizePolicy(SiPoExp, SiPoPre) return comboBox def createFilesTable(self): self.filesTable = QTableWidget(0, 2) self.filesTable.setSelectionBehavior(QAbstractItemView.SelectRows) self.filesTable.setHorizontalHeaderLabels(("File Name", "Size")) self.filesTable.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch) self.filesTable.verticalHeader().hide() self.filesTable.setShowGrid(False) self.filesTable.cellActivated.connect(self.openFileOfItem) def openFileOfItem(self, row, column): item = self.filesTable.item(row, 0) QDesktopServices.openUrl(QUrl(self.currentDir.absoluteFilePath(item.text())))