Home Backend Development Python Tutorial python实现360的字符显示界面

python实现360的字符显示界面

Jun 16, 2016 am 08:45 AM
360

复制代码 代码如下:

#!/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_())

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What folder is 360safe? What folder is 360safe? Feb 28, 2023 pm 01:56 PM

360safe is the installation folder of 360 Security Guard, which contains the relevant cache files of 360 Security Guard. Deleting the contents in 360safe may affect the normal operation of 360 Security Guard; and 360safe cannot be moved to other disks because 360 ​​Security Guard is installed version has been registered in the registry. Moving it to another disk will result in the inability to start 360. You can only uninstall it and then reselect the path to install it to another disk.

What to do if 360 folder access is denied What to do if 360 folder access is denied Apr 28, 2023 pm 04:41 PM

Solution to 360 folder access denied: 1. Check the permissions of the 360 ​​folder, check the attribute settings, and set it to readable; 2. Check every file in the 360 ​​folder to ensure there is no damage; 3. Check the 360 ​​folder Allow access permissions for each file; 4. Reauthorize the 360 ​​folder and set it to be accessible.

Is Master Lu from 360? Is Master Lu from 360? Sep 06, 2022 pm 03:14 PM

Master Lu is from 360. "Master Lu" is a hardware-level professional tool software. On September 6, 2010, "Master Lu" announced that it would join 360's "Free Software Takeoff Plan" and became another new member accepted since the launch of the plan, that is, it became a product of 360 .

How to turn off 360 computer lock screen wallpaper How to turn off 360 computer lock screen wallpaper Dec 01, 2022 am 10:26 AM

How to turn off the 360 ​​computer lock screen wallpaper: 1. Open the 360 ​​browser, click the three horizontal icons in the upper right corner, and then click "Settings"; 2. Find and click the "Laboratory" category on the settings page, and then uncheck the pictorial function. You can turn off the computer lock screen wallpaper.

How to recover 360 quarantined files How to recover 360 quarantined files Dec 01, 2022 am 10:32 AM

How to recover 360 quarantined files: 1. Open 360 Security Guard and click "Trojan Detection"; 2. Click "Recovery Area" in the lower left corner of the Trojan Detection page to open; 3. On the recovery area page, check the files to be recovered. And click "Restore"; 4. Click Restore and confirm the recovery window.

What is the difference between 360 Antivirus and 360 Guard? What is the difference between 360 Antivirus and 360 Guard? Nov 10, 2022 pm 04:40 PM

Differences: 1. The main functions are different. 360 Security Guard focuses on killing Trojans, ensuring the user’s computer account, and cleaning up garbage and optimizing acceleration; while 360 ​​Anti-Virus software is for anti-virus. 2. 360 Security Guard has complete self-protection capabilities, but 360 Antivirus software does not. It needs to rely on the self-protection function of 360 Security Guard. 3. 360 Security Guard uses its own engine, while 360 ​​Antivirus software has its own engine and two from other countries (Bitdefender and Avira).

How to remove 360 ​​interception How to remove 360 ​​interception Dec 01, 2022 am 10:18 AM

How to remove 360 ​​interception: 1. Open 360 Security Guard and click [Security Protection Center]; 2. Click the [Enter Protection] button; 3. Click [Trust and Block]; 4. Switch to [Blocked Area]; 5. Click the [Remove] button; 6. Click the [Confirm] button to remove.

What is the reason why 360wifi cannot connect? What is the reason why 360wifi cannot connect? Apr 26, 2023 pm 02:22 PM

Reasons and solutions for 360wifi failure to connect: 1. Caused by loose network lines, connection errors or damage, you need to check the broadband connection line; 2. Caused by network card failure, you need to restart the network card; 3. Caused by incorrect network card settings , you need to check the MODEM settings and restore them to the default settings; 4. If the optical modem fails, you need to use a cotton swab to wipe the head of the optical fiber tail plug. After wiping it clean, insert it into the optical modem again.

See all articles