def parse(main_window): """Prepares the UI for executing the xkill command""" tools.debug_output(__name__, 'parse', 'starting', 1) main_window.status_notification_reset( ) # Reset status notification back to OK main_window.plugin__update_general_ui_information( 'Kill') # update plugin info icon_size = ini.read_single_ini_value('General', 'icon_size') # get preference value ## command button & txt main_window.ui__bt_command_img = wx.Image( 'gfx/plugins/kill/' + icon_size + '/kill.png', wx.BITMAP_TYPE_PNG) main_window.ui__bt_command.SetBitmap( main_window.ui__bt_command_img.ConvertToBitmap()) main_window.ui__bt_command.SetToolTipString( 'Kill application by selecting a window with your cursor') main_window.ui__txt_command.SetValue('xkill') ## parameter button & txt main_window.ui__bt_parameter.SetToolTipString('Start rampage') main_window.ui__bt_parameter_img = wx.Image( 'gfx/core/' + icon_size + '/execute.png', wx.BITMAP_TYPE_PNG) main_window.ui__bt_parameter.SetBitmap( main_window.ui__bt_parameter_img.ConvertToBitmap()) main_window.ui__txt_parameter.SetValue('')
def validate(): """Validate the entire ini""" check_if_ini_exists() # https://pymotw.com/3/configparser/ tools.debug_output( __name__, 'validate', 'Validating ini (' + constants.APP_INI_PATH + ') for existing sections and options', 1) ## Section: Language SECTIONS = ['Language'] OPTIONS = ['lang'] validate_single_section(SECTIONS, OPTIONS) ## Section: General SECTIONS = ['General'] OPTIONS = ['hide_ui_after_command_execution', 'icon_size', 'transparency'] validate_single_section(SECTIONS, OPTIONS) ## Section: Statistics SECTIONS = ['Statistics'] OPTIONS = ['apparat_started', 'command_executed', 'plugin_executed'] validate_single_section(SECTIONS, OPTIONS) ## Section: Plugins SECTIONS = ['Plugins'] OPTIONS = [ 'plugin_kill', 'plugin_misc', 'plugin_nautilus', 'plugin_passwordgen', 'plugin_screenshot', 'plugin_search_internet', 'plugin_search_local', 'plugin_session', 'plugin_shell' ] validate_single_section(SECTIONS, OPTIONS) tools.debug_output( __name__, 'validate', 'Finished validating complete ini (' + constants.APP_INI_PATH + ')', 1)
def on_tray_popup_click_github(self, event): """Method to handle click on the 'GitHub' tray menu item""" tools.debug_output(__name__, 'on_tray_popup_click_github', 'starting with event: ' + str(event), 1) tools.debug_output(__name__, 'on_tray_popup_click_github', 'Opening: ' + constants.APP_URL, 1) webbrowser.open(constants.APP_URL) # Go to github
def prepare_plugin_nautilus_show_network_devices(main_window, icon_size): """Plugin Nautilus - Network - Opens network view in nautilus""" tools.debug_output(__name__, 'prepare_plugin_nautilus_show_network_devices', 'starting', 1) ## update plugin info main_window.plugin__update_general_ui_information('Nautilus (Network)') ## command button & txt main_window.ui__bt_command_img = wx.Image( 'gfx/plugins/nautilus/' + icon_size + '/network.png', wx.BITMAP_TYPE_PNG) main_window.ui__bt_command.SetBitmap( main_window.ui__bt_command_img.ConvertToBitmap()) main_window.ui__bt_command.SetToolTipString('Show network devices') main_window.ui__txt_command.SetValue('nautilus') ## parameter button & txt main_window.ui__bt_parameter.SetToolTipString('Open') main_window.ui__bt_parameter_img = wx.Image( 'gfx/core/' + icon_size + '/execute.png', wx.BITMAP_TYPE_PNG) main_window.ui__bt_parameter.SetBitmap( main_window.ui__bt_parameter_img.ConvertToBitmap()) main_window.ui__txt_parameter.SetValue('network://')
def prepare_plugin_nautilus_goto(main_window, icon_size): """Plugin Nautilus - GoTo - Opens a path in nautilus""" tools.debug_output(__name__, 'prepare_plugin_nautilus_goto', 'starting', 1) ## update plugin info main_window.plugin__update_general_ui_information('Nautilus (GoTo)') ## command button & txt main_window.ui__bt_command_img = wx.Image( 'gfx/plugins/nautilus/' + icon_size + '/goto.png', wx.BITMAP_TYPE_PNG) main_window.ui__bt_command.SetBitmap( main_window.ui__bt_command_img.ConvertToBitmap()) main_window.ui__bt_command.SetToolTipString('Go to folder') main_window.ui__txt_command.SetValue('nautilus') ## parameter button & txt main_window.ui__bt_parameter.SetToolTipString('Open') main_window.ui__bt_parameter_img = wx.Image( 'gfx/core/' + icon_size + '/execute.png', wx.BITMAP_TYPE_PNG) main_window.ui__bt_parameter.SetBitmap( main_window.ui__bt_parameter_img.ConvertToBitmap()) ## set parameter txt if (main_window.ui__cb_search.GetValue()[6:7] == '~'): tools.debug_output(__name__, 'prepare_plugin_nautilus_goto', 'Replacing ~', 1) home = os.environ['HOME'] main_window.ui__txt_parameter.SetValue( home + main_window.ui__cb_search.GetValue()[7:]) # possible parameter else: main_window.ui__txt_parameter.SetValue( main_window.ui__cb_search.GetValue()[6:]) # possible parameter
def __init__(self, frame): """Method to initialize the tray icon""" tools.debug_output(__name__, '__init__ (TaskBarIcon)', 'starting', 1) self.frame = frame super(TaskBarIcon, self).__init__() self.set_tray_icon(constants.APP_TRAY_ICON) self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.on_app_tray_icon_left_click) tools.debug_output(__name__, '__init__ (TaskBarIcon)', 'Task icon is ready now', 1)
def create_menu_item(menu, label, func, enable=True): """Generates single menu items for the tray icon popup menu""" tools.debug_output(__name__, 'create_menu_item', 'Menuitem: ' + label, 1) item = wx.MenuItem(menu, -1, label) menu.Bind(wx.EVT_MENU, func, id=item.GetId()) menu.AppendItem(item) if enable is False: item.Enable(False) return item
def execute_tray_icon_left_click(self): """Method to handle left click on the tray icon - toggles visibility of the Main Window""" if self.frame.IsIconized(): # if main window is minimized tools.debug_output(__name__, 'execute_tray_icon_left_click', 'MainWindow is now visible', 1) self.frame.Raise() else: # if main window is shown tools.debug_output(__name__, 'execute_tray_icon_left_click', 'MainWindow is now hidden/minimized', 1) self.frame.Iconize(True)
def generate_xkcd_password(): """Generated an xkcd like password - see: https://xkcd.com/936/""" single = '' full = '' for _ in range(0, 5): single = get_random_word() single = single.rstrip() full = full+' '+single tools.debug_output(__name__, 'generate_xkcd_password', 'Finished generating an xkcd-like password', 1) return full
def on_change_icon_size(self, event): """Handles the value change of icon_size dropbox""" tools.debug_output( __name__, 'on_change_icon_size', 'Preference - General - change icon size: ' + str(event), 1) tools.debug_output( __name__, 'on_change_icon_size', 'New icon size is set to: ' + str(self.ui__cb_iconsizes.GetValue()) + 'px', 1) ini.write_single_ini_value( 'General', 'icon_size', self.ui__cb_iconsizes.GetValue()) # update preference value
def parse(main_window, current_search_string): """Updates the UI according to the matching internet-search trigger""" tools.debug_output(__name__, 'prepare_internet_search', 'starting', 1) ## Reset status notification back to OK main_window.status_notification_got_distinct_result() icon_size = ini.read_single_ini_value('General', 'icon_size') # get preference value ## show searchstring in parameter field if (main_window.ui__txt_command.GetValue() != ''): cur_searchphrase_parameter = current_search_string[ 3:] # remove trigger - example: '!y ' main_window.ui__txt_parameter.SetValue(cur_searchphrase_parameter) ## check if there is NO space after the trigger - abort this function and reset some parts of the UI if (len(current_search_string) >= 4) and (current_search_string[3] != " "): tools.debug_output(__name__, 'parse', 'No space after trigger - should reset icons', 1) main_window.plugin__update_general_ui_information('') main_window.status_notification_display_error('Invalid input') return ## If search-string > 3 - abort - as all the work is already done # if (len(current_search_string) > 3): return # we can stop here - nothing more to do as plugin should be already activated # get tuple position of command index = TRIGGER.index(current_search_string) # get icon-name based on tuple index icon = 'gfx/plugins/search_internet/' + icon_size + '/' + ICONS[index] # get description based on tuple index description = DESCRIPTIONS[index] # update UI with icon and description main_window.ui__bt_command_img = wx.Image(icon, wx.BITMAP_TYPE_PNG) main_window.plugin__update_general_ui_information(description) ## command button main_window.ui__bt_command.Enable(True) main_window.ui__bt_command.SetBitmap( main_window.ui__bt_command_img.ConvertToBitmap()) ## parameter button main_window.ui__bt_parameter_img = wx.Image( 'gfx/core/' + icon_size + '/search.png', wx.BITMAP_TYPE_PNG) main_window.ui__bt_parameter.Enable(True) main_window.ui__bt_parameter.SetBitmap( main_window.ui__bt_parameter_img.ConvertToBitmap()) main_window.ui__bt_parameter.SetToolTipString('Search')
def on_change_transparency(self, event): """Handles the value change of transparency dropbox""" tools.debug_output( __name__, 'on_change_transparency', 'Preference - General - change transparency: ' + str(event), 1) tools.debug_output( __name__, 'on_change_transparency', 'New transparency value is set to: ' + str(self.ui__cb_transparency.GetValue()), 1) ini.write_single_ini_value( 'General', 'transparency', self.ui__cb_transparency.GetValue()) # update preference value
def parse(current_search_string, main_window): """Validates input and loads the command related sub function""" tools.debug_output(__name__, 'prepare_general', 'starting', 1) ## Reset status notification back to OK main_window.status_notification_reset() icon_size = ini.read_single_ini_value('General', 'icon_size') # get preference value ## Selective Screenshot # if current_search_string == "!ss": tools.debug_output(__name__, 'parse', 'Case: Selective Screenshot', 1) prepare_selective_screenshot(main_window, icon_size) ## Full Screenshot # elif current_search_string == "!fs": tools.debug_output(__name__, 'parse', 'Case: Full Screenshot', 1) prepare_full_screenshot(main_window, icon_size) ## Invalid input # else: tools.debug_output(__name__, 'parse', 'Error: Unexpected screenshot plugin command', 3) main_window.status_notification_display_error('Unexpected screenshot plugin command') return
def on_tray_popup_click_about(self, event): """Method to handle click in the 'About' tray menu item""" tools.debug_output(__name__, 'on_tray_popup_click_about', 'starting with event: ' + str(event), 1) aboutInfo = wx.AboutDialogInfo() aboutInfo.SetName(constants.APP_NAME) aboutInfo.SetVersion(version.APP_VERSION) aboutInfo.SetDescription((constants.APP_DESCRIPTION)) aboutInfo.SetLicense(open("../LICENSE").read()) aboutInfo.SetWebSite(constants.APP_URL) aboutInfo.SetIcon( wx.Icon('gfx/core/128/appIcon.png', wx.BITMAP_TYPE_PNG, 128, 128)) aboutInfo.AddDeveloper("yafp") #aboutInfo.AddDeveloper('Name of other contributors') # additional devs/contributors wx.AboutBox(aboutInfo)
def write_single_ini_value(section_name, key_name, value): """Method to write a single value to the configuration file apparat.ini""" try: config = ConfigParser.ConfigParser() config.read(constants.APP_INI_PATH) config.set(section_name, key_name, value) tools.debug_output( __name__, 'write_single_ini_value', 'Section: ' + section_name + ' - Key: ' + key_name + ' - Value: ' + str(value), 1) with open(constants.APP_INI_PATH, 'wb') as configfile: config.write(configfile) except ConfigParser.NoSectionError: tools.debug_output(__name__, 'write_single_ini_value', 'Section ' + section_name + ' does not exist.', 3) return
def prepare_plugin_passwordgen(main_window, icon_size): """Prepares UI for plugin PasswordGen""" tools.debug_output(__name__, 'prepare_plugin_passwordgen', 'starting', 1) main_window.plugin__update_general_ui_information('Password Generator') ## update plugin info ## command button & txt main_window.ui__bt_command_img = wx.Image('gfx/plugins/passwordgen/'+icon_size+'/password.png', wx.BITMAP_TYPE_PNG) main_window.ui__bt_command.SetBitmap(main_window.ui__bt_command_img.ConvertToBitmap()) main_window.ui__bt_command.SetToolTipString('Password Generator') ## parameter button main_window.ui__bt_parameter.SetToolTipString('Generate') main_window.ui__bt_parameter_img = wx.Image('gfx/core/'+icon_size+'/execute.png', wx.BITMAP_TYPE_PNG) main_window.ui__bt_parameter.SetBitmap(main_window.ui__bt_parameter_img.ConvertToBitmap()) tools.debug_output(__name__, 'prepare_plugin_passwordgen', 'Finished preparing password UI', 1)
def prepare_plugin_shell(main_window, icon_size): """Plugin Shell""" tools.debug_output(__name__, 'prepare_plugin_shell', 'starting', 1) main_window.plugin__update_general_ui_information('Shell') # update plugin info ## command button & txt main_window.ui__bt_command_img = wx.Image('gfx/plugins/shell/'+icon_size+'/shell.png', wx.BITMAP_TYPE_PNG) main_window.ui__bt_command.SetBitmap(main_window.ui__bt_command_img.ConvertToBitmap()) main_window.ui__bt_command.SetToolTipString('Execute terminal command') main_window.ui__txt_command.SetValue('x-terminal-emulator') ## parameter button & txt main_window.ui__bt_parameter.SetToolTipString('Run') main_window.ui__bt_parameter_img = wx.Image('gfx/core/'+icon_size+'/execute.png', wx.BITMAP_TYPE_PNG) main_window.ui__bt_parameter.SetBitmap(main_window.ui__bt_parameter_img.ConvertToBitmap()) main_window.ui__txt_parameter.SetValue('-e '+main_window.ui__cb_search.GetValue()[4:])
def prepare_plugin_session_logout(main_window, icon_size): """Plugin Session - Logout""" tools.debug_output(__name__, 'prepare_plugin_session_logout', 'starting', 1) ## update plugin info main_window.plugin__update_general_ui_information('Session (Logout)') ## command button & txt main_window.ui__bt_command_img = wx.Image('gfx/plugins/session/'+icon_size+'/logout.png', wx.BITMAP_TYPE_PNG) main_window.ui__bt_command.SetBitmap(main_window.ui__bt_command_img.ConvertToBitmap()) main_window.ui__bt_command.SetToolTipString('Logout Session') main_window.ui__txt_command.SetValue('gnome-session-quit') ## parameter button & txt main_window.ui__bt_parameter.SetToolTipString('Launch') main_window.ui__bt_parameter_img = wx.Image('gfx/core/'+icon_size+'/execute.png', wx.BITMAP_TYPE_PNG) main_window.ui__bt_parameter.SetBitmap(main_window.ui__bt_parameter_img.ConvertToBitmap()) main_window.ui__txt_parameter.SetValue('--logout')
def CreatePopupMenu(self): # pylint:disable=invalid-name """Method to generate a Popupmenu for the TrayIcon (do NOT rename)""" tools.debug_output(__name__, 'CreatePopupMenu', 'starting', 1) menu = wx.Menu() create_menu_item(menu, "Version " + version.APP_VERSION, self.on_tray_popup_click_github, enable=False) # disabled menu menu.AppendSeparator() create_menu_item(menu, 'Show', self.on_tray_popup_left_show) menu.AppendSeparator() create_menu_item(menu, 'Preferences', self.on_tray_popup_click_preferences) create_menu_item(menu, 'About', self.on_tray_popup_click_about) create_menu_item(menu, 'GitHub', self.on_tray_popup_click_github) menu.AppendSeparator() create_menu_item(menu, 'Exit', self.on_tray_popup_click_exit) return menu
def prepare_plugin_session_hibernate(main_window, icon_size): """Plugin Session - Hibernate""" tools.debug_output(__name__, 'prepare_plugin_session_hibernate', 'starting', 1) ## update plugin info main_window.plugin__update_general_ui_information('Session (Hibernate)') ## command button & txt main_window.ui__bt_command_img = wx.Image('gfx/plugins/session/'+icon_size+'/hibernate.png', wx.BITMAP_TYPE_PNG) main_window.ui__bt_command.SetBitmap(main_window.ui__bt_command_img.ConvertToBitmap()) main_window.ui__bt_command.SetToolTipString('Hibernate machine') main_window.ui__txt_command.SetValue('systemctl') ## parameter button & txt main_window.ui__bt_parameter.SetToolTipString('Launch') main_window.ui__bt_parameter_img = wx.Image('gfx/core/'+icon_size+'/execute.png', wx.BITMAP_TYPE_PNG) main_window.ui__bt_parameter.SetBitmap(main_window.ui__bt_parameter_img.ConvertToBitmap()) main_window.ui__txt_parameter.SetValue('suspend')
def prepare_full_screenshot(main_window, icon_size): """Prepare UI for full screenshot""" tools.debug_output(__name__, 'prepare_full_screenshot', 'starting', 1) ## update plugin info main_window.plugin__update_general_ui_information('Screenshot (Full)') ## command button & txt main_window.ui__bt_command_img = wx.Image('gfx/plugins/screenshot/'+icon_size+'/screenshot_full.png', wx.BITMAP_TYPE_PNG) main_window.ui__bt_command.SetBitmap(main_window.ui__bt_command_img.ConvertToBitmap()) main_window.ui__bt_command.SetToolTipString('Full Screenshot') main_window.ui__txt_command.SetValue('import') ## parameter button & txt main_window.ui__bt_parameter.SetToolTipString('Do') main_window.ui__bt_parameter_img = wx.Image('gfx/core/'+icon_size+'/execute.png', wx.BITMAP_TYPE_PNG) main_window.ui__bt_parameter.SetBitmap(main_window.ui__bt_parameter_img.ConvertToBitmap()) ## parameter txt current_timestamp = tools.generate_timestamp() parameter = '-window root '+os.environ['HOME']+'/'+current_timestamp+'_full.png' main_window.ui__txt_parameter.SetValue(parameter)
def on_plugin_checkbox_change(self, event): """Triggered if a checkbox state is changing and writes the new state to ini""" btn = event.GetEventObject().GetLabel() # button label value = event.GetEventObject().GetValue() # button value ui_element = event.GetEventObject() # object itself if value is True: check_requirements = requirements.check_plugin_requirements( btn ) # check if requirements for this plugin are fulfilled, otherwise enabling doesnt make sense if check_requirements is True: tools.debug_output(__name__, 'on_plugin_checkbox_change', 'Enabled Plugin: ' + btn, 1) ini.write_single_ini_value('Plugins', 'plugin_' + btn, 'True') else: tools.debug_output( __name__, 'on_plugin_checkbox_change', 'Can not enable plugin: ' + btn + ' due to missing requirements', 3) ui_element.SetValue(False) ini.write_single_ini_value('Plugins', 'plugin_' + btn, 'False') wx.MessageBox( 'Plugin can not be enabled because of missing requirements', 'Error', wx.OK | wx.ICON_WARNING) else: tools.debug_output(__name__, 'on_plugin_checkbox_change', 'Disabled Plugin: ' + btn, 1) ini.write_single_ini_value('Plugins', 'plugin_' + btn, 'False')
def prepare_plugin_nautilus_open_trash(main_window, icon_size): """Plugin Nautilus - Trash - Opens trash in nautilus""" tools.debug_output(__name__, 'prepare_plugin_nautilus_open_trash', 'starting', 1) ## update plugin info main_window.plugin__update_general_ui_information('Nautilus (Trash)') ## command button & txt main_window.ui__bt_command_img = wx.Image( 'gfx/plugins/nautilus/' + icon_size + '/trash.png', wx.BITMAP_TYPE_PNG) main_window.ui__bt_command.SetBitmap( main_window.ui__bt_command_img.ConvertToBitmap()) main_window.ui__bt_command.SetToolTipString('Open Trash') main_window.ui__txt_command.SetValue('nautilus') ## parameter button & txt main_window.ui__bt_parameter.SetToolTipString('Open') main_window.ui__bt_parameter_img = wx.Image( 'gfx/core/' + icon_size + '/execute.png', wx.BITMAP_TYPE_PNG) main_window.ui__bt_parameter.SetBitmap( main_window.ui__bt_parameter_img.ConvertToBitmap()) main_window.ui__txt_parameter.SetValue('trash://')
def parse(current_search_string, main_window): """parse""" tools.debug_output(__name__, 'parse', 'starting with searchstring: '+current_search_string, 1) # Reset status notification back to OK main_window.status_notification_reset() icon_size = ini.read_single_ini_value('General', 'icon_size') # get preference value ## Hibernate if current_search_string == '!hibernate' or current_search_string == '!sleep': prepare_plugin_session_hibernate(main_window, icon_size) ## Lock elif current_search_string == '!lock': prepare_plugin_session_lock(main_window, icon_size) ## Logout elif current_search_string == '!logout': prepare_plugin_session_logout(main_window, icon_size) ## Reboot elif current_search_string == '!reboot' or current_search_string == '!restart': prepare_plugin_session_reboot(main_window, icon_size) ## Shutdown elif current_search_string == '!shutdown' or current_search_string == '!halt': prepare_plugin_session_shutdown(main_window, icon_size) ## Screensaver elif current_search_string == '!screensaver' or current_search_string == '!saver': prepare_plugin_session_screensaver(main_window, icon_size) else: tools.debug_output(__name__, 'parse', 'Error: Unexpected session command', 3) main_window.status_notification_display_error('Unexpected session plugin command') return
def parse(current_search_string, main_window): """Valides the input and prepares the UI for executing the password command""" tools.debug_output(__name__, 'parse', 'starting', 1) ## Reset status notification back to OK main_window.status_notification_reset() icon_size = ini.read_single_ini_value('General', 'icon_size') # get preference value if current_search_string == ('!pw') or current_search_string == ('!password'): tools.debug_output(__name__, 'parse', 'Case: Password Generator', 1) prepare_plugin_passwordgen(main_window, icon_size) else: tools.debug_output(__name__, 'parse', 'Error: Unexpected passwordgen plugin command', 3) main_window.status_notification_display_error('Unexpected passwordgen plugin command') tools.debug_output(__name__, 'parse', 'finished', 1)
def on_tray_popup_left_show(self, event): """Method to handle click in the 'Show mainwindow' tray menu item""" tools.debug_output(__name__, 'on_tray_popup_left_show', 'starting with event: ' + str(event), 1) if self.frame.IsIconized(): # if main window is minimized tools.debug_output(__name__, 'on_tray_popup_left_show', 'MainWindow is now visible', 1) self.frame.Raise() else: # if main window is shown tools.debug_output( __name__, 'on_tray_popup_left_show', 'MainWindow is already shown, nothing to do here', 1)
def parse(current_search_string, main_window): """Validates the misc command and calls the matching sub function""" tools.debug_output(__name__, 'parse', 'starting', 1) # Reset status notification back to OK main_window.status_notification_reset() icon_size = ini.read_single_ini_value('General', 'icon_size') # get preference value if current_search_string.startswith('!open'): tools.debug_output(__name__, 'parse', 'Case: Open', 1) prepare_plugin_misc_open(main_window, icon_size) else: tools.debug_output(__name__, 'parse', 'Error: Unexpected misc plugin command', 3) main_window.status_notification_display_error( 'Unexpected misc plugin command') tools.debug_output(__name__, 'parse', 'finished', 1)
def parse(current_search_string, main_window): """parse""" tools.debug_output(__name__, 'parse', 'starting', 1) main_window.status_notification_reset() # Reset status notification back to OK icon_size = ini.read_single_ini_value('General', 'icon_size') # get preference value if current_search_string.startswith("!sh"): tools.debug_output(__name__, 'parse', 'Case: Shell', 1) prepare_plugin_shell(main_window, icon_size) if (len(current_search_string) > 3): if current_search_string.startswith("!sh "): prepare_plugin_shell(main_window, icon_size) else: main_window.plugin__update_general_ui_information('') tools.debug_output(__name__, 'parse', 'Aborting shell', 2) return else: tools.debug_output(__name__, 'parse', 'Error: Unexpected shell plugin command', 3) main_window.status_notification_display_error('Unexpected shell plugin command') return
def prefs_general_toggle_hide_ui(self, event): """Toggle the general pref: hide_ui""" tools.debug_output(__name__, 'prefs_general_toggle_hide_ui', 'Preference - General - Hide UI: ' + str(event), 1) if self.cb_enable_hide_ui.GetValue() is True: tools.debug_output(__name__, 'prefs_general_toggle_hide_ui', 'Enabled', 1) ini.write_single_ini_value('General', 'hide_ui_after_command_execution', "True") # update preference value else: tools.debug_output(__name__, 'prefs_general_toggle_hide_ui', 'Disabled', 1) ini.write_single_ini_value('General', 'hide_ui_after_command_execution', "False") # update preference value
def read_single_ini_value(section_name, key_name): """Method to read a single value from the configuration file apparat.ini""" config = ConfigParser.ConfigParser() config.read(constants.APP_INI_PATH) try: value = config.get(section_name, key_name) tools.debug_output( __name__, 'read_single_ini_value', 'Section: ' + section_name + ' - Key: ' + key_name + ' - Value: ' + value, 1) except ConfigParser.NoOptionError: tools.debug_output( __name__, 'read_single_ini_value', 'key ' + key_name + ' does not exist. Should create the key with a default value in this case - see #13', 2) if \ (key_name == 'apparat_started') or \ (key_name == 'command_executed') or \ (key_name == 'plugin_executed'): value = '0' elif (key_name == 'hide_ui_after_command_execution'): value = 'True' elif (key_name == 'icon_size'): value = '128' elif (key_name == 'transparency'): value = '255' elif (key_name == 'lang'): value = 'EN' elif key_name.startswith('plugin'): # any plugin value = 'False' # if a key was missing - create it with a default value write_single_ini_value( section_name, key_name, value) # write default value for missing key/value pair tools.debug_output(__name__, 'read_single_ini_value', 'key ' + key_name + ' written with value: ' + value, 2) return value return value