~marnold128/gmtenpoko

dd1a31ee4e54104b33a4b454b884d572c62792e3 — Matt Arnold 6 months ago 9806cba
This code was deprecated when i wrote it apperently.. It's now fixed
1 files changed, 55 insertions(+), 6 deletions(-)

M main.py -rw-r--r-- => -rwxr-xr-x
M main.py => main.py +55 -6
@@ 2,17 2,48 @@

import gi
gi.require_version('Gtk', '3.0')
gi.require_version('AppIndicator3', '0.1')
try:
    gi.require_version('AyatanaAppIndicator3', '0.1')
    from gi.repository import AyatanaAppIndicator3 as appindicator
except (ImportError, ValueError):
    appindicator = None

import time
import math
from threading import Thread
from gi.repository import Gtk, AppIndicator3, GObject
from gi.repository import Gtk, GObject
import signal
import datetime
import astro

asset_paths = {"fire": "/opt/tenpoko/fire.png", "water": "/opt/tenpoko/water.png",
              "earth": "/opt/tenpoko/earth.png", "air": "/opt/tenpoko/air.png"}
def get_moon_phase():
    now = time.time()
    jdate = astro.unix_to_julian(now)
    phase_t = astro.phase(jdate)
    phase = phase_t[0]

    if 0 <= phase < 0.03 or 0.97 <= phase <= 1.0:
        return "New Moon"
    elif 0.03 <= phase < 0.5:
        if 0.03 <= phase < 0.5:
            return "First Quater Waxing Cresent"
        elif 0.15 <= phase < 0.35:
            return "Waxing Gibbous"
        else:
            return "Full Moon"
    elif 0.03 <= phase < 0.5:
        if 0.65 <= phase < 0.97:
            return "Last Quater Waning Cresent"
        elif 0.35 <= phase < 0.65:
            return "Waning Gibbous"
        else:
            return "New Moon"
    else:
        return "Invalid"

    

def get_tenpko_time():
    litu = "living"


@@ 46,15 77,16 @@ class Indicator():
        self.seed_time = get_tenpko_time()
        iconpath =  asset_paths[self.seed_time[0]]
        self.timeMsg = self.seed_time[0] + " " + self.seed_time[1] + " "
        self.indicator = AppIndicator3.Indicator.new(
        self.indicator = appindicator.Indicator.new(
            self.app, iconpath,
            AppIndicator3.IndicatorCategory.OTHER)
        self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
            appindicator.IndicatorCategory.OTHER)
        self.indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
        self.indicator.set_menu(self.create_menu())
        self.indicator.set_label(self.timeMsg, self.app)
        self.ticker = Thread(target=self.update_time)
        self.ticker.setDaemon(True)
        self.ticker.start()
        self.moon_phase_show = False

    def create_menu(self):
        menu = Gtk.Menu()


@@ 62,22 94,38 @@ class Indicator():
        # separator
        menu_sep = Gtk.SeparatorMenuItem()
        menu.append(menu_sep)

        item_moon = Gtk.MenuItem(label='Show Moon')
        item_moon.connect('activate', self.show_moon_phase)
        menu.append(item_moon)
        # quit
        item_quit = Gtk.MenuItem(label='Quit')
        item_quit.connect('activate', self.stop)
        menu.append(item_quit)


        menu.show_all()
        return menu

    def stop(self, source):
        Gtk.main_quit()

    def show_moon_phase(self, source):
        self.moon_phase_show = not self.moon_phase_show
        if self.moon_phase_show:
            self.timeMsg = get_moon_phase() + " "
        else:
            self.timeMsg = self.seed_time[0] + " " + self.seed_time[1] + " "
        self.indicator.set_label(self.timeMsg, self.app)

    def update_time(self):
        while True:
            time.sleep(30)
            self.seed_time = get_tenpko_time()
            self.timeMsg = self.seed_time[0] + " " + self.seed_time[1] + " "
            if self.moon_phase_show:
                self.timeMsg = get_moon_phase() + " "
            else:
                self.timeMsg = self.seed_time[0] + " " + self.seed_time[1] + " "
            GObject.idle_add(
                self.indicator.set_label,
                self.timeMsg, self.app,


@@ 94,6 142,7 @@ class Indicator():




if __name__== '__main__':
    Indicator()
    GObject.threads_init()