Skip to content

Commit

Permalink
cache file system and permissions fixed Log system added
Browse files Browse the repository at this point in the history
  • Loading branch information
serdarsen committed Apr 29, 2018
1 parent e4807ee commit 160d9e2
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 32 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,11 @@ ENV/

# mypy
.mypy_cache/

# Intellij
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/dictionaries
.idea/libraries
3 changes: 1 addition & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ function fail() {
echo "Installing UBrightnessController to $PLUGIN_DIR"

sudo rm -rf "${PLUGIN_DIR}/UBrightnessController" || fail
sudo cp -r ./src/UBrightnessController "${PLUGIN_DIR}/" || fail
sudo chmod -R 755 "${PLUGIN_DIR}/UBrightnessController/ubrightnesscontroller" || fail
sudo cp -r ./src/UBrightnessController "${PLUGIN_DIR}/" || fail
sudo chmod -R 644 "${PLUGIN_DIR}/UBrightnessController/UBrightnessController.py" || fail
budgie-panel --replace &

Expand Down
39 changes: 39 additions & 0 deletions src/UBrightnessController/Log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3

# This file is part of UBrightnessController

# Copyright © 2018 Serdar ŞEN <[email protected]>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

class Log():

logErrorOn = True
logDebugOn = False
logInfoOn = True

ERROR_TAG = "Log e: "
DEBUG_TAG = "Log d: "
INFO_TAG = "Log i: "

#prints error logs
@staticmethod
def e(TAG, msg):
if (Log.logErrorOn):
print(Log.ERROR_TAG + TAG + "; " + msg)

#prints debug logs
@staticmethod
def d(TAG, msg):
if (Log.logDebugOn):
print(Log.DEBUG_TAG + TAG + "; " + msg)


#prints info logs
@staticmethod
def i(TAG, msg):
if (Log.logInfoOn):
print(Log.INFO_TAG + TAG + "; " + msg)
83 changes: 54 additions & 29 deletions src/UBrightnessController/UBrightnessController.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
gi.require_version('Budgie', '1.0')
from gi.repository import Budgie, GObject, Gtk, Gdk
import check_displays as CDisplay
import os.path
import os, errno

import subprocess
from Log import Log

class UBrightnessController(GObject.GObject, Budgie.Plugin):
#This is simply an entry point into your Budgie Applet implementation. Note you must always override Object, and implement Plugin.
Expand All @@ -52,26 +54,40 @@ def do_get_panel_widget(self, uuid):

class UBrightnessControllerApplet(Budgie.Applet):
#Budgie.Applet is in fact a Gtk.Bin

TAG = "UBrightnessControllerApplet"
manager = None
isBacklightAvailable = True
isDimAvailable = True
dimValue = 0.5
config_path = ""
dim_cache_file_path = ""
image_path = ""
ubrightnesscontroller_path = ""

############################################
### Brightness (Light) methods Start #
############################################
MAXSTEPS = 15 # Depends on gnome-settings-daemon
closest = lambda self, num,list: min(list, key = lambda x: abs(x-num))

def makeDirIfNotExist(self, path):
if (path is not ""):
try:
os.makedirs(path)
except OSError as e:
if e.errno != errno.EEXIST:
raise

def setBacklightAvailable(self, b):
self.isBacklightAvailable = b
if(not self.isBacklightAvailable):
print("UBrightnessController No backlight detected")
Log.i(self.TAG, "UBrightnessController No backlight detected")

def setDimAvailable(self, b):
self.isDimAvailable = b
if(not self.isDimAvailable):
print("UBrightnessController Dim is not available")
Log.i(self.TAG, "UBrightnessController Dim is not available")

def get_brightness_settings(self):
if self.max_brightness < self.MAXSTEPS:
Expand Down Expand Up @@ -128,27 +144,29 @@ def initBrightness(self):
### Brightness (Dim) methods Start #
############################################
def saveDimValue(self, val):
try:
file = open(self.file_path,"w")
file.write("%s"%(str(val)))
file.close()
except:
print("UBrightnessController dim value save error")
if(self.dim_cache_file_path is not ""):
try:
file = open(self.dim_cache_file_path, "w+")
file.write("%s"%(str(val)))
file.close()
except:
Log.e(self.TAG, "error_4010 dim value save error")

def retriveDimValue(self):
val = "0.5"
try:
if(os.path.isfile(self.file_path)):
file = open(self.file_path,"r")
file.seek(0)
val = file.read()
file.close()
if (val == None):
val = "0.5"
if (val == ""):
val = "0.5"
if (self.dim_cache_file_path is not ""):
if(os.path.isfile(self.dim_cache_file_path)):
file = open(self.dim_cache_file_path, "r+")
file.seek(0)
val = file.read()
file.close()
if (val == None):
val = "0.5"
if (val == ""):
val = "0.5"
except:
print("UBrightnessController dim value retrive error")
Log.e(self.TAG, "error_4011 dim value retrive error")

return float("%s"%(val))

Expand Down Expand Up @@ -191,12 +209,18 @@ def dim_scale_moved(self, event):
def __init__(self, uuid):

Budgie.Applet.__init__(self)

#about files
self.dir_path = os.path.dirname(os.path.realpath(__file__))
self.file_path = self.dir_path + "/ubrightnesscontroller"
self.image_path = self.dir_path + "/brightness.svg"


# about files
try:
self.home_dir = os.path.expanduser("~")
self.dir_path = os.path.dirname(os.path.realpath(__file__))
self.ubrightnesscontroller_path = self.home_dir + '/.config/ubrightnesscontroller'
self.makeDirIfNotExist(self.ubrightnesscontroller_path)
self.dim_cache_file_path = self.ubrightnesscontroller_path + "/dim.txt"
self.image_path = self.dir_path + "/brightness.svg"
except:
Log.e("error_1015 get files path error")

#about displays
self.display1 = None
self.display2 = None
Expand All @@ -206,10 +230,11 @@ def __init__(self, uuid):
self.box = Gtk.EventBox()

#about ui
self.iconImage = Gtk.Image()
self.iconImage.set_from_file(self.image_path)
#self.iconImage = Gtk.Image.new_from_icon_name("display-brightness-symbolic", Gtk.IconSize.BUTTON)
self.box.add(self.iconImage)
if(self.image_path is not ""):
self.iconImage = Gtk.Image()
self.iconImage.set_from_file(self.image_path)
#self.iconImage = Gtk.Image.new_from_icon_name("display-brightness-symbolic", Gtk.IconSize.BUTTON)
self.box.add(self.iconImage)
self.box.show_all()
self.add(self.box)
self.popover = Budgie.Popover.new(self.box)
Expand Down
1 change: 0 additions & 1 deletion src/UBrightnessController/ubrightnesscontroller

This file was deleted.

0 comments on commit 160d9e2

Please sign in to comment.