复制代码 代码如下:
#!/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() <= 40):
    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 <= -WINDOW_ONEBUTTON_WIDTH):
      if(self.current_index < WINDOW_PAGE_COUNT-1):
       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 < self.current_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 < WINDOW_PAGE_COUNT-1):
      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.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)
  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_())

标签:
360,显示界面

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
评论“python实现360的字符显示界面”
暂无“python实现360的字符显示界面”评论...

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。