def SetCategory(self, event=None): try: ID = event.GetKeyCode() except AttributeError: ID = event.GetEventObject().GetId() cat = GetField(self, inputid.CAT).GetValue() cat = cat.split() cat = u''.join(cat) lst_categories = GetField(self, listid.CAT) if ID in (wx.ID_ADD, wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER): lst_categories.InsertStringItem(lst_categories.GetItemCount(), cat) elif ID in (wx.ID_REMOVE, wx.WXK_DELETE): if lst_categories.GetItemCount( ) and lst_categories.GetSelectedItemCount(): cur_cat = lst_categories.GetFirstSelected() lst_categories.DeleteItem(cur_cat) elif ID == wx.ID_CLEAR: if lst_categories.GetItemCount(): if ConfirmationDialog( GetMainWindow(), GT(u'Confirm'), GT(u'Clear categories?')).ShowModal() in (wx.ID_OK, wx.OK): lst_categories.DeleteAllItems() if event: event.Skip()
def GetLauncherInfo(self): desktop_list = [u'[Desktop Entry]'] name = GetField(self, inputid.NAME).GetValue() if not TextIsEmpty(name): desktop_list.append(u'Name={}'.format(name)) desktop_list.append(u'Version=1.0') executable = GetField(self, inputid.EXEC).GetValue() if not TextIsEmpty(executable): desktop_list.append(u'Exec={}'.format(executable)) comment = GetField(self, inputid.DESCR).GetValue() if not TextIsEmpty(comment): desktop_list.append(u'Comment={}'.format(comment)) icon = GetField(self, inputid.ICON).GetValue() if not TextIsEmpty(icon): desktop_list.append(u'Icon={}'.format(icon)) launcher_type = GetField(self, inputid.TYPE).GetValue() if not TextIsEmpty(launcher_type): desktop_list.append(u'Type={}'.format(launcher_type)) desktop_list.append(u'Terminal={}'.format( GS(self.sel_term.GetSelection() == 0).lower())) desktop_list.append(u'StartupNotify={}'.format( GS(self.sel_notify.GetSelection() == 0).lower())) encoding = GetField(self, inputid.ENC).GetValue() if not TextIsEmpty(encoding): desktop_list.append(u'Encoding={}'.format(encoding)) lst_categories = GetField(self, listid.CAT) categories = [] cat_total = lst_categories.GetItemCount() count = 0 while count < cat_total: C = lst_categories.GetItemText(count) if not TextIsEmpty(C): categories.append(lst_categories.GetItemText(count)) count += 1 # Add a final semi-colon if categories is not empty if categories: categories = u';'.join(categories) if categories[-1] != u';': categories = u'{};'.format(categories) desktop_list.append(u'Categories={}'.format(categories)) ''' other = self.ti_other.GetValue() if not TextIsEmpty(other): desktop_list.append(other) ''' return u'\n'.join(desktop_list)
def ImportExes(self, event=None): event_id = event.GetId() if event_id == btnid.IMPORT: # First clear the Auto-Link display and the executable list self.Executables.Reset() # Get executables from "files" tab file_list = GetField(pgid.FILES, inputid.LIST) for INDEX in range(file_list.GetItemCount()): # Get the filename from the source file_name = file_list.GetFilename(INDEX, basename=True) file_path = file_list.GetPath(INDEX) # Where the file linked to will be installed file_target = file_list.GetItem(INDEX, 1) # Walk directory to find executables if file_list.IsDirectory(INDEX): for EXE in GetFiles(file_path, os.X_OK): self.Executables.Append(FileItem(EXE, file_target)) # Search for executables (distinguished by red text) elif file_list.IsExecutable(INDEX): try: # If destination doesn't start with "/" do not include executable if file_target.GetText()[0] == u'/': if file_target.GetText()[-1] == u'/' or file_target.GetText()[-1] == u' ': # In case the full path of the destination is "/" keep going if len(file_target.GetText()) == 1: dest_path = u'' else: search = True # Set the number of spaces to remove from dest path in case of multiple "/" slashes = 1 while search: # Find the number of slashes/spaces at the end of the filename endline = slashes - 1 if file_target.GetText()[-slashes] == u'/' or file_target.GetText()[-slashes] == u' ': slashes += 1 else: dest_path = file_target.GetText()[:-endline] search = False else: dest_path = file_target.GetText() self.Executables.Append(file_name, dest_path) else: Logger.Warn(__name__, u'{}: The executables destination is not valid'.format(__name__)) except IndexError: Logger.Warn(__name__, u'{}: The executables destination is not available'.format(__name__)) elif event_id in (btnid.REMOVE, wx.WXK_DELETE): self.Executables.RemoveSelected()
def OnClearCategories(self, event=None): cats = GetField(self, listid.CAT) if cats.GetItemCount(): clear = ConfirmationDialog(GetMainWindow(), GT(u'Confirm'), GT(u'Clear categories?')) if clear.Confirmed(): cats.DeleteAllItems()
def GetCtrlInfo(self): pg_depends = GetPage(pgid.DEPENDS) ctrl_list = [] synopsis = None description = None # Email will be set if maintainer changed to True maintainer = False # Text input fields for field in self.grp_input: field_name = field.GetName().title() field_value = field.GetValue() if FieldEnabled(field) and not TextIsEmpty(field_value): Logger.Debug(__name__, GT(u'Exporting {} field').format(field_name)) # Strip leading & trailing spaces, tabs, & newlines field_value = field_value.strip(u' \t\n') if field_name == u'Synopsis': synopsis = u'{}: {}'.format(u'Description', field_value) continue if field_name == u'Description': description = field_value.split(u'\n') for line_index in range(len(description)): # Remove trailing whitespace description[line_index] = description[ line_index].rstrip() if TextIsEmpty(description[line_index]): # Empty lines are formatted with one space indentation & a period description[line_index] = u' .' else: # All other lines are formatted with one space indentation description[line_index] = u' {}'.format( description[line_index]) description = u'\n'.join(description) continue if field_name in (u'Package', u'Version'): # Don't allow whitespace in package name & version ctrl_list.append(u'{}: {}'.format( field_name, u'-'.join(field_value.split(u' ')))) continue if field_name == u'Email': if maintainer and ctrl_list: # Append email to end of maintainer string for ctrl_index in range(len(ctrl_list)): if ctrl_list[ctrl_index].startswith( u'Maintainer: '): Logger.Debug(__name__, u'Found maintainer') ctrl_list[ctrl_index] = u'{} <{}>'.format( ctrl_list[ctrl_index], field_value) break continue # Don't use 'continue' on this statement if field_name == u'Maintainer': maintainer = True # The rest of the fields ctrl_list.append(u'{}: {}'.format(field_name, field_value)) # Selection box fields for field in self.grp_select: field_name = field.GetName().title() field_value = field.GetStringSelection() if FieldEnabled(field) and not TextIsEmpty(field_value): Logger.Debug(__name__, GT(u'Exporting {} field').format(field_name)) # Strip leading & trailing spaces, tabs, & newlines field_value = field_value.strip(u' \t\n') ctrl_list.append(u'{}: {}'.format(field_name, field_value)) if self.chk_essential.GetValue(): ctrl_list.append(u'Essential: yes') # Dependencies & conflicts dep_list = [] # Depends pre_list = [] # Pre-Depends rec_list = [] # Recommends sug_list = [] # Suggests enh_list = [] # Enhances con_list = [] # Conflicts rep_list = [] # Replaces brk_list = [] # Breaks all_deps = { u'Depends': dep_list, u'Pre-Depends': pre_list, u'Recommends': rec_list, u'Suggests': sug_list, u'Enhances': enh_list, u'Conflicts': con_list, u'Replaces': rep_list, u'Breaks': brk_list, } # Get amount of items to add dep_area = GetField(pg_depends, inputid.LIST) dep_count = dep_area.GetItemCount() count = 0 while count < dep_count: # Get each item from dependencies page dep_type = dep_area.GetItem(count, 0).GetText() dep_val = dep_area.GetItem(count, 1).GetText() for item in all_deps: if dep_type == item: all_deps[item].append(dep_val) count += 1 for item in all_deps: if len(all_deps[item]) != 0: ctrl_list.append(u'{}: {}'.format(item, u', '.join(all_deps[item]))) if synopsis: ctrl_list.append(synopsis) # Long description is only added if synopsis is not empty if description: ctrl_list.append(description) # dpkg requires empty newline at end of file return u'\n'.join(ctrl_list).strip(u'\n') + u'\n'
def SetLauncherData(self, data, enabled=True): # Make sure we are dealing with a list if isinstance(data, (unicode, str)): data = data.split(u'\n') # Data list is not empty if data: Logger.Debug(__name__, u'Loading launcher') if data[0].isnumeric(): enabled = int(data.pop(0)) > 0 if DebugEnabled(): for L in data: print(u' Launcher line: {}'.format(L)) Logger.Debug(__name__, u'Enabling launcher: {}'.format(enabled)) if enabled: GetField(self, chkid.ENABLE).SetValue(True) data_defs = {} data_defs_remove = [] misc_defs = [] for L in data: if u'=' in L: if L[0] == u'[' and L[-1] == u']': key = L[1:-1].split(u'=') value = key[1] key = key[0] misc_defs.append(u'{}={}'.format(key, value)) else: key = L.split(u'=') value = key[1] key = key[0] data_defs[key] = value # Fields using SetValue() function set_value_fields = ( (u'Name', GetField(self, inputid.NAME)), (u'Exec', GetField(self, inputid.EXEC)), (u'Comment', GetField(self, inputid.DESCR)), (u'Icon', GetField(self, inputid.ICON)), (u'Type', GetField(self, inputid.TYPE)), (u'Encoding', GetField(self, inputid.ENC)), ) for label, control in set_value_fields: try: control.SetValue(data_defs[label]) data_defs_remove.append(label) except KeyError: pass check_box_fields = ( (u'Terminal', GetField(self, chkid.TERM)), (u'StartupNotify', GetField(self, chkid.NOTIFY)), ) for label, control in check_box_fields: try: if data_defs[label].lower() == u'true': control.SetValue(True) else: control.SetValue(False) data_defs_remove.append(label) except KeyError: pass try: lst_categories = GetField(self, listid.CAT) categories = tuple(data_defs[u'Categories'].split(u';')) for C in categories: lst_categories.InsertStringItem( lst_categories.GetItemCount(), C) data_defs_remove.append(u'Categories') except KeyError: pass for K in data_defs_remove: if K in data_defs: del data_defs[K] # Add any leftover keys to misc/other for K in data_defs: if K not in (u'Version', ): misc_defs.append(u'{}={}'.format(K, data_defs[K])) for index in reversed(range(len(misc_defs))): K = misc_defs[index] # Set custom filename if u'FILENAME=' in K: filename = K.replace(u'FILENAME=', u'') if not TextIsEmpty(filename): Logger.Debug( __name__, u'Setting custom filename: {}'.format( filename)) GetField(self, inputid.FNAME).SetValue(filename) GetField(self, chkid.FNAME).SetValue(False) # Remove so not added to misc. list misc_defs.pop(index) continue if misc_defs: GetField(self, inputid.OTHER).SetValue(u'\n'.join( sorted(misc_defs))) self.OnToggle()
def Set(self, data): # Make sure we are dealing with a list if isinstance(data, (unicode, str)): data = data.split(u'\n') # Data list is not empty if data: Logger.Debug(__name__, u'Loading launcher') if DebugEnabled(): for L in data: print(u' Launcher line: {}'.format(L)) data_defs = {} data_defs_remove = [] misc_defs = [] for L in data: if u'=' in L: if L[0] == u'[' and L[-1] == u']': key = L[1:-1].split(u'=') value = key[1] key = key[0] misc_defs.append(u'{}={}'.format(key, value)) else: key = L.split(u'=') value = key[1] key = key[0] data_defs[key] = value # Fields using SetValue() function set_value_fields = ( (u'Name', GetField(self, inputid.NAME)), (u'Exec', GetField(self, inputid.EXEC)), (u'Comment', GetField(self, inputid.DESCR)), (u'Icon', GetField(self, inputid.ICON)), (u'Type', GetField(self, inputid.TYPE)), (u'Encoding', GetField(self, inputid.ENC)), ) for label, control in set_value_fields: try: control.SetValue(data_defs[label]) data_defs_remove.append(label) except KeyError: pass # Fields using SetSelection() function set_selection_fields = ( (u'Terminal', self.sel_term), (u'StartupNotify', self.sel_notify), ) for label, control in set_selection_fields: try: control.SetStringSelection(data_defs[label].lower()) data_defs_remove.append(label) except KeyError: pass try: lst_categories = GetField(self, listid.CAT) categories = tuple(data_defs[u'Categories'].split(u';')) for C in categories: lst_categories.InsertStringItem( lst_categories.GetItemCount(), C) data_defs_remove.append(u'Categories') except KeyError: pass for K in data_defs_remove: if K in data_defs: del data_defs[K] # Add any leftover keys to misc/other for K in data_defs: if K not in (u'Version', ): misc_defs.append(u'{}={}'.format(K, data_defs[K])) for index in reversed(range(len(misc_defs))): K = misc_defs[index] # Set custom filename if u'FILENAME=' in K: filename = K.replace(u'FILENAME=', u'') # Remove so not added to misc. list misc_defs.pop(index) continue '''