⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 list.py

📁 ABC-win32-v3.1 一个P2P软源代码
💻 PY
📖 第 1 页 / 共 2 页
字号:
import wx
import sys

from wx.lib import masked

#from Utility.compat import convertINI


################################################################
#
# Class: ColumnsDialog
#
# Allows a user to alter the settings and appearance of 
# columns in a ManagedList.
#
################################################################
class ColumnsDialog(wx.Dialog):
    def __init__(self, list):
        
        self.utility = list.utility
        
        title = self.utility.lang.get('columns')
        
        pre = wx.PreDialog()
        pre.Create(list, -1, title)
        self.this = pre.this

        outerbox = wx.BoxSizer(wx.VERTICAL)
        
        self.columnsPanel = ColumnsPanel(self, list)
        
        applybtn  = wx.Button(self, -1, self.utility.lang.get('apply'))
        self.Bind(wx.EVT_BUTTON, self.onApply, applybtn)
        
        okbtn  = wx.Button(self, -1, self.utility.lang.get('ok'))
        self.Bind(wx.EVT_BUTTON, self.onOK, okbtn)
        
        cancelbtn = wx.Button(self, wx.ID_CANCEL, self.utility.lang.get('cancel'))
        
#        setDefaultsbtn = wx.Button(self, -1, self.utility.lang.get('reverttodefault'))
        
        buttonbox = wx.BoxSizer(wx.HORIZONTAL)
        buttonbox.Add(applybtn, 0, wx.ALL, 5)
        buttonbox.Add(okbtn, 0, wx.ALL, 5)
        buttonbox.Add(cancelbtn, 0, wx.ALL, 5)
        
        outerbox.Add(self.columnsPanel, 0, wx.EXPAND|wx.ALL, 5)
        outerbox.Add(buttonbox, 0, wx.ALIGN_CENTER)
       
        self.SetAutoLayout(True)
        self.SetSizer(outerbox)
        self.Fit()
        
    def onOK(self, event = None):
        if self.onApply(event):
            self.EndModal(wx.ID_OK)
        
    def onApply(self, event = None):
        self.columnsPanel.apply()
        return True


################################################################
#
# Class: ColumnsPanel
#
# Contains the interface elements for a ColumnsDialog
#
################################################################
class ColumnsPanel(wx.Panel):
    def __init__(self, parent, list):
        wx.Panel.__init__(self, parent, -1)
        
        # Constants
        self.RANK = 0
        self.COLID = 1
        self.TEXT = 2
        self.WIDTH = 3

        self.utility = parent.utility
        
        self.list = list
        self.columns = list.columns
        
        self.changed = False
        
        self.changingvalue = False

        self.leftid = []
        self.rightid = []
        self.leftindex = -1
        self.rightindex = -1
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        
        listsizer = wx.BoxSizer(wx.HORIZONTAL)
        
        # unselected list ctrl
       
        self.checklistbox = wx.CheckListBox(self, -1, size = wx.Size(150, 200), style = wx.LB_SINGLE)

        listsizer.Add(self.checklistbox, 0, wx.ALL, 5)

        # Up & Down button
        ###################        
        self.upbutton = self.utility.makeBitmapButton(self, 'moveup.bmp', 'move_up', self.OnMove)
        self.downbutton = self.utility.makeBitmapButton(self, 'movedown.bmp', 'move_down', self.OnMove)

        updownsizer = wx.BoxSizer(wx.VERTICAL)
        
        updownsizer.Add(self.upbutton, 0, wx.BOTTOM, 5)
        updownsizer.Add(self.downbutton, 0, wx.TOP, 5)
        
        listsizer.Add(updownsizer, 0, wx.ALL, 5)
        
        sizer.Add(listsizer, 0)
        
        labelbox = wx.BoxSizer(wx.HORIZONTAL)
        labelbox.Add(wx.StaticText(self, -1, self.utility.lang.get('displayname')), 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 5)
        columnlabel = ""
        self.labelsetting = wx.TextCtrl(self, -1, columnlabel)
        labelbox.Add(self.labelsetting, 0, wx.ALIGN_CENTER_VERTICAL)
        
        sizer.Add(labelbox, 0, wx.ALL, 5)
        
        widthbox = wx.BoxSizer(wx.HORIZONTAL)
        widthbox.Add(wx.StaticText(self, -1, self.utility.lang.get('columnwidth')), 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 5)
        initialvalue = 0
        self.widthsetting = self.utility.makeNumCtrl(self, initialvalue, integerWidth = 4, max = 2000)
        widthbox.Add(self.widthsetting, 0, wx.ALIGN_CENTER_VERTICAL)
        
        sizer.Add(widthbox, 0, wx.ALL, 5)
               
        self.getDefaultValues()

        self.labelsetting.Enable(False)
        self.widthsetting.Enable(False)
        
        self.SetSizerAndFit(sizer)

        # Add Event
        #########################
        self.Bind(wx.EVT_LISTBOX, self.OnSelect, self.checklistbox)
        self.Bind(wx.EVT_TEXT, self.OnChangeLabel, self.labelsetting)
        self.Bind(masked.EVT_NUM, self.OnChangeWidth, self.widthsetting)

    def getDefaultValues(self):
        unselected = []
        
        selected = []

        for colid in range(self.columns.minid, self.columns.maxid):
            rank = self.utility.config.Read(self.list.prefix + str(colid) + "_rank", "int")
            text = self.utility.lang.get(self.list.prefix + str(colid) + "_text")
            width = self.utility.config.Read(self.list.prefix + str(colid) + "_width", "int")
            if colid in self.list.exclude:
                pass
            elif rank == -1:
                unselected.append([rank, colid, text, width])
            else:
                selected.append([rank, colid, text, width])
        
        unselected.sort()
        selected.sort()
        
        self.columnlist = selected + unselected
        
        self.checklistbox.Set([item[2] for item in self.columnlist])
        
        for i in range(len(self.columnlist)):
            if self.columnlist[i][0] != -1:
                self.checklistbox.Check(i)
    
    # Select one of the items in the list
    def OnSelect(self, event):
        # The index of the selection within the checklistbox
        index = self.checklistbox.GetSelection()
        if index == wx.NOT_FOUND:
            self.labelsetting.Enable(False)
            self.widthsetting.Enable(False)
            return
        self.labelsetting.Enable(True)
        self.widthsetting.Enable(True)
            
        textstring = self.checklistbox.GetString(index)

        self.changingvalue = True
        self.labelsetting.SetValue(textstring)
        self.widthsetting.SetValue(self.columnlist[index][self.WIDTH])
        self.changingvalue = False
        
    def OnChangeLabel(self, event):
        if self.changingvalue:
            return
        
        index = self.checklistbox.GetSelection()
        if index == wx.NOT_FOUND:
            return
        
        oldlabel = self.columnlist[index][self.TEXT]
        newlabel = self.labelsetting.GetValue()
        if oldlabel == newlabel:
            return
            
        self.columnlist[index][self.TEXT] = newlabel
        self.checklistbox.SetString(index, newlabel)
        
    def OnChangeWidth(self, event):
        if self.changingvalue:
            return
        
        index = self.checklistbox.GetSelection()
        if index == wx.NOT_FOUND:
            return
        
        self.columnlist[index][self.WIDTH] = self.widthsetting.GetValue()
    
    # Move a list item up or down           
    def OnMove(self, event):
        # Move up
        if event.GetId() == self.upbutton.GetId():
            direction = -1
        # Move down
        else:
            direction = 1
        
        index = self.checklistbox.GetSelection()
        if index == wx.NOT_FOUND:
            # Nothing is selected:
            return

        if (direction == 1) and (index == self.checklistbox.GetCount() - 1):
            #Last Item can't move down anymore
            return
        elif (direction == -1) and (index == 0):
            # First Item can't move up anymore
            return
        else:
            self.columnlist[index], self.columnlist[index + direction] = self.columnlist[index + direction], self.columnlist[index]

            col1text = self.checklistbox.GetString(index)
            col2text = self.checklistbox.GetString(index + direction)

            col1checked = self.checklistbox.IsChecked(index)
            col2checked = self.checklistbox.IsChecked(index + direction)

            #Update display
            self.checklistbox.SetString(index + direction, col1text)
            self.checklistbox.SetString(index, col2text)
            
            self.checklistbox.Check(index + direction, col1checked)
            self.checklistbox.Check(index, col2checked)
            
            self.checklistbox.SetSelection(index + direction)

    def apply(self):
        selected = 0
        for i in range(0, self.checklistbox.GetCount()):
            colid = self.columnlist[i][1]
            if self.checklistbox.IsChecked(i):
                self.columnlist[i][self.RANK] = selected
                selected += 1
            else:
                self.columnlist[i][self.RANK] = -1

        # Check to see if anything has changed
        overallchange = False                
        for item in self.columnlist:
            colid = item[self.COLID]

            rank = item[self.RANK]
            changed = self.utility.config.Write(self.list.prefix + str(colid) + "_rank", rank)
            if changed:
                overallchange = True
            
            changed = self.utility.lang.writeUser(self.list.prefix + str(colid) + "_text", item[self.TEXT])
            if changed:
                overallchange = True

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -