Python实现的基于ADB的Android远程工具(10)

if btn_name != 'none':
                self.tbutton = ttk.Button(self, name = btn_name, text=btn_name)
            else:
                self.tbutton = ttk.Button(self, name = btn_name, text='')

self.tbutton['width'] = 10
            if btn_name != 'none':
                self.tbutton.bind('<ButtonRelease-1>', self.sendKey)
                self.tbutton.grid(padx = 5, pady = 1, column = col_id, row = row_id)

def devexist(self):
        p = subprocess.Popen("adb devices", shell=True, stdout=subprocess.PIPE)
        p.wait()
        devList = p.communicate()
        devList = devList[0].splitlines()
        if 'device' in devList[1]:
            if DEBUG:
                print devList[1]
            return True
        else:
            if DEBUG:
                print 'No adb device found'
            return False

def sendKey(self, event=None):
        if DEBUG:
            print event.widget.winfo_name()
        keyname = event.widget.winfo_name()
        if keyname in keynames:
            sender = send_key_thread(keyname)
            sender.start()

# LCD Tkinter-Based GUI application
class LcdApplication(tk.Frame):
    __img_factor = 1.00 # image resize rate
    __lcd = None # the label widget
    __keepupdate = True
    __im = None
    __rotate = 0

# record mouse start & end point location
    __start = [0, 0]
    __end = [0, 0]

def __init__(self, master=None):
        if DEBUG:
            print 'LcdApplication: __init__'
        if master == None:
            master = tk.Tk()
        tk.Frame.__init__(self, master, class_='LcdApplication')
        self.__rotate = 0
        self.createlcd()
        self.grid()

def createlcd(self):
        # creat label as lcd
        if DEBUG:
            print 'LcdApplication: createlcd'

# make default image display on label
        image = Image.new(mode = 'RGB', size = (240, 320), color = '#000000')
        draw = ImageDraw.Draw(image)
        draw.text((80, 100), 'Connecting...')
        self.__im = ImageTk.PhotoImage(image)

# create label with image option
        self.__lcd = tk.Label(self, image=self.__im)
        self.__lcd.bind('<Button-1>', self.click_label)
        self.__lcd.bind('<ButtonRelease-1>', self.click_label)
        self.__lcd.bind('<ButtonRelease-3>', self.rightclick_label)

# disply label on frame
        self.__lcd.grid()

# To serve right click on label widget
    def rightclick_label(self, event=None):
        if DEBUG:
            print 'Type: %s' % event.type
        self.__rotate = (self.__rotate + 90) % 360
        print "rotate: %d" % self.__rotate

# To serve left click on label widget
    def click_label(self, event=None):
        if DEBUG:
            print 'Type: %s' % event.type
        if event.type == '4':
            # record mouse left button down
            if DEBUG:
                print 'Click at: (%d, %d)' % (event.x, event.y)
            self.__start[0] = int(float(event.x) / float(self.__img_factor))
            self.__start[1] = int(float(event.y) / float(self.__img_factor))
            self.__end = None
        elif event.type == '5':
            # record mouse left button up
            if DEBUG:
                print 'Release at: (%d, %d)' % (event.x, event.y)
            self.__end = [0, 0]
            self.__end[0] = int(float(event.x) / float(self.__img_factor))
            self.__end[1] = int(float(event.y) / float(self.__img_factor))

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/4426fff1a55660c72a73dc3e3c0f172d.html