#!/usr/bin/python
#-*-coding:utf-8-*-
from push_button import *
from clabel import *
from common import *
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.Qt import *
class CharacterWidget(QWidget):
def __init__(self,parent = None):
super(CharacterWidget,self).__init__()
self.mouse_press = False
self.mouse_move = False
self.current_index = 0 #当前图片下标
self.current_pos_x = 0
#self.name_list = QStringList()
self.m_mouseSrcPos = QPoint()
self.m_mouseDstPos = QPoint()
self.label_move = False
self.label_array = [CLabel(),CLabel(),CLabel(),CLabel()] #存储图片的数组
self.resize(QSize(WINDOW_WIDTH, WINDOW_HEIGHT))
self.setWindowFlags(Qt.FramelessWindowHint)
self.background_label = QLabel(self) #背景图片
self.background_label.setPixmap(QPixmap("./img/Character/bg_bottom.png"))
self.background_label.setGeometry(QRect(0, 0, self.width(), self.height()))
#将4张图片合成一张
self.pixmap = QPixmap(QSize(self.width()*WINDOW_PAGE_COUNT, WINDOW_HEIGHT)) #
painter = QPainter(self.pixmap)
for i in range(WINDOW_PAGE_COUNT):
painter.drawImage(QRect(WINDOW_WIDTH*i, 0, WINDOW_WIDTH, WINDOW_HEIGHT),\
QImage(QString("./img/Character/desktop_%1").arg(i)))
self.total_label = QLabel(self) #图片(结合体)
self.total_label.resize(self.pixmap.size())
self.total_label.setPixmap(self.pixmap)
self.total_label.move(WINDOW_START_X, WINDOW_START_Y)
self.close_button = PushButton(self) #关闭按钮
self.translateLanguage()
for i in range(WINDOW_BUTTON_COUNT):
self.label = CLabel(self)
self.label.resize(QSize(155, 45))
self.label.setPixmap(QPixmap(QString("./img/Character/btn_%1").arg(i)))
self.label.setText(self.name_list[i])
self.label.move(8+i*170, 319)
self.connect(self.label, SIGNAL("clicked()"), self, SLOT("changeCurrentPage(CLabel())"))
self.label_array[i] = self.label
self.label_array[0].setMousePressFlag(False)
self.close_button.loadPixmap("./img/sysButton/close.png")
self.close_button.move(self.width()-52, 0)
self.connect(self.close_button, SIGNAL("clicked()"), self, SLOT("close()"))
def translateLanguage(self):
self.name_list= [u"function",u"clear cookie",u"triggerman",u"booster"]
self.close_button.setToolTip(u"close")
def mousePressEvent(self,event):
if(event.button() == Qt.LeftButton):
self.m_mouseSrcPos = event.pos()
if(self.m_mouseSrcPos.y() self.mouse_move = True
else:
self.current_pos_x = self.total_label.x()
self.mouse_press = True
elif(event.button() == Qt.RightButton):
if(self.label_move):
if(self.current_index > 0):
self.current_index = self.current_index-1
self.moveCurrentPage(False) #右移
def mouseReleaseEvent(self,event):
self.xpos = 0
if (self.mouse_press):
if (self.label_move):
self.m_mouseDstPos = event.pos()
self.xpos = self.m_mouseDstPos.x() - self.m_mouseSrcPos.x()
if(self.xpos > 0):#右移
if(self.xpos >= WINDOW_ONEBUTTON_WIDTH):
if(self.current_index > 0):
self.current_index = self.current_index-1
self.moveCurrentPage(False) #右移
else:
self.moveCurrentPage(True) #左移
else:
self.moveCurrentPage(True) #左移
else: #左移
if(self.xpos if(self.current_index self.current_index = self.current_index+1
self.moveCurrentPage(True) #左移
else:
self.moveCurrentPage(False) #右移
else:
self.moveCurrentPage(False) #右移
self.mouse_press = False
elif(self.mouse_move):
self.mouse_move = False
def changeCurrentPage(label):
for i in range(WINDOW_BUTTON_COUNT):
if(label != self.label_array[i]):
self.label_array[i].setMousePressFlag(False)
#获取点击的图标下标
index = 0
for i in range(WINDOW_PAGE_COUNT):
if(label == self.label_array[i]):
index = i
return
#若下标小于当前下标右移,否则左移
if(index while(index != self.current_index):
self.current_index = self.current_index-1
self.moveCurrentPage(False)
elif(index > self.current_index):
while(index != self.current_index):
self.current_index = self.current_index+1
self.moveCurrentPage(True)
def mouseMoveEvent(self,event):
x = 10
if(self.mouse_press):
if(self.label_move):
self.m_mouseDstPos = event.pos()
x = self.m_mouseDstPos.x() - self.m_mouseSrcPos.x()
self.setLabelMove(False)
self.total_label.move(self.current_pos_x + x, WINDOW_START_Y)
self.setLabelMove(True)
elif(self.mouse_move):
self.m_mouseDstPos = event.pos()
self.move(event.pos() + self.m_mouseDstPos - self.m_mouseSrcPos) #注意debug
def keyPressEvent(self, e):
if(self.label_move):
if e.key() == Qt.Key_Left | e.key() == Qt.Key_Up:
if(self.current_index > 0):
self.current_index = self.current_index-1
self.moveCurrentPage(False) #右移
elif e.key() == Qt.Key_Down | e.key() == Qt.Key_Right:
if(self.current_index self.current_index = self.current_index + 1
self.moveCurrentPage(True) #左移
def moveCurrentPage(self,direction):
#改变当前页面对应的按钮
self.changeCurrentButton()
#图片的几个分割点
#0-680, 680-1360, 1360-2040, 2040-2720
#真:向左移 假:向右移
#左移的几种可能性,对于x坐标
#index=0, 将label移动到-680*0
#index=1, 将label移动到-680*1
#index=2, 将label移动到-680*2
#index=3, 将label移动到-680*3
self.setLabelMove(False)
self.current_pos_x = self.total_label.x() #当前label坐标
self.dest_pos_x = -WINDOW_WIDTH * self.current_index #目标X坐标
if(direction):
if(self.current_pos_x > self.dest_pos_x):
self.total_label.move(self.current_pos_x-WINDOW_PAGE_MOVE, WINDOW_START_Y)
self.current_pos_x = self.total_label.x()
qApp.processEvents(QEventLoop.AllEvents)
else:
if(self.current_pos_x
self.total_label.move(self.current_pos_x+WINDOW_PAGE_MOVE, WINDOW_START_Y)
self.current_pos_x = self.total_label.x()
qApp.processEvents(QEventLoop.AllEvents)
self.total_label.move(self.dest_pos_x, WINDOW_START_Y)
self.setLabelMove(True)
def changeCurrentButton(self):
for i in range(WINDOW_BUTTON_COUNT):
if(i != self.current_index):
self.label_array[i].setMousePressFlag(False)
else:
self.label_array[i].setMousePressFlag(True)
def setLabelMove(self,enable):
self.label_move = enable
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
Character = CharacterWidget()
Character.show()
sys.exit(app.exec_())

TomergelistsinPython,youcanusethe operator,extendmethod,listcomprehension,oritertools.chain,eachwithspecificadvantages:1)The operatorissimplebutlessefficientforlargelists;2)extendismemory-efficientbutmodifiestheoriginallist;3)listcomprehensionoffersf

In Python 3, two lists can be connected through a variety of methods: 1) Use operator, which is suitable for small lists, but is inefficient for large lists; 2) Use extend method, which is suitable for large lists, with high memory efficiency, but will modify the original list; 3) Use * operator, which is suitable for merging multiple lists, without modifying the original list; 4) Use itertools.chain, which is suitable for large data sets, with high memory efficiency.

Using the join() method is the most efficient way to connect strings from lists in Python. 1) Use the join() method to be efficient and easy to read. 2) The cycle uses operators inefficiently for large lists. 3) The combination of list comprehension and join() is suitable for scenarios that require conversion. 4) The reduce() method is suitable for other types of reductions, but is inefficient for string concatenation. The complete sentence ends.

PythonexecutionistheprocessoftransformingPythoncodeintoexecutableinstructions.1)Theinterpreterreadsthecode,convertingitintobytecode,whichthePythonVirtualMachine(PVM)executes.2)TheGlobalInterpreterLock(GIL)managesthreadexecution,potentiallylimitingmul

Key features of Python include: 1. The syntax is concise and easy to understand, suitable for beginners; 2. Dynamic type system, improving development speed; 3. Rich standard library, supporting multiple tasks; 4. Strong community and ecosystem, providing extensive support; 5. Interpretation, suitable for scripting and rapid prototyping; 6. Multi-paradigm support, suitable for various programming styles.

Python is an interpreted language, but it also includes the compilation process. 1) Python code is first compiled into bytecode. 2) Bytecode is interpreted and executed by Python virtual machine. 3) This hybrid mechanism makes Python both flexible and efficient, but not as fast as a fully compiled language.

Useaforloopwheniteratingoverasequenceorforaspecificnumberoftimes;useawhileloopwhencontinuinguntilaconditionismet.Forloopsareidealforknownsequences,whilewhileloopssuitsituationswithundeterminediterations.

Pythonloopscanleadtoerrorslikeinfiniteloops,modifyinglistsduringiteration,off-by-oneerrors,zero-indexingissues,andnestedloopinefficiencies.Toavoidthese:1)Use'i


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
