def __init__(self, loop_self): self._controller = Controller() computer = self._controller.get_computer() if computer is None: exit(1) self._computer = computer self._COMPUTER_BLOCKS_TO_SAVE = ( (True, self._computer.BLOCK_LOAD_ON_BOOT), #(True, self._computer.BLOCK_STANDBY), #(True, self._computer.BLOCK_AC_POWER), #(#True, self._computer.BLOCK_CHARGING), #(True, self._computer.BLOCK_BATT_SLEEPING), #(True, self._computer.BLOCK_BAT_POWER), #(True, self._computer.BLOCK_BATT_CRITICAL), (False, self._computer.BLOCK_LOAD_ON_BOOT)) self.loop_self = loop_self # Initialize the daemon # self._user = '******' self._paths = Paths() self._paths = Paths(self._user) self._ccp = CCParser(self._paths.CONFIGURATION_PATH, 'GUI Configuration') self._indicator_pyro = False self.reload_configurations(self._user) self._lights_state = False
def get_computers(): computers = [] path = Paths()._computers_configuration_dir for file_name in os.listdir(path): if file_name.endswith(".ini"): file_path = path + "/" + file_name computer = get_computer_by_path(file_path) if not computer is None: add = True for added_computer in computers: if computer.NAME == added_computer: print_warning("Computer name already exists={}".format( computer.NAME)) add = False break if add: computers.append(computer) computers.sort(key=lambda computer: computer.NAME) return computers
def __init__(self): self._paths = Paths() """ Glade """ builder = Gtk.Builder() builder.add_from_file(self._paths._block_testing_glade_file) builder.connect_signals(self) glade_object_names = ( 'window_block_testing', 'entry_id_vendor', 'entry_id_product', 'togglebutton_find_device', 'box_block_testing', 'spinbutton_block_speed', 'viewport_common_block', 'button_update_common_blocks', 'button_block_make_test', 'checkbutton_auto_turn_off', 'checkbutton_hex_format_when_finding', 'combobox_block_modes', 'colorbutton_1_block', 'colorbutton_2_block', 'config_grid', 'textbuffer_device_info', 'combobox_default_blocks', 'textbuffer_block_testing', 'entry_block_testing', 'box_pyusb', 'textbuffer_pyusb', 'entry_custom_command', 'button_send_custom_command', ) # load the glade objects for glade_object in glade_object_names: setattr(self, glade_object, builder.get_object(glade_object)) # get the computer info computer_device_info = get_alienware_device_info() # Fill the computer data self.textbuffer_device_info.set_text(computer_device_info) # Fill the idProduct and idVendor entries if possible if 'idVendor' in computer_device_info and 'idProduct' in computer_device_info: for line in computer_device_info.split('\n'): if 'idVendor' in line: self.entry_id_vendor.set_text(line.split()[1]) elif 'idProduct' in line: self.entry_id_product.set_text(line.split()[1]) # Display the window self.window_block_testing.show_all()
def get_computers(): computers = [] path = Paths().COMPUTERS_CONFIGURATION_FOLDER for file_name in os.listdir(path): if file_name.endswith(".ini"): file_path = path + "/" + file_name print_debug("Reading {}".format(file_path)) computer = Computer() config = ConfigParser() config.optionxform = str config.read(file_path) for key in config["COMMON"]: if hasattr(computer, key): value = config["COMMON"][key] if value != "": if key in ("NAME", "DEFAULT_MODE"): setattr(computer, key, value) else: setattr(computer, key, int(value)) for section in config.sections(): if section.startswith("REGION"): region = Region(config[section]["ID"], config[section]["DESCRIPTION"], int(config[section]["BLOCK"]), int(config[section]["SUPPORTED_COMMANDS"]), config[section]["CAN_BLINK"] == "True", config[section]["CAN_MORPH"] == "True", config[section]["CAN_LIGHT"] == "True") computer.add_region(region) add = True for added_computer in computers: if computer.NAME == added_computer: print_warning("Computer name already exists={}".format( computer.NAME)) add = False break if add: computers.append(computer) computers.sort(key=lambda computer: computer.NAME) return computers
def main(): if not AKBLConnection.ping(): gtk_dialog_info(None, TEXT_GUI_CANT_DAEMON_OFF, icon=Paths()._small_icon_file) else: GObject.threads_init() Gdk.threads_init() GUI() Gtk.main()
def __init__(self): self.daemon = Pyro4.Daemon() self.paths = Paths() uri = self.daemon.register(Daemon(self)) with open(self.paths._daemon_pyro_file, encoding='utf-8', mode='wt') as f: f.write(str(uri)) self.daemon.requestLoop()
def set_profile(self, user, profile): """ Set a profile from the existing profiles. + 'profile' is the profile name """ if user != self._user: self._user = user self._paths = Paths(user) self.reload_configurations(user, False, False) if profile in theme_factory._AVAILABLE_THEMES.keys(): self._theme = theme_factory._AVAILABLE_THEMES[profile] self._iluminate_keyboard()
def __init__(self, self_main): self._ = self_main self.paths = Paths() # Status variables for the loop # self.current_code = None self.check_daemon = True # GUI stuff # self.indicator = appindicator.Indicator.new_with_path( 'akbl-indicator', self.paths.INDICATOR_NO_DAEMON_ICON, appindicator.IndicatorCategory.APPLICATION_STATUS, os.path.dirname(os.path.realpath(__file__))) self.indicator.set_status(appindicator.IndicatorStatus.ACTIVE) self.menu = Gtk.Menu() self.profiles_menu = Gtk.MenuItem(label=TEXT_PROFILES) self.menu.append(self.profiles_menu) self.submenu_profiles = Gtk.Menu() self.profiles_menu.set_submenu(self.submenu_profiles) item = Gtk.MenuItem(label=TEXT_START_THE_GUI) item.connect('activate', self.on_menuitem_gui) self.menu.append(item) self.switch_state = Gtk.MenuItem(label=TEXT_SWICH_STATE) self.switch_state.connect('activate', self.on_menuitem_change) self.menu.append(self.switch_state) item = Gtk.MenuItem(TEXT_EXIT) item.connect('activate', self.on_menuitem_exit) self.menu.append(item) self.menu.show_all() self.indicator.set_menu(self.menu) self.set_code(666) threading.Thread(target=self.daemon_check).start()
def reload_configurations(self, user, indicator=True, set_default=True): if user != self._user: self._user = user self._paths = Paths(user) self._ccp.set_configuration_path(self._paths.CONFIGURATION_PATH) Theme.LOAD_profiles(self._computer, self._paths.PROFILES_PATH) if set_default: _, profile_name = Theme.GET_last_configuration() self._theme = Theme.get_theme_by_name(profile_name) if self._indicator_pyro and indicator: try: self._indicator_pyro.load_profiles( Theme.AVAILABLE_THEMES.keys(), self._theme.name, self._lights_state) except Exception: print_error(format_exc())
def reload_configurations(self, user, indicator=True, set_default=True): if user != self._user: self._user = user self._paths = Paths(user) self._ccp.set_configuration_path(self._paths._configuration_file) theme_factory.LOAD_profiles(self._computer, self._paths._profiles_dir) if set_default: _, profile_name = theme_factory.GET_last_configuration() self._theme = theme_factory.get_theme_by_name(profile_name) if self._indicator_pyro and indicator: try: self._indicator_pyro.load_profiles( theme_factory._AVAILABLE_THEMES.keys(), self._theme.name, self._lights_state) except Exception: print_error(format_exc())
# You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import gi gi.require_version('Gtk', '3.0') gi.require_version('AppIndicator3', '0.1') from gi.repository import Gtk import os import subprocess from AKBL.texts import (TEXT_ONLY_ROOT) from AKBL.utils import getuser from AKBL.Paths import Paths _SOFTWARE_PATHS = Paths() from AKBL.Engine.Driver import Driver import AKBL.Data.Computer.factory as computer_factory from AKBL.Addons.gtk_utils import gtk_dialog_info, gtk_dialog_question from AKBL.Addons.ModelChooser.texts import _TEXT_NO_COMPUTER_MODEL_WANT_TO_QUIT _EMPTY_MODEL = "<NONE>" def get_alienware_device_info(): bash_output = subprocess.run("lsusb", shell=True, stdout=subprocess.PIPE,
def __init__(self): self._paths = Paths() # Glade # builder = Gtk.Builder() builder.add_from_file(self._paths.GLADE_FILE) builder.connect_signals(self) glade_object_names = ( 'window_root', 'menubar', 'menuitem_profile', 'menuitem_options', 'checkbutton_autosave', 'checkbutton_profile_buttons', 'checkbutton_delete_warning', 'menuitem_off_areas', 'liststore_profiles', 'combobox_profiles', 'tempobutton', 'box_profile_buttons', 'horizontal_main_box', 'box_area_labels', 'box_areas', 'label_user_message', 'scrolledwindow_no_computer', 'window_new_profile', 'entry_new_profile', 'button_new_profile_create', 'window_about', 'window_computer_data', 'textbuffer_computer_data') for glade_object in glade_object_names: setattr(self, glade_object, builder.get_object(glade_object)) """ Add the accel groups """ for _id, shorcut in (('imagemenuitem_apply_configuration', 'a'), ('imagemenuitem_save', 's'), ('imagemenuitem_delete', 'd'), ('imagemenuitem_new', 'n'), ('imagemenuitem_quit', 'q'), ('button_lights_on', 'o'), ('button_lights_off', 'f'), ('imagemenuitem_export', 'e'), ('imagemenuitem_import', 'i')): imagemenuitem_apply_configuration = builder.get_object(_id) accel_group = Gtk.AccelGroup() self.window_root.add_accel_group(accel_group) imagemenuitem_apply_configuration.add_accelerator( 'activate', accel_group, ord(shorcut), Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE) """ Ask to the user if he wants to import its global configuration (this is a support for older versions of alienware-kbl) """ if (not os.path.exists(self._paths.CONFIGURATION_PATH) and os.path.exists(self._paths.BACKUP_CONFIG)) or \ (not os.path.exists(self._paths.PROFILES_PATH) and os.path.exists(self._paths.BACKUP_PROFILES)): self.window_root.hide() if gtk_dialog_question(self.window_root, TEXT_COPY_CONFIG, icon=self._paths.SMALL_ICON): from distutils.dir_util import copy_tree if not os.path.exists( os.path.dirname(self._paths.CONFIGURATION_PATH)): print_warning('Adding the configuration {}'.format( self._paths.CONFIGURATION_PATH)) os.makedirs(os.path.dirname( self._paths.CONFIGURATION_PATH)) if not os.path.exists(self._paths.PROFILES_PATH): os.makedirs(self._paths.PROFILES_PATH) shutil.copyfile(self._paths.BACKUP_CONFIG, self._paths.CONFIGURATION_PATH) copy_tree(self._paths.BACKUP_PROFILES, self._paths.PROFILES_PATH) self.window_root.show() self.apply_configuration = False self.queue_zones = [] self.ccp = CCParser(self._paths.CONFIGURATION_PATH, 'GUI Configuration') # # self.color_chooser_toolbar = ColorChooserToolbar(self) self.color_chooser_toolbar.set_orientation(Gtk.Orientation.VERTICAL) self.color_chooser_toolbar.connect("colorlist-changed", self.on_toolbar_colorlist_changed) default_toolbar_colors = self.ccp.get_list('toolbar_colors') if len(default_toolbar_colors) > 0: self.color_chooser_toolbar.set_colors(default_toolbar_colors) # Load a configuration # computer_name = AKBLConnection._command('get_computer_name') self.computer = get_computer(computer_name) Theme.LOAD_profiles(self.computer, self._paths.PROFILES_PATH) self.POPULATE_liststore_profiles() """ Extra GUI initialization """ computer_data = AKBLConnection._command('get_computer_info') self.textbuffer_computer_data.set_text( TEXT_COMPUTER_DATA.format(*computer_data[0:5])) # Add the areas to the "menuitem_off_areas" # self.menu_turn_off_areas = Gtk.Menu() self.areas_description_dict = dict( (area.description, area.name) for area in self.theme.get_areas()) active_configuration_areas = self.ccp.get_str_defval( 'areas_to_keep_on', '').split('|') for description, area in sorted(self.areas_description_dict.items(), key=lambda x: x[0]): checkbox = Gtk.CheckMenuItem(label=description) if area in active_configuration_areas: checkbox.set_active(True) checkbox.connect('activate', self.on_checkbox_turnoff_areas_changed) self.menu_turn_off_areas.append(checkbox) self.menuitem_off_areas.set_submenu(self.menu_turn_off_areas) # Extra stuff # self.horizontal_main_box.add(self.color_chooser_toolbar) self.horizontal_main_box.reorder_child(self.color_chooser_toolbar, 0) self.checkbutton_autosave.set_active( self.ccp.get_bool_defval('auto_save', True)) self.checkbutton_profile_buttons.set_active( self.ccp.get_bool_defval('profile_buttons', False)) self.checkbutton_delete_warning.set_active( self.ccp.get_bool_defval('delete_warning', True)) self.POPULATE_box_areas() self.window_root.show_all() if not self.checkbutton_profile_buttons.get_active(): self.box_profile_buttons.hide() self.scrolledwindow_no_computer.hide()
from AKBL.Data.Computer.factory import get_computer from AKBL.utils import print_error, print_warning from AKBL.Bindings import Bindings from AKBL.CCParser import CCParser from AKBL.Paths import Paths from AKBL.Addons.GUI.ZoneWidget import ZoneWidget from AKBL.texts import ( TEXT_COPY_CONFIG, TEXT_COMPUTER_DATA, TEXT_ADD, TEXT_CONFIRM_DELETE_CONFIGURATION, TEXT_CONFIGURATION_DELETED, TEXT_SHUTTING_LIGHTS_OFF, TEXT_APPLYING_CONFIGURATION, TEXT_SAVING_THE_CONFIGURATION, TEXT_THEME_ALREADY_EXISTS, TEXT_CHOOSE_A_THEME, TEXT_CHOOSE_A_FOLDER_TO_EXPORT, TEXT_MAXIMUM_NUMBER_OF_ZONES_REACHED, TEXT_GUI_CANT_DAEMON_OFF) os.chdir(Paths().MAIN) # this is important for the rest of the code. def get_text_gtk_buffer(textbuffer): return textbuffer.get_text(textbuffer.get_start_iter(), textbuffer.get_end_iter(), True) def gtk_append_text_to_buffer(textbuffer, text): textbuffer.set_text(get_text_gtk_buffer(textbuffer) + text) def gtk_dialog_question(parent, text1, text2=None, icon=None): dialog = Gtk.MessageDialog(parent, Gtk.DialogFlags.MODAL, Gtk.MessageType.QUESTION,
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, Gdk from gi.repository import GObject import cairo from AKBL.utils import print_warning from AKBL.Paths import Paths _IMAGES_PATH = Paths()._images_dir _LEFT_CLICK_ID = 1 _RIGHT_CLICK_ID = 3 _BUTTONS_IMAGE_PATTERN = [ 'empty', 'fixed_on', 'morph_on', 'blink_on', 'empty', 'fixed_off', 'morph_off', 'blink_off' ] _BUTTONS_IMAGE_PATTERN_WITH_DELETE = [ 'cross_on', 'fixed_on', 'morph_on', 'blink_on', 'cross_off', 'fixed_off', 'morph_off', 'blink_off' ] class ZoneWidget(Gtk.Frame):
def __init__(self): self._address = None self._pyro = None self._paths = Paths() self._user = getpass.getuser() self.reload_address()
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import sys import os from AKBL.Bindings import Bindings from AKBL.Paths import Paths from AKBL.texts import (TEXT_ERROR_DAEMON_OFF, TEXT_HELP, TEXT_LICENSE, TEXT_WRONG_ARGUMENT) AKBLConnection = Bindings() PATHS = Paths() __version__ = None #TO BE REPLACED IN THE SETUP FILE def send_command(command, *args): if not os.path.exists(PATHS._systemctl_dir) or not AKBLConnection.ping(): print(TEXT_ERROR_DAEMON_OFF) else: AKBLConnection._command(command, *args) if __name__ == '__main__': total = len(sys.argv)
# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, Gdk from gi.repository import GObject import cairo from AKBL.utils import print_warning from AKBL.Paths import Paths _IMAGES_PATH = Paths().IMAGES _LEFT_CLICK_ID = 1 _RIGHT_CLICK_ID = 3 _BUTTONS_IMAGE_PATTERN = [ 'empty', 'fixed_on', 'morph_on', 'blink_on', 'empty', 'fixed_off', 'morph_off', 'blink_off' ] _BUTTONS_IMAGE_PATTERN_WITH_DELETE = [ 'cross_on', 'fixed_on', 'morph_on', 'blink_on', 'cross_off', 'fixed_off', 'morph_off', 'blink_off' ] class ZoneWidget(Gtk.Frame):
def __init__(self): self._paths = Paths() # Glade # builder = Gtk.Builder() builder.add_from_file(self._paths._gui_glade_file) builder.connect_signals(self) glade_object_names = ( 'window_root', 'menubar', 'menuitem_profile', 'menuitem_options', 'checkbutton_autosave', 'checkbutton_profile_buttons', 'checkbutton_delete_warning', 'menuitem_off_areas', 'liststore_profiles', 'combobox_profiles', 'tempobutton', 'label_computer_model', 'box_profile_buttons', 'horizontal_main_box', 'box_area_labels', 'box_areas', 'label_user_message', 'window_new_profile', 'entry_new_profile', 'button_new_profile_create', 'window_about') for glade_object in glade_object_names: setattr(self, glade_object, builder.get_object(glade_object)) """ Add the accel groups """ for _id, shorcut in (('imagemenuitem_apply_configuration', 'a'), ('imagemenuitem_save', 's'), ('imagemenuitem_delete', 'd'), ('imagemenuitem_new', 'n'), ('imagemenuitem_quit', 'q'), ('button_lights_on', 'o'), ('button_lights_off', 'f'), ('imagemenuitem_export', 'e'), ('imagemenuitem_import', 'i')): imagemenuitem_apply_configuration = builder.get_object(_id) accel_group = Gtk.AccelGroup() self.window_root.add_accel_group(accel_group) imagemenuitem_apply_configuration.add_accelerator('activate', accel_group, ord(shorcut), Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE) self.ccp = CCParser(self._paths._configuration_file, 'GUI Configuration') # # self.color_chooser_toolbar = ColorChooserToolbar(self) self.color_chooser_toolbar.set_orientation(Gtk.Orientation.VERTICAL) self.color_chooser_toolbar.connect("colorlist-changed", self.on_toolbar_colorlist_changed) default_toolbar_colors = self.ccp.get_list('toolbar_colors') if len(default_toolbar_colors) > 0: self.color_chooser_toolbar.set_colors(default_toolbar_colors) # Load a configuration # computer_name = AKBLConnection._command('get_computer_name') self.computer = get_computer(computer_name) self.label_computer_model.set_text(computer_name) theme_factory.LOAD_profiles(self.computer, self._paths._profiles_dir) self.POPULATE_liststore_profiles() """ Extra GUI initialization """ # Add the areas to the "menuitem_off_areas" # self.menu_turn_off_areas = Gtk.Menu() self.areas_description_dict = dict((area.description, area.name) for area in self.theme.get_areas()) active_configuration_areas = self.ccp.get_str_defval('areas_to_keep_on', '').split('|') for description, area in sorted(self.areas_description_dict.items(), key=lambda x: x[0]): checkbox = Gtk.CheckMenuItem(label=description) if area in active_configuration_areas: checkbox.set_active(True) checkbox.connect('activate', self.on_checkbox_turnoff_areas_changed) self.menu_turn_off_areas.append(checkbox) self.menuitem_off_areas.set_submenu(self.menu_turn_off_areas) # Extra stuff # self.horizontal_main_box.add(self.color_chooser_toolbar) self.horizontal_main_box.reorder_child(self.color_chooser_toolbar, 0) self.checkbutton_autosave.set_active(self.ccp.get_bool_defval('auto_save', True)) self.checkbutton_profile_buttons.set_active(self.ccp.get_bool_defval('profile_buttons', False)) self.checkbutton_delete_warning.set_active(self.ccp.get_bool_defval('delete_warning', True)) self.POPULATE_box_areas() self.window_root.show_all() if not self.checkbutton_profile_buttons.get_active(): self.box_profile_buttons.hide()
from AKBL.texts import (TEXT_ADD, TEXT_CONFIRM_DELETE_CONFIGURATION, TEXT_CONFIGURATION_DELETED, TEXT_SHUTTING_LIGHTS_OFF, TEXT_APPLYING_CONFIGURATION, TEXT_SAVING_THE_CONFIGURATION, TEXT_THEME_ALREADY_EXISTS, TEXT_CHOOSE_A_THEME, TEXT_CHOOSE_A_FOLDER_TO_EXPORT, TEXT_MAXIMUM_NUMBER_OF_ZONES_REACHED, TEXT_GUI_CANT_DAEMON_OFF) os.chdir(Paths()._akbl_module_dir) # this is important for the rest of the code. # 12/11/2018, why? the code should work even without this.. class GUI(Gtk.Window): def __init__(self): self._paths = Paths() # Glade # builder = Gtk.Builder() builder.add_from_file(self._paths._gui_glade_file) builder.connect_signals(self)