Python implements a 360 character display interface

Source: Internet
Author: User
Copy CodeThe code is as follows:


#!/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) #图片 (combination)
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): #右移 br> 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
#若下标小于当前下标右移, otherwise move left
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
#真: Move left false: Move right

#左移的几种可能性, for x-coordinates
#index = 0, move the label to -680*0
#index = 1, move the label to -680*1
#index = 2, move the label to -680*2
#index = 3, move the label to -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_ ())

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.