-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
-> now can save settings -> now can load settings as well! -> small fix in UI
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
LordAmit
Author
Owner
|
||
|
||
class MyApplication(QtGui.QMainWindow): | ||
|
||
|
@@ -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): | ||
''' | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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() | ||
|
@@ -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): | ||
|
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) | ||
|
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) | ||
|
When use
from <doom> import <boom>
you do not need to addas <boom>
.So, correct one is
from os import path
. 😄