Skip to content

Commit

Permalink
New changes!
Browse files Browse the repository at this point in the history
->  now can save settings
-> now can load settings as well!
-> small fix in UI
  • Loading branch information
LordAmit committed Sep 17, 2013
1 parent 182a5a1 commit 13baf73
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 7 deletions.
110 changes: 108 additions & 2 deletions src/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
from ui.help import Ui_Form as Help_Ui_Form
import util.executor as executor
import util.check_displays as cdisplay
import util.write_config as w_config
import util.read_config as r_config
import sys
from os import path as path

This comment has been minimized.

Copy link
@zlatanvasovic

zlatanvasovic Sep 17, 2013

Contributor

When use from <doom> import <boom> you do not need to add as <boom>.
So, correct one is from os import path. 😄

This comment has been minimized.

Copy link
@LordAmit

LordAmit Sep 17, 2013

Author Owner

That's what I knew as well, but Komodo was showing some sort of error at that time.
Was focusing on finishing things fast 👅
Got lots of other things to take care these days T_T

This comment has been minimized.

Copy link
@zlatanvasovic

zlatanvasovic Sep 17, 2013

Contributor

Use Brackets, really the best open source one. It's mainly for web, but also can be used for Python, PHP, etc. 😄

This comment has been minimized.

Copy link
@LordAmit

LordAmit Sep 17, 2013

Author Owner

I use Komodo for one specific reason. It shows pyDoc better than any free IDE I have tried till now 👅
I hope bracket does the same.

This comment has been minimized.

Copy link
@zlatanvasovic

zlatanvasovic Sep 17, 2013

Contributor

:D

This comment has been minimized.

Copy link
@archisman-panigrahi

archisman-panigrahi Sep 17, 2013

Contributor

Sublime Text 2?

This comment has been minimized.

Copy link
@LordAmit

LordAmit Sep 17, 2013

Author Owner

That's not even an IDE.

This comment has been minimized.

Copy link
@LordAmit

LordAmit Sep 17, 2013

Author Owner

Already not liking it @zdroid. It is just an editor with cool looking color scheme. >.>


class MyApplication(QtGui.QMainWindow):

Expand Down Expand Up @@ -87,6 +90,8 @@ def connect_handlers(self):
user_interface.actionExit.triggered.connect(self.close)
user_interface.actionHelp.triggered.connect(self.show_help)
user_interface.actionLicense.triggered.connect(self.show_license)
user_interface.actionSave.triggered.connect(self.save_settings)
user_interface.actionLoad.triggered.connect(self.load_settings)

def enable_secondary_widgets(self, boolean):
'''
Expand Down Expand Up @@ -241,8 +246,6 @@ def combo_activated(self, text):
self.change_primary_sliders(rgb)
if self.no_of_connected_dev == 2:
self.change_secondary_sliders(rgb)
#time.sleep(5)
#executor.execute_command('eog troll_face_problem-2555px_2.png')
elif text == '2600K 40W Tungsten':
rgb = [255, 197, 143]
self.change_primary_sliders(rgb)
Expand Down Expand Up @@ -301,6 +304,7 @@ def change_secondary_sliders(self, rgb):
'''
rgb - based on the rgb array, assign values to
secondary display sliders and in turn changes secondary display color
rgb is given in array from a range of 0 to 255
'''
slider_r = int((rgb[0] * 100 ) / 255)
slider_g = int((rgb[1] * 100 ) / 255)
Expand All @@ -310,6 +314,36 @@ def change_secondary_sliders(self, rgb):
self.ui.secondary_green.setValue(slider_g)
self.ui.secondary_blue.setValue(slider_b)

def change_secondary_sliders_in_rgb_0_99(self, br_rgb):
'''
change slider values in rgb from a range of 0 to 99 value
for secondary monitor slider
'''
self.ui.secondary_brightness.setValue(br_rgb[0])
self.ui.secondary_red.setValue(br_rgb[1])
self.ui.secondary_green.setValue(br_rgb[2])
self.ui.secondary_blue.setValue(br_rgb[3])

def primary_sliders_in_rgb_0_99(self, br_rgb):
'''
change slider values in rgb from a range of 0 to 99 value
for primary monitor sliders
'''
self.ui.primary_brightness.setValue(br_rgb[0])
self.ui.primary_red.setValue(br_rgb[1])
self.ui.primary_green.setValue(br_rgb[2])
self.ui.primary_blue.setValue(br_rgb[3])

def secondary_sliders_in_rgb_0_99(self, br_rgb):
'''
change slider values in rgb from a range of 0 to 99 value
for primary monitor sliders
'''
self.ui.secondary_brightness.setValue(br_rgb[0])
self.ui.secondary_red.setValue(br_rgb[1])
self.ui.secondary_green.setValue(br_rgb[2])
self.ui.secondary_blue.setValue(br_rgb[3])

def show_about(self):
''' Shows the About widget'''
self.about_widget.show()
Expand All @@ -320,6 +354,78 @@ def show_help(self):
''' Shows the Help Widget'''
self.help_widget.show()

def save_settings(self):
''' save current primary and secondary display settings'''
file_path = QtGui.QFileDialog.getSaveFileName()[0]
if path.exists(file_path):
if self.no_of_connected_dev == 1:
print 'here I am in primary'
w_config.write_primary_display(
self.return_current_primary_settings(),
file_path
)
elif self.no_of_connected_dev == 2:
print 'here I am in secondary'
w_config.write_both_display(
self.return_current_primary_settings(),
self.return_current_secondary_settings(),
self.ui.checkBox.isChecked(),
file_path
)

def load_settings(self):
'''
Load current primary and secondary display settings
'''
file_path = QtGui.QFileDialog.getOpenFileName()[0]
if path.exists(file_path):
loaded_settings = r_config.read_configuration(file_path)
if len(loaded_settings) == 4:
self.primary_sliders_in_rgb_0_99(loaded_settings)
elif len(loaded_settings) == 9:
# checks just in case saved settings are for two displays,
# but loads when only one display is connected
if self.no_of_connected_dev == 1:

self.primary_sliders_in_rgb_0_99((loaded_settings[0],
loaded_settings[1],
loaded_settings[2],
loaded_settings[3]))
return
# sets reverse control
self.ui.checkBox.setChecked(loaded_settings[8])
self.primary_sliders_in_rgb_0_99((loaded_settings[0],
loaded_settings[1],
loaded_settings[2],
loaded_settings[3]))
self.secondary_sliders_in_rgb_0_99((loaded_settings[4],
loaded_settings[5],
loaded_settings[6],
loaded_settings[7]))

def return_current_primary_settings(self):
'''
return p_br_rgb(primary_brightness,
primary_red, primary_green, primary_blue)
'''
p_br_rgb = []
p_br_rgb.append(self.ui.primary_brightness.value())
p_br_rgb.append(self.ui.primary_red.value())
p_br_rgb.append(self.ui.primary_green.value())
p_br_rgb.append(self.ui.primary_blue.value())
return p_br_rgb
def return_current_secondary_settings(self):
'''
return s_br_rgb(secondary_brightness,
secondary_red, secondary_green, secondary_blue)
'''
s_br_rgb = []
s_br_rgb.append(self.ui.secondary_brightness.value())
s_br_rgb.append(self.ui.secondary_red.value())
s_br_rgb.append(self.ui.secondary_green.value())
s_br_rgb.append(self.ui.secondary_blue.value())
return s_br_rgb

class LicenseForm(QtGui.QWidget):
'''License Form widget initialization'''
def __init__(self, parent=None):
Expand Down
6 changes: 3 additions & 3 deletions src/ui/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'mainwindow.ui'
#
# Created: Wed Aug 28 19:24:43 2013
# Created: Tue Sep 17 11:56:47 2013
# by: pyside-uic 0.2.14 running on PySide 1.1.2
#
# WARNING! All changes made in this file will be lost!
Expand Down Expand Up @@ -204,7 +204,7 @@ def retranslateUi(self, MainWindow):
self.actionHelp.setText(QtGui.QApplication.translate("MainWindow", "&Help", None, QtGui.QApplication.UnicodeUTF8))
self.actionAbout.setText(QtGui.QApplication.translate("MainWindow", "&About", None, QtGui.QApplication.UnicodeUTF8))
self.actionLicense.setText(QtGui.QApplication.translate("MainWindow", "&License", None, QtGui.QApplication.UnicodeUTF8))
self.actionSave.setText(QtGui.QApplication.translate("MainWindow", "Save Color Profile", None, QtGui.QApplication.UnicodeUTF8))
self.actionLoad.setText(QtGui.QApplication.translate("MainWindow", "Load Color Profile", None, QtGui.QApplication.UnicodeUTF8))
self.actionSave.setText(QtGui.QApplication.translate("MainWindow", "&Save current settings", None, QtGui.QApplication.UnicodeUTF8))
self.actionLoad.setText(QtGui.QApplication.translate("MainWindow", "&Load settings", None, QtGui.QApplication.UnicodeUTF8))
self.actionCheck_for_update.setText(QtGui.QApplication.translate("MainWindow", "&Check for Update", None, QtGui.QApplication.UnicodeUTF8))

4 changes: 2 additions & 2 deletions src/ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,12 @@
</action>
<action name="actionSave">
<property name="text">
<string>Save Color Profile</string>
<string>&amp;Save current settings</string>
</property>
</action>
<action name="actionLoad">
<property name="text">
<string>Load Color Profile</string>
<string>&amp;Load settings</string>
</property>
</action>
<action name="actionCheck_for_update">
Expand Down
33 changes: 33 additions & 0 deletions src/util/read_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python

import ConfigParser

def read_configuration(file_path):
'''
reads configuration from given file path
For two displays:
return (p_brightness, p_red, p_green, p_blue,
s_brightness, s_red, s_green, s_blue, s_reversed)
for one display:
return (p_brightness, p_red, p_green, p_blue)
'''
config = ConfigParser.RawConfigParser()
config.read(file_path)
p_brightness = config.getint('primary', 'brightness')
p_red = config.getint('primary', 'red')
p_green = config.getint('primary', 'green')
p_blue = config.getint('primary', 'blue')

if config.getboolean('primary', 'has_secondary'):
s_brightness = config.getint('secondary', 'brightness')
s_red = config.getint('secondary', 'red')
s_green = config.getint('secondary', 'green')
s_blue = config.getint('secondary', 'blue')
s_reversed = config.getboolean('secondary', 'reversed')
print (p_brightness, p_red, p_green, p_blue,
s_brightness, s_red, s_green, s_blue, s_reversed)
return (p_brightness, p_red, p_green, p_blue,
s_brightness, s_red, s_green, s_blue, s_reversed)
else:
return (p_brightness, p_red, p_green, p_blue)

69 changes: 69 additions & 0 deletions src/util/write_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env python

import ConfigParser

def write_primary_display(p_br_rgb, path):
'''
writes the configuration file as set in brightness controller
p_br_rgb - (int primary_brightness, int primary_red,
int primary_green, int primary_blue)
'''
config = ConfigParser.RawConfigParser()
config.add_section('primary')
config.set('primary', 'has_secondary', False)
if p_br_rgb is None:
config.set('primary', 'brightness', 99)
config.set('primary', 'red', 99)
config.set('primary', 'green', 99)
config.set('primary', 'blue', 99)
else:
config.set('primary', 'brightness', p_br_rgb[0])
config.set('primary', 'red', p_br_rgb[1])
config.set('primary', 'green', p_br_rgb[2])
config.set('primary', 'blue', p_br_rgb[3])

with open(path, 'wb') as configfile:
config.write(configfile)

def write_both_display(p_br_rgb, s_br_rgb, is_control_reversed, path):
'''
writes the configuration file as set in brightness controller
p_br_rgb - (int primary_brightness, int primary_red,
int primary_green, int primary_blue)
s_br_rgb - (int secondary_brightness, int secondary_red,
int secondary_green, int secondary_blue)
is_control_reversed - returns if reverse control was checked
path - the save file path
'''
config = ConfigParser.RawConfigParser()
config.add_section('primary')
config.set('primary', 'has_secondary', True)
if p_br_rgb is None:
print 'p_br_rgb is none'
config.set('primary', 'brightness', 99)
config.set('primary', 'red', 99)
config.set('primary', 'green', 99)
config.set('primary', 'blue', 99)
else:
print 'p_br_rgb is not none'
config.set('primary', 'brightness', p_br_rgb[0])
config.set('primary', 'red', p_br_rgb[1])
config.set('primary', 'green', p_br_rgb[2])
config.set('primary', 'blue', p_br_rgb[3])
config.add_section('secondary')
if s_br_rgb is None:
print 's_br_rgb is none'
config.set('secondary', 'brightness', 99)
config.set('secondary', 'red', 99)
config.set('secondary', 'green', 99)
config.set('secondary', 'blue', 99)
else:
print 's_br_rgb is not none'
config.set('secondary', 'brightness', s_br_rgb[0])
config.set('secondary', 'red', s_br_rgb[1])
config.set('secondary', 'green', s_br_rgb[2])
config.set('secondary', 'blue', s_br_rgb[3])
config.set('secondary', 'reversed', is_control_reversed)
with open(path, 'wb') as configfile:
config.write(configfile)

0 comments on commit 13baf73

Please sign in to comment.