class QueueItem(QWidget): def __init__(self, user_id, skill, queue_position, parent=None): QWidget.__init__(self, parent=parent) self.skill = skill self.user_id = user_id self.queue_position = queue_position self.setBackgroundColor() self.dbHandler = DatabaseHandler() self.staticData = self.dbHandler.getStaticSkillData(self.skill.skill_id) self.createLayout() if self.staticData is None: print("Queue Item Widget got a None Skill Static Data") else: # Int Values of the Characters primary and secondary Attributes, used for calculation charAttributes = self.dbHandler.getCharacterAttributes(self.user_id) charPrimaryAtt = tools.getCharPrimaryValue(charAttributes, self.staticData) charSecondaryAtt = tools.getCharSecondaryValue(charAttributes, self.staticData) self.spPerMinute = tools.spPerMinute(charPrimaryAtt, charSecondaryAtt) # Fill the Labels with Data, and update it every second for the 1st Skill in the Queue self.updateLabels() if self.queue_position == 1: self.startUpdateTimer() def createLayout(self): self.layout = QVBoxLayout() self.layout.addLayout(self.firstLine()) self.layout.addLayout(self.secondLine()) self.setLayout(self.layout) self.set_size_policy() def firstLine(self): hbox = QHBoxLayout() self.titleLabel = QLabel("x. Skill Name") self.rankLabel = QLabel("Rank x") self.levelLabel = QLabel("Level X") self.titleLabel.setFont(QFont("Arial", 8, QFont.Bold)) hbox.addWidget(self.titleLabel) hbox.addSpacing(5) hbox.addWidget(self.rankLabel) hbox.addStretch(1) hbox.addWidget(self.levelLabel) return hbox def secondLine(self): hbox = QHBoxLayout() self.spLabel = QLabel("SP: ") self.spPerHourLabel = QLabel("SP/Hour: ") self.trainingTimeLabel = QLabel("Training Time: ") self.progressLabel = QLabel(" % Done") hbox.addWidget(self.spLabel) hbox.addSpacing(5) hbox.addWidget(self.spPerHourLabel) hbox.addSpacing(5) hbox.addWidget(self.trainingTimeLabel) hbox.addStretch(1) hbox.addWidget(self.progressLabel) return hbox def updateLabels(self): #First Line ToDo: Optimize pos = str(self.queue_position) name = self.staticData.name self.titleLabel.setText(pos + ". " + name) self.rankLabel.setText("(Rank " + str(self.staticData.rank) + ")") self.levelLabel.setText("Level " + str(self.skill.finished_level)) if self.skill.finish_date is not None: self.trainingTimeLabel.setText("Training Time: " + tools.getSkillTrainingTime(self.skill)) # - # Second Line skillTrainingProgress = tools.getSkillTrainingProgress(self.skill, self.spPerMinute) # + self.spLabel.setText("SP: " + format(self.skill.level_start_sp + skillTrainingProgress) + "/" # + + format(self.skill.level_end_sp)) self.spPerHourLabel.setText("SP/Hour: " + str(int(60*self.spPerMinute))) # - self.progressLabel.setText(str(round(skillTrainingProgress / (self.skill.level_end_sp - self.skill.level_start_sp) * 100, 1)) + " % Done") # + self.layout.update() def setBackgroundColor(self): self.setAutoFillBackground(True) # Background Color pal = QPalette() mod = self.skill.queue_position % 2 if mod == 0: pal.setColor(self.backgroundRole(), QtCore.Qt.lightGray) else: pal.setColor(self.backgroundRole(), QtCore.Qt.white) self.setPalette(pal) def set_size_policy(self): self.layout.setContentsMargins(1, 1, 1, 1) self.layout.setSpacing(1) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum) def startUpdateTimer(self): self.timer = QtCore.QTimer() self.timer.timeout.connect(self.updateLabels) self.timer.setSingleShot(False) self.timer.start(1000)
class KnownSkillsItem(QWidget): def __init__(self, user_id, skill, position, parent=None): QWidget.__init__(self, parent=parent) self.skill = skill self.position = position self.user_id = user_id self.dbHandler = DatabaseHandler() self.staticData = self.dbHandler.getStaticSkillData( self.skill.skill_id) self.skillQueueItem = None # ToDo: If this skill is in this User's skillQueue activate updateTimer and update labels self.setBackgroundColor() self.createLayout() self.checkSkillQueue() if self.staticData is None: print("Completed Skill Item Widget got a None Skill Static Data") else: # Int Values of the Characters primary and secondary Attributes, used for calculation charAttributes = self.dbHandler.getCharacterAttributes( self.user_id) charPrimaryAtt = tools.getCharPrimaryValue(charAttributes, self.staticData) charSecondaryAtt = tools.getCharSecondaryValue( charAttributes, self.staticData) self.spPerMinute = tools.spPerMinute(charPrimaryAtt, charSecondaryAtt) # Fill the Labels with Data, and update it every second for the 1st Skill in the Queue self.updateLabels() def createLayout(self): self.layout = QVBoxLayout() self.layout.addLayout(self.firstLine()) self.layout.addLayout(self.secondLine()) self.setLayout(self.layout) self.set_size_policy() def firstLine(self): hbox = QHBoxLayout() self.titleLabel = QLabel("x. Skill Name") self.rankLabel = QLabel("Rank x") self.levelLabel = QLabel("Level X") self.titleLabel.setFont(QFont("Arial", 8, QFont.Bold)) hbox.addWidget(self.titleLabel) hbox.addSpacing(5) hbox.addWidget(self.rankLabel) hbox.addStretch(1) hbox.addWidget(self.levelLabel) return hbox def secondLine(self): hbox = QHBoxLayout() self.spLabel = QLabel("SP: ") self.progressLabel = QLabel(" % Done") hbox.addWidget(self.spLabel) hbox.addStretch(1) hbox.addWidget(self.progressLabel) return hbox def updateLabels(self): #First Line ToDo: Optimize #pos = str(self.queue_position) name = self.staticData.name self.titleLabel.setText(name) self.rankLabel.setText("(Rank " + str(self.staticData.rank) + ")") self.levelLabel.setText("Level " + str(self.skill.trained_skill_level)) # Second Line if self.skill.trained_skill_level == 5: modifier = 4 else: modifier = self.skill.trained_skill_level # Eve training multiplier formula: SP = 250 * multiplier * sqrt(32)^(level-1) skill_level_end_sp = 250 * self.staticData.rank * math.sqrt( 32)**modifier if self.skillQueueItem is None: skillTrainingProgress = 0 else: skillTrainingProgress = tools.getSkillTrainingProgress( self.skillQueueItem, self.spPerMinute) self.spLabel.setText("SP: " + format(self.skill.skillpoints_in_skill + skillTrainingProgress) + "/" + format(round(skill_level_end_sp))) self.progressLabel.setText( str( round( skillTrainingProgress / (skill_level_end_sp - self.skill.skillpoints_in_skill) * 100, 1)) + " % Done") # + self.layout.update() def checkSkillQueue(self): # ToDO: Might need improvement check if skill is already completed # we want to know if this skill is in this users skill queue self.skillQueueItem = dbHandler.getSkillQueueItem( self.user_id, self.skill.skill_id) if self.skillQueueItem is not None: self.startUpdateTimer() def setBackgroundColor(self): self.setAutoFillBackground(True) # Background Color pal = QPalette() mod = self.position % 2 if mod == 0: pal.setColor(self.backgroundRole(), QtCore.Qt.lightGray) else: pal.setColor(self.backgroundRole(), QtCore.Qt.white) self.setPalette(pal) def set_size_policy(self): self.layout.setContentsMargins(1, 1, 1, 1) self.layout.setSpacing(1) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum) def startUpdateTimer(self): self.timer = QtCore.QTimer() self.timer.timeout.connect(self.updateLabels) self.timer.setSingleShot(False) self.timer.start(1000)
class CharacterTabWidget(QWidget): def __init__(self, user, parent=None): super(CharacterTabWidget, self).__init__(parent) self.parent = parent self.user = user self.dbHandler = DatabaseHandler() try: self.character = self.dbHandler.getCharacter(user.get_id()) self.attributes = self.dbHandler.getCharacterAttributes(user.get_id()) except Exception as e: print("Exception in CharacterTab: " + str(e)) if self.character is None: print("Character Tab has a None Character") else: self.layout = self.createLayout() self.layout.setSpacing(0) self.setLayout(self.layout) self.startUpdateTimer() def getUser(self): # returns the user_id for this character_tab return self.user.id def startUpdateTimer(self): self.timer = QtCore.QTimer() self.timer.timeout.connect(self.updateLabels) self.timer.setSingleShot(False) self.timer.start(1000) def updateLabels(self): self.layout.update() def createLayout(self): vBox = QVBoxLayout() vBox.addLayout(self.horizontalTop()) vBox.addSpacing(5) vBox.addLayout(self.horizontalMiddle()) self.functionTab = FunctionTabWidget(self.user) vBox.addWidget(self.functionTab) #vBox.addStretch(1) return vBox def horizontalTop(self): # Character Image characterImage = QLabel() pixmap = QPixmap(self.getCharacterPortrait()) if pixmap is None: pixmap = QPixmap('portrait.png') characterImage.setPixmap(pixmap.scaled(150, 150)) characterImage.resize(150, 150) hBox = QHBoxLayout() hBox.setAlignment(QtCore.Qt.AlignTop) hBox.addWidget(characterImage) hBox.addSpacing(5) # Character General Information vBox = QVBoxLayout() #vBox.setAlignment(QtCore.Qt.AlignLeft) vBox.setAlignment(QtCore.Qt.AlignTop) vBox.setSpacing(0) vBox.setContentsMargins(0,0,0,0) nameLabel = QLabel(self.character.name) nameLabel.setFont(QFont("Arial", 14, QFont.Bold)) balanceLabel = QLabel("Balance: " + format(self.character.balance) + " ISK") corpLabel = QLabel("Corporation: ") allyLabel = QLabel("Alliance: ") secLabel = QLabel("Security Status: " + str(round(self.character.security_status, 2))) fatigueLabel = QLabel("Jump Fatigue: ") shipLabel = QLabel("Active Ship: ") locationLabel = QLabel("Located in: ") dockedLabel = QLabel("Docked at: ") vBox.addWidget(nameLabel) vBox.addWidget(balanceLabel) vBox.addWidget(corpLabel) vBox.addWidget(allyLabel) vBox.addWidget(secLabel) vBox.addWidget(fatigueLabel) vBox.addWidget(shipLabel) vBox.addWidget(locationLabel) vBox.addWidget(dockedLabel) #vBox.addStretch(1) hBox.addLayout(vBox) hBox.addStretch(1) #ToDo: Update Timer + Force update button (When will the next update occur) return hBox def horizontalMiddle(self): # Account Subscription Status vBox1 = QVBoxLayout() vBox1.setAlignment(QtCore.Qt.AlignTop) subscriptionStatusLabel = QLabel("Account Status: " + "Unknown") #subsriptionTimeLabel = QLabel("Remaining Time") subscriptionStatusLabel.setFixedWidth(155) # To indent the Middle hBox. size: pixmap + spacing vBox1.addWidget(subscriptionStatusLabel) #vBox1.addWidget(subsriptionTimeLabel) #vBox1.addStretch(1) # Character Stats vBox2 = QVBoxLayout() vBox2.setAlignment(QtCore.Qt.AlignTop) intelligenceLabel = QLabel("Intelligence: " + offset(8) + str(self.attributes.intelligence)) # 12 perceptionLabel = QLabel("Perception: " + offset(9) + str(self.attributes.perception)) # 10 charismaLabel = QLabel("Charisma: " + offset(11) + str(self.attributes.charisma)) # 8 willpowerLabel = QLabel("Willpower: " + offset(11) + str(self.attributes.willpower)) # 9 memoryLabel = QLabel("Memory: " + offset(13) + str(self.attributes.memory)) # 6 intelligenceLabel.setFixedWidth(120) vBox2.addWidget(intelligenceLabel) vBox2.addWidget(perceptionLabel) vBox2.addWidget(charismaLabel) vBox2.addWidget(willpowerLabel) vBox2.addWidget(memoryLabel) #vBox2.addStretch(1) #Clone Jump Status vBox3 = QVBoxLayout() vBox3.setAlignment(QtCore.Qt.AlignTop) bonusRemapLabel = QLabel("Bonus Remap: " + str(self.attributes.bonus_remaps)) neuralRemapLabel = QLabel("Next Neural Remap: " + remapTime(self.attributes.accrued_remap_cooldown_date)) cloneJumpLabel = QLabel("Next Clone Jump: ") vBox3.addWidget(bonusRemapLabel) vBox3.addWidget(neuralRemapLabel) vBox3.addWidget(cloneJumpLabel) #vBox3.addStretch(1) # Skills Statistics vBox4 = QVBoxLayout() vBox4.setAlignment(QtCore.Qt.AlignTop) # ToDo: Include the completed Skills in SkillQueue knownSkillsLabel = QLabel("Known Skills: " + str(self.dbHandler.getKnownSkillsCount(self.user))) skillsAt5Label = QLabel("Skills at Level V: " + str(self.dbHandler.getSkillsAtV(self.user))) totalSPLabel = QLabel("Total SP: " + format(self.character.total_sp)) if self.character.unallocated_sp is None: tmp = 0 else: tmp = self.character.unallocated_sp unallocatedSP = QLabel("Unallocated SP: " + format(tmp)) vBox4.addWidget(knownSkillsLabel) vBox4.addWidget(skillsAt5Label) vBox4.addWidget(totalSPLabel) vBox4.addWidget(unallocatedSP) #vBox4.addStretch(1) # Complete horizontal Middle hBox = QHBoxLayout() hBox.addLayout(vBox1) hBox.addLayout(vBox2) hBox.addSpacing(20) hBox.addLayout(vBox3) hBox.addStretch(1) hBox.addLayout(vBox4) return hBox def getCharacterPortrait(self): # Gets url to the character Portrait from db and sets the shown image to it # ToDo: Needs to be changed, so that the image is be save on the harddrive pixmap = QPixmap() try: portraitUrl = self.dbHandler.getCharacterPortrait(self.user.get_id()) if portraitUrl is not None: data = request.urlopen(portraitUrl.px256x256).read() pixmap.loadFromData(data) else: print("No portrait URL for " + self.user.CharacterName + " in the Database") except Exception as e: print("Exception in CharacterTabWidget.getCharacterPortrait: " + str(e)) return pixmap