<commit_before>#!/usr/bin/python
import appindicator
import gtk
import sys
import subprocess

class Fluxgui:

  def __init__(self):
    self.indicator = Indicator(self)
    self.start_xflux("52.07") #get these from preferences file

  def start_xflux(self, latitude):
    self.xflux = subprocess.Popen(["/bin/xflux", "-l", latitude], stdout=subprocess.PIPE)

    returncode = self.xflux.stdout
    self.xfluxKillCode = ""

    while True:
      line = returncode.readline()
      if "background" in line:
        newline = line.split("\'")
        self.xfluxKillCode = newline[1]
        return
      return

  def kill_xflux(self, item):
    self.indicator.killxflux.hide()
    self.indicator.restartxflux.show()

    self.xfluxKill = subprocess.Popen(self.xfluxKillCode, stdout=subprocess.PIPE)

  def restart_xflux(self, item):
    self.indicator.killxflux.show()
    self.indicator.restartxflux.hide()

    self.start_xflux("52.07") #get these from preferences file

  def open_preferences(self, item):
    print "yellow"
    self.preferences = Preferences(self)

  def run(self):
    gtk.main()

  def exit(self, widget, data=None):
    self.kill_xflux("activate")
    gtk.main_quit()
    sys.exit(0)


class Indicator:

  def __init__(self, main):
    self.main = main
    self.setup_indicator()

  def setup_indicator(self):
    self.indicator = appindicator.Indicator(
      "fluxgui-indicator",
      "fluxgui",
      appindicator.CATEGORY_APPLICATION_STATUS)
    self.indicator.set_status(appindicator.STATUS_ACTIVE)

    # Check for special Ubuntu themes. copied from lookit
    theme = gtk.gdk.screen_get_default().get_setting(
            'gtk-icon-theme-name')
    if theme == 'ubuntu-mono-dark':
      self.indicator.set_icon('fluxgui-dark')
    elif theme == 'ubuntu-mono-light':
      self.indicator.set_icon('fluxgui-light')
    else:
      self.indicator.set_icon('fluxgui')

    self.indicator.set_menu(self.setup_menu())

  def setup_menu(self):
    menu = gtk.Menu()

    self.killxflux = gtk.MenuItem("_Turn f.lux off")
    self.killxflux.connect("activate", self.main.kill_xflux)
    self.killxflux.show()
    menu.append(self.killxflux)

    self.restartxflux = gtk.MenuItem("_Turn f.lux on")
    self.restartxflux.connect("activate", self.main.restart_xflux)
    self.restartxflux.hide()
    menu.append(self.restartxflux)

    item = gtk.MenuItem("_Preferences")
    item.connect("activate", self.main.open_preferences)
    item.show()
    menu.append(item)

    item = gtk.SeparatorMenuItem()
    item.show()
    menu.append(item)

    item = gtk.MenuItem("Exit")
    item.connect("activate", self.main.exit)
    item.show()
    menu.append(item)

    return menu

  def main(self):
    gtk.main()

class Preferences:

  def __init__(self, main):
    self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    self.window.set_title("fluxgui preferences")
    self.window.connect("delete_event", self.delete_event)
    self.window.set_border_width(10)

    self.button = gtk.Button("Hello World")
    #self.button.connect("clicked", self.hello, None)
    self.window.add(self.button)

    self.button.show()

    self.window.show()

  def delete_event(self, widget, data=None):
    print "save stuff here"
    return False

  def main(self):
    gtk.main()

if __name__=="__main__":
  app = Fluxgui()
  app.run()
<commit_msg>better naming<commit_after>#!/usr/bin/python
import appindicator
import gtk
import sys
import subprocess

VERSION = "1.0.0"
MYLATITUDE = "52.07"

class Fluxgui:

  def __init__(self):
    self.indicator = Indicator(self)
    self.start_xflux(MYLATITUDE) #get these from preferences file

  def start_xflux(self, latitude):
    process = subprocess.Popen(["/bin/xflux", "-l", latitude], stdout=subprocess.PIPE)

    returncode = process.stdout
    self.xflux_kill_code = ""

    #figure out if this is correct
    while True:
      line = returncode.readline()
      if "background" in line:
        newline = line.split("\'")
        self.xflux_kill_code = newline[1]
        return
      return

  def stop_xflux(self, item):
    self.indicator.item_turn_off.hide()
    self.indicator.item_turn_on.show()

    #figure out how to get this actually working (permission denied, now)
    process = subprocess.Popen(self.xflux_kill_code, stdout=subprocess.PIPE)

  def restart_xflux(self, item):
    self.stop_xflux(self, "activate")

    self.indicator.item_turn_off.show()
    self.indicator.item_turn_on.hide()

    self.start_xflux(MYLATITUDE) #get these from preferences file

  def open_preferences(self, item):
    self.preferences = Preferences(self)

  def run(self):
    gtk.main()

  def exit(self, widget, data=None):
    self.kill_xflux("activate")
    gtk.main_quit()
    sys.exit(0)


class Indicator:

  def __init__(self, main):
    self.main = main
    self.setup_indicator()

  def setup_indicator(self):
    self.indicator = appindicator.Indicator(
      "fluxgui-indicator",
      "fluxgui",
      appindicator.CATEGORY_APPLICATION_STATUS)
    self.indicator.set_status(appindicator.STATUS_ACTIVE)

    # Check for special Ubuntu themes. copied from lookit
    theme = gtk.gdk.screen_get_default().get_setting(
            'gtk-icon-theme-name')
    if theme == 'ubuntu-mono-dark':
      self.indicator.set_icon('fluxgui-dark')
    elif theme == 'ubuntu-mono-light':
      self.indicator.set_icon('fluxgui-light')
    else:
      self.indicator.set_icon('fluxgui')

    self.indicator.set_menu(self.setup_menu())

  def setup_menu(self):
    menu = gtk.Menu()

    self.item_turn_off = gtk.MenuItem("_Turn f.lux off")
    self.item_turn_off.connect("activate", self.main.stop_xflux)
    self.item_turn_off.show()
    menu.append(self.item_turn_off)

    self.item_turn_on = gtk.MenuItem("_Turn f.lux on")
    self.item_turn_on.connect("activate", self.main.restart_xflux)
    self.item_turn_on.hide()
    menu.append(self.item_turn_on)

    item = gtk.MenuItem("_Preferences")
    item.connect("activate", self.main.open_preferences)
    item.show()
    menu.append(item)

    item = gtk.SeparatorMenuItem()
    item.show()
    menu.append(item)

    item = gtk.MenuItem("Exit")
    item.connect("activate", self.main.exit)
    item.show()
    menu.append(item)

    return menu

  def main(self):
    gtk.main()


class Preferences:

  def __init__(self, main):
    #import glade file here, somehow

  def delete_event(self, widget, data=None):
    #get latitude and save it
    return False

  def main(self):
    gtk.main()


if __name__=="__main__":
  app = Fluxgui()
  app.run()
{'fraction_non_alphanumeric': 0.12624178511386214, 'fraction_numerical': 0.0032095369096744614, 'mean_word_length': 3.374331550802139, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5288092', 'n_tokens_mistral': 2391, 'n_tokens_neox': 2229, 'n_words': 412}