Nokia N900 >> Native Debian >> Kernel 5.3.0

自製設定Trayicon


由於目前的VBUS供電需要透過CommandLine設定,司徒也不想一直開啓VBUS供電功能,主要原因在於耗電過快,因此,司徒使用PyGtk寫了一個USB供電和掛載SDCard的設定App,可以透過這個TrayIcon作切換,程式碼如下。

trayicon.py

#!/usr/bin/python
import os
import sys
import gtk
import glib
import time
import commands
import subprocess

base_path = '/usr/n900/trayicon/'
usb_vbus = '/sys/devices/platform/68000000.ocp/48072000.i2c/i2c-2/2-006b/power_supply/bq24150a-0/mode'
usb_mass = '/sys/devices/platform/68000000.ocp/480ab000.usb_otg_hs/musb-hdrc.0.auto/gadget/lun0/file'

class n900:
  mass = False

  def __init__(self):
    mass = False
    os.system('echo "" > {}'.format(usb_mass))
    self.statusicon = gtk.StatusIcon()
    self.statusicon.set_from_file('{}{}'.format(base_path, 'main.png'))
    self.statusicon.connect("activate", self.left_click_event)

  def left_click_event(self, event):
    time = gtk.get_current_event_time()
    button = gtk.get_current_event().button

    menu = gtk.Menu()
    cur_vbus = commands.getoutput('cat {}'.format(usb_vbus))

    submenu = None
    img = gtk.Image()
    img.set_from_file('{}{}'.format(base_path, 'vbus.png'))
    if 'auto' in cur_vbus:
      submenu = gtk.ImageMenuItem("Enable VBUS")
      submenu.connect("button-press-event", self.enable_vbus) 
    else:
      submenu = gtk.ImageMenuItem("Disable VBUS")
      submenu.connect("button-press-event", self.disable_vbus) 
    submenu.set_image(img)
    menu.append(submenu)

    submenu = None
    img = gtk.Image()
    img.set_from_file('{}{}'.format(base_path, 'mass.png'))
    if self.mass == False:
      submenu = gtk.ImageMenuItem("Mount SDCard")
      submenu.connect("button-press-event", self.mount_sd) 
    else:
      submenu = gtk.ImageMenuItem("Unmount SDCard")
      submenu.connect("button-press-event", self.unmount_sd) 
    submenu.set_image(img)
    menu.append(submenu)

    menu.append(gtk.SeparatorMenuItem())
    menuexit = gtk.ImageMenuItem("Exit")
    img = gtk.Image()
    img.set_from_file('{}{}'.format(base_path, 'exit.png'))
    menuexit.set_image(img)
    menuexit.connect("button-press-event", self.exit) 
    menu.append(menuexit) 

    menu.show_all() 
    menu.popup(None, None, 
      gtk.status_icon_position_menu, button, time, self.statusicon) 

  def disable_vbus(self, widget, event): 
    os.system('echo auto > {}'.format(usb_vbus))
  
  def enable_vbus(self, widget, event): 
    os.system('echo boost > {}'.format(usb_vbus))
  
  def mount_sd(self, widget, event): 
    self.mass = True
    os.system('echo /dev/mmcblk0p1 > {}'.format(usb_mass))
  
  def unmount_sd(self, widget, event): 
    self.mass = False
    os.system('echo "" > {}'.format(usb_mass))
  
  def exit(self, widget, event): 
    if event.button == 1:
      gtk.main_quit() 
  
n900()
gtk.main()


完成


返回上一頁