示例#1
0
文件: conkyrc.py 项目: qtm/dotfiles
def blockify_date():
  """ Prints the date and time. """

  now = datetime.datetime.now()

  calendar = StatusUnit('calendar')
  calendar.set_icon('')
  calendar.set_text(now.strftime('%a %d/%b.'))
  return calendar
示例#2
0
def blockify_active_window():
  """ Print the currently active window (or 'none'). """

  active_window, return_code = executor.run('xdotool getactivewindow getwindowname')
  if return_code != 0:
    return None
  if len(active_window) > 100:
    active_window = active_window[:80] + '...' + active_window[-20:]

  block = StatusUnit('active-window')
  block.set_icon('')
  block.set_text(active_window)

  return block
示例#3
0
文件: conkyrc.py 项目: qtm/dotfiles
def blockify_time():
  """ Prints the time. """

  now = datetime.datetime.now()

  clock = StatusUnit('clock')
  clock.set_icon('')
  clock.set_text(now.strftime('%H:%M:%S'))
  clock.set_color(colors['bg'], colors['bg'])
  clock.set_background(colors['green'])
  return clock
示例#4
0
def blockify_ethernet():
  """ Prints information about the connected ethernet. """

  interface = "eth0"
  try:
    with open('/sys/class/net/{}/operstate'.format(interface)) as operstate:
      status = operstate.read().strip()
  except:
    return None
  if status != 'up':
    return None

  block = StatusUnit('network')
  block.set_icon('')
  block.set_text(interface + ' @ ' + netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['addr'])

  return block
示例#5
0
def blockify_cpu():
  """ Print the CPU load average and temperature """
  
  block = StatusUnit("cpu")
  block.set_icon("C")

  cpuload = executor.run("uptime | awk -F'[a-z]:' '{ print $2}'")[0]
  oneminload = float(cpuload.split(",")[0] + "." + cpuload.split(",")[1])
  cputemp = executor.run("cat /sys/class/thermal/thermal_zone7/temp")[0]
  temp = int(cputemp) / 1000
  
  if oneminload > 3 or temp > 80:
    block.set_urgent()
  elif oneminload > 1 or temp > 60:
    block.set_border(colors["urgent"], 0, TOP_BORDER_WIDTH, 0, 0)

  block.set_text(str(oneminload) + "/" + str(temp))
  block.status_block.set_min_width(40, "right")
  return block.to_json()
示例#6
0
def blockify_time():
  """ Prints the time. """

  now = datetime.datetime.now()

  clock = StatusUnit('clock')
  clock.set_icon('')
  clock.set_text(' ' + now.strftime('%H:%M:%S') + ' ')
  return clock.to_json()
示例#7
0
def blockify_date():
  """ Prints the date and time. """

  now = datetime.datetime.now()

  calendar = StatusUnit('calendar')
  calendar.set_icon('')
  calendar.set_text(' ' + now.strftime('%a., %d. %b. %Y') + ' ')
  return calendar.to_json()
示例#8
0
def blockify_pidgin():
  """ If pidgin is running, print the number of unread messages.

  For this to work, the pidgin option to set a X variable must be enabled.
  """

  unread_messages, return_code = executor.run_script('pidgin-count')
  if return_code != 0:
    return None

  block = StatusUnit('pidgin')
  block.set_icon('')
  block.set_text(unread_messages)

  if int(unread_messages) != 0:
    block.set_urgent()
  return block.to_json()
示例#9
0
def blockify_time():
  """ Prints the time. """

  now = datetime.datetime.now()

  clock = StatusUnit('clock')
  clock.set_icon('')
  clock.set_text(now.strftime('%H:%M:%S'))
  return clock.to_json()
示例#10
0
def blockify_pidgin():
  """ If pidgin is running, print the number of unread messages.

  For this to work, the pidgin option to set a X variable must be enabled.
  """

  unread_messages, return_code = executor.run_script('pidgin-count')
  if return_code != 0:
    return None

  block = StatusUnit('pidgin')
  block.set_icon('')
  block.set_text(unread_messages)

  if int(unread_messages) != 0:
    block.set_urgent()
  return block.to_json()
示例#11
0
def blockify_wifi():
  """ Prints information about the connected wifi. """

  interface = "wlan0"
  try:
    with open('/sys/class/net/{}/operstate'.format(interface)) as operstate:
      status = operstate.read().strip()
  except:
    return None
  if status != 'up':
    return None

  info = basiciw.iwinfo(interface)

  block = StatusUnit('network')
  block.set_icon('')
  block.set_background(colors['yellow'])
  block.set_color(colors['bg'], colors['bg'])
  block.set_text(info['essid'])

  return block
示例#12
0
def blockify_topprocess():
  """ Print the top CPU consuming process """
  
  block = StatusUnit("topcpu")
  block.set_icon("T")

  topprocess = executor.run("ps aux | sort -rk 3,3 | head -n 2 | tail -n 1 | rev | sed -e 's/^[[:space:]]*//' | cut -d' ' -f 1 | rev")[0]
  block.set_text(str(topprocess))
  block.status_block.set_min_width(40, "right")
  return block.to_json()
示例#13
0
def blockify_active_window():
  """ Print the currently active window (or 'none'). """

  active_window, return_code = executor.run('xdotool getactivewindow getwindowname')
  if return_code != 0:
    return None
  if len(active_window) > 100:
    active_window = active_window[:80] + '...' + active_window[-20:]

  block = StatusUnit('active-window')
  block.set_icon('')
  block.set_text(' ' + active_window)

  return block.to_json()
示例#14
0
def blockify_toggl():
  w = workingtime.WorkingTime(config.WORKING_HOURS_PER_DAY, config.BUSINESS_DAYS, config.WEEK_DAYS)
  a = api.TogglAPI(config.API_TOKEN, config.TIMEZONE)
  t = target.Target()
  achieved_minutes = a.get_minutes_tracked(start_date=w.week_start, end_date=w.minute)
  t.achieved_hours = achieved_minutes / 60.0
  today_minutes = a.get_minutes_tracked(start_date=w.today, end_date=w.minute)
  t.today_hours = today_minutes / 60.0
  logging.debug('today minutes: %d' % (today_minutes))
  t.required_hours = w.required_hours_this_month
  t.tolerance      = config.TOLERANCE_PERCENTAGE

  normal_min_hours, crunch_min_hours = t.get_required_daily_hours(w.business_days_left_count, w.days_left_count)

  today_required_minutes = normal_min_hours * 60
  elapsed_minutes = today_required_minutes - today_minutes

  if (elapsed_minutes > 0):
    e_h, e_m = divmod(elapsed_minutes, 60)
    text = '%dh %dm' % (e_h, e_m)
  else:
    text = ''

  text += "  "

  if (achieved_minutes > 0):
    a_h, a_m = divmod(achieved_minutes, 60)
    text += '%dh %dm' % (a_h, a_m)
  else:
    text += '0h 0m'

  toggl = StatusUnit('toggl')
  toggl.set_icon('')
  toggl.set_text(text)
  toggl.set_background(colors['blue'])
  toggl.set_color(colors['red'], colors['bg'])
  return toggl
示例#15
0
def blockify_ethernet():
  """ Prints information about the connected ethernet. """

  interface = "eth0"
  try:
    with open('/sys/class/net/{}/operstate'.format(interface)) as operstate:
      status = operstate.read().strip()
  except:
    return None  
  if status != 'up':
    return None

  block = StatusUnit('network')
  block.set_icon('')
  block.set_text(' ' + interface + ' @ ' + netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['addr'])

  return block.to_json()
示例#16
0
def blockify_wifi():
  """ Prints information about the connected wifi. """

  interface = "wlan0"
  try:
    with open('/sys/class/net/{}/operstate'.format(interface)) as operstate:
      status = operstate.read().strip()
  except:
    return None  
  if status != 'up':
    return None

  info = basiciw.iwinfo(interface)

  block = StatusUnit('network')
  block.set_icon('')
  block.set_text(info['essid'])

  return block.to_json()
示例#17
0
def blockify_volume():
  """ Print the current volume. """

  block = StatusUnit('volume')
  block.icon_block.set_name('toggle-volume')

  status = volume_control.status()
  if status == "on":
    volume = int(volume_control.get_volume())
    if volume > 80:
      block.set_icon('')
    elif volume > 40:
      block.set_icon('')
    else:
      block.set_icon('')

    block.set_text(str(volume) + '%')

    color = get_color_gradient(volume, [
      { 'threshold': 0,   'color': colors['urgent'] },
      { 'threshold': 100, 'color': colors['blue'] },
      { 'threshold': 101, 'color': colors['yellow'] },
      { 'threshold': 200, 'color': colors['yellow'] } ])
    block.set_border(color, 0, TOP_BORDER_WIDTH, 0, 0)
    block.status_block.set_min_width(40, 'right')
  else:
    block.set_icon('')
    block.set_text('muted')
    block.set_urgent()
    block.status_block.set_name('toggle-volume')

  return block.to_json()
示例#18
0
def blockify_battery():
  """ Print the current battery level. """

  block = StatusUnit('battery')
  block.set_icon('')

  acpi = executor.run('acpi -b')[0]
  battery = re.search('\d*%', acpi).group(0)
  battery_int = int(battery[:-1])
  is_charging = bool(re.search('Charging|Unknown', acpi))

  if is_charging:
    block.set_icon('')
  elif battery_int > 90:
    block.set_icon('')
  elif battery_int > 50:
    block.set_icon('')
  elif battery_int > 20:
    block.set_icon('')
  else:
    block.set_icon('')

  block.set_text(battery)

  if battery_int > 10 or is_charging:
    color = get_color_gradient(battery_int, [ 
      { 'threshold': 0,   'color': colors['urgent'] },
      { 'threshold': 20,  'color': colors['urgent'] },
      { 'threshold': 80,  'color': colors['blue'] },
      { 'threshold': 100, 'color': colors['blue'] } ])
    block.set_border(color, 0, TOP_BORDER_WIDTH, 0, 0)
  else:
    block.set_urgent()

  block.status_block.set_min_width(40, 'right')
  return block.to_json()
示例#19
0
def blockify_volume():
  """ Print the current volume. """

  block = StatusUnit('volume')
  block.icon_block.set_name('toggle-volume')

  status = volume_control.status()
  if status == "on":
    volume = int(volume_control.get_volume())
    if volume > 80:
      block.set_icon('')
    elif volume > 40:
      block.set_icon('')
    else:
      block.set_icon('')

    block.set_text(str(volume) + '%')

    color = get_color_gradient(volume, [
      { 'threshold': 0,   'color': colors['urgent'] },
      { 'threshold': 100, 'color': colors['blue'] },
      { 'threshold': 101, 'color': colors['yellow'] },
      { 'threshold': 200, 'color': colors['yellow'] } ])
    block.set_border(color, 0, TOP_BORDER_WIDTH, 0, 0)
    block.status_block.set_min_width(40, 'right')
  else:
    block.set_icon('')
    block.set_text('muted')
    block.set_urgent()
    block.status_block.set_name('toggle-volume')

  return block.to_json()
示例#20
0
def blockify_battery():
  """ Print the current battery level. """

  block = StatusUnit('battery')
  block.set_icon('')

  acpi = executor.run('acpi -b')[0]
  battery = re.search('\d*%', acpi).group(0)
  battery_int = int(battery[:-1])
  is_charging = bool(re.search('Charging|Unknown', acpi))

  if is_charging:
    block.set_icon('')
  elif battery_int > 90:
    block.set_icon('')
  elif battery_int > 50:
    block.set_icon('')
  elif battery_int > 20:
    block.set_icon('')
  else:
    block.set_icon('')

  block.set_text(battery)

  if battery_int > 10 or is_charging:
    color = get_color_gradient(battery_int, [ 
      { 'threshold': 0,   'color': colors['urgent'] },
      { 'threshold': 20,  'color': colors['urgent'] },
      { 'threshold': 80,  'color': colors['blue'] },
      { 'threshold': 100, 'color': colors['blue'] } ])
    block.set_border(color, 0, TOP_BORDER_WIDTH, 0, 0)
  else:
    block.set_urgent()

  block.status_block.set_min_width(40, 'right')
  return block.to_json()
示例#21
0
def blockify_battery():
  """ Print the current battery level. """

  block = StatusUnit('battery')
  block.set_icon('')

  acpi = executor.run('acpi -b')[0]
  battery = re.search('\d*%', acpi).group(0)
  battery_int = int(battery[:-1])
  is_charging = bool(re.search('Charging|Unknown', acpi))

  if is_charging:
    block.set_icon('')
  elif battery_int > 90:
    block.set_icon('')
  elif battery_int > 60:
    block.set_icon('')
  elif battery_int > 30:
    block.set_icon('')
  elif battery_int > 10:
    block.set_icon('')
  else:
    block.set_icon('')

  if is_charging:
    block.set_text('')
  else:
    block.set_text(battery)
    block.set_background(colors['red'])
    block.set_color(colors['white'], colors['white'])

  return block