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

📄 abc_tweak.py

📁 BitTorrentABC-Linux-V.2.4.3源码
💻 PY
📖 第 1 页 / 共 2 页
字号:
##############################################################################
# Module : abc_tweak.py
# Author : Choopan RATTANAPOKA
# Data   : 16 September 2003
#
# Description : a utility for tweaking ABC [Yet Another Bittorrent Client]
#               display.
##############################################################################
from sys import argv
from wxPython.wx import *
from wxPython import *
from os import path, chdir

F_ID            = 0
F_COL           = 1
F_TEXT          = 2
F_VALUE         = 3

ID_ABCWIDTH     = 0
ID_ABCHEIGHT    = 1
ID_DETWIDTH     = 2
ID_DETHEIGHT    = 3
ID_TITLE        = 4
ID_PROGRESS     = 5


##############################################################
# Class : inimanager
##############################################################
class inimanager:
    ###########################################################
    # abc.ini pattern
    # id|column|text|startingwidth [column -1 = no display]
    # 0 = app_width,        1 = app_height
    # 2 = detailwin_width,  3 = detailwin_height
    # 4 = Title             5 = Progress
    # 6 = BT status         7 = Priority
    # 8 = ETA               9= Size
    #10 = DL speed          11= UL speed
    #12 = %U/D Size         13= Error message
    #14 = #connected seed   15= #connected peer
    #16 = #seeing copies    17=Peer Avg progress
    #18= Download Size      19=Upload Size
    #20= Total Speed
    ###########################################################
    def __init__(self):
        self.maxid = 21
        self.configdata = []

        
        # read abc.ini
        ################
        ini = open("abc.ini", "rb")
        while True:
            iniline = ini.readline()
            if iniline == "" or iniline == "\n":
                break
            iniarg = iniline.split("|")        
            self.configdata.append([ int(iniarg[0]), int(iniarg[1]), iniarg[2], int(iniarg[3][0:-1])])
        ini.close()

    # Save setting to abc.ini
    ################################
    def savefile(self, selected_list):
        ini = open("abc.ini", "w")
        for i in range(0, self.maxid):
            iniline = (str(self.configdata[i][F_ID]) + "|" + self.getrank(selected_list, i) + "|" + self.configdata[i][F_TEXT] + "|" + str(self.configdata[i][F_VALUE]) + "\n")
            ini.writelines(iniline)
        ini.close()

    # Get Column Rank
    ################################
    def getrank(self, selected_list, id):            
        for i in range(0, len(selected_list)):
            if selected_list[i] == id :
                return str(i)
        return str(-1)


##############################################################
# Class : ABCTweakPanel
##############################################################
class ABCTweakPanel(wxPanel):
    def __init__(self, parent):
        wxPanel.__init__(self, parent, -1, style=wxWANTS_CHARS)

        self.parent = parent
        self.ini = inimanager()
        self.leftid = []
        self.rightid = []
        self.leftindex = -1
        self.rightindex = -1
        
        # Title
        title = wxStaticText(self, -1, "ABC Tweak 1.0", wxPoint(155, 5))
        title.SetFont(wxFont(18, wxDEFAULT, wxNORMAL, wxNORMAL,false))

        # ABC window size setting
        wxStaticText(self, -1, "ABC Window Width", wxPoint(20,50))
        self.abc_width  = wxTextCtrl(self, -1, "", wxPoint(128, 45), wxSize(40, -1))
        wxStaticText(self, -1, "Pixel", wxPoint(175,50))

        wxStaticText(self, -1, "ABC Window Height", wxPoint(20,75))
        self.abc_height = wxTextCtrl(self, -1, "", wxPoint(128, 70), wxSize(40, -1))
        wxStaticText(self, -1, "Pixel", wxPoint(175,75))


        # ABC detail window size setting
        wxStaticText(self, -1, "Detail Window Width", wxPoint(270,50))
        self.det_width  = wxTextCtrl(self, -1, "", wxPoint(378, 45), wxSize(40, -1))
        wxStaticText(self, -1, "Pixel", wxPoint(425,50))

        wxStaticText(self, -1, "Detail Window Height", wxPoint(270,75))
        self.det_height = wxTextCtrl(self, -1, "", wxPoint(378, 70), wxSize(40, -1))
        wxStaticText(self, -1, "Pixel", wxPoint(425,75))

        ID_LEFT_LIST  = wxNewId()
        ID_RIGHT_LIST = wxNewId()
        ID_ADD_BUTTON = wxNewId()
        ID_REMOVE_BUTTON = wxNewId()
        
        # unselected list ctrl
        self.unselected_list = wxListCtrl(self, ID_LEFT_LIST,
                                          wxPoint(20, 100), wxSize(150,180),
                                          style=wxLC_REPORT | wxLC_SINGLE_SEL
                                          )
        self.unselected_list.InsertColumn(0, "Unselected Display")
        self.unselected_list.SetColumnWidth(0, 140)
        
        # add column button
        self.addbutton = wxButton(self, ID_ADD_BUTTON, "Add >>", wxPoint(175, 155))
        # remove column button
        self.removebutton = wxButton(self, ID_REMOVE_BUTTON, "<< Remove", wxPoint(175, 190))
        
        # selected list ctrl
        self.selected_list = wxListCtrl(self, ID_RIGHT_LIST,
                                        wxPoint(255, 100), wxSize(150,180),
                                        style=wxLC_REPORT | wxLC_SINGLE_SEL
                                          )
        self.selected_list.InsertColumn(0, "Selected Display")
        self.selected_list.SetColumnWidth(0, 140)


        # Up & Down button
        ###################
        ID_UP   = wxNewId()
        ID_DOWN = wxNewId()
        wxButton(self, ID_UP, "Up", wxPoint(413, 155), wxSize(45, -1))
        wxButton(self, ID_DOWN, "Down", wxPoint(413, 190), wxSize(45,-1))

        ID_APPLY = wxNewId()
        # Column Setting
        wxStaticBox(self, -1, "Column Setting (Click Apply everytime if you want to change parameters)", wxPoint(20,290), wxSize(430,65))
        wxStaticText(self, -1, "Column :", wxPoint(30, 310))
        self.displaycol = wxStaticText(self, -1, "", wxPoint(75, 310))

        wxStaticText(self, -1, "Display Name :", wxPoint(105, 310))
        self.displayname = wxTextCtrl(self, -1, "", wxPoint(180, 305), wxSize(200, -1))

        wxStaticText(self, -1, "Column Width :", wxPoint(105, 335))
        self.displaywidth = wxTextCtrl(self, -1, "", wxPoint(180, 330), wxSize(60, -1))
        wxStaticText(self, -1, "Pixel", wxPoint(250, 335))

        wxButton(self, ID_APPLY, "Apply", wxPoint(330, 328), wxSize(50, -1))
        

        # save&exit, cancel button
        ID_SAVE   = wxNewId()
        ID_CANCEL = wxNewId()
        wxButton(self, ID_SAVE, "SAVE and Apply",wxPoint(140,362))
        wxButton(self, ID_CANCEL, "     Close     ",wxPoint(250,362))

        # Add Event
        #########################
        EVT_LIST_ITEM_RIGHT_CLICK(self, ID_LEFT_LIST, self.OnRightUnSelected)
        EVT_LEFT_DOWN(self.unselected_list, self.OnLeftUnSelected)
        
        EVT_LIST_ITEM_RIGHT_CLICK(self, ID_RIGHT_LIST, self.OnRightSelected)
        EVT_LEFT_DOWN(self.selected_list  , self.OnLeftSelected)

        EVT_KEY_DOWN(self.selected_list, self.OnKeySelectedList)
        EVT_KEY_DOWN(self.unselected_list, self.OnKeyUnselectedList)
                     
        EVT_BUTTON(self, ID_ADD_BUTTON, self.OnAdd)
        EVT_BUTTON(self, ID_REMOVE_BUTTON, self.OnRemove)
        EVT_BUTTON(self, ID_UP,     self.OnUp)
        EVT_BUTTON(self, ID_DOWN,   self.OnDown)
        EVT_BUTTON(self, ID_APPLY,  self.OnApply)
        EVT_BUTTON(self, ID_SAVE,   self.OnSave)
        EVT_BUTTON(self, ID_CANCEL, self.OnClose)

        # Set Default value from abc.ini
        ######################################
        self.abc_width.SetValue(str(self.ini.configdata[ID_ABCWIDTH][F_VALUE]))
        self.abc_height.SetValue(str(self.ini.configdata[ID_ABCHEIGHT][F_VALUE]))
        self.det_width.SetValue(str(self.ini.configdata[ID_DETWIDTH][F_VALUE]))
        self.det_height.SetValue(str(self.ini.configdata[ID_DETHEIGHT][F_VALUE]))
        self.max_selected   = 0
        self.max_unselected = 0
        for i in range(4, self.ini.maxid):
            numcol = self.ini.configdata[i][F_COL]
            if numcol == -1:
                self.unselected_list.InsertStringItem(self.max_unselected, "")
                self.unselected_list.SetStringItem(self.max_unselected, 0, self.ini.configdata[i][F_TEXT])
                self.leftid.append(self.ini.configdata[i][F_ID])
                self.max_unselected += 1
            else:
                if numcol >= self.max_selected:
                    for j in range(self.max_selected, numcol+1):
                        self.selected_list.InsertStringItem(j,"")
                        self.rightid.append("")
                        self.max_selected += 1
                self.selected_list.SetStringItem(numcol, 0, self.ini.configdata[i][F_TEXT])
                self.rightid[numcol] = self.ini.configdata[i][F_ID]

    def OnKeySelectedList(self, event):
        if event.GetKeyCode() == WXK_UP:
            if self.rightindex > 0:
                self.rightindex -= 1
                self.selected_list.Select(self.rightindex)                
                self.DisplayInfo()
        elif event.GetKeyCode() == WXK_DOWN:
            if self.rightindex < self.max_selected-1:
                self.rightindex += 1
                self.selected_list.Select(self.rightindex)
                self.DisplayInfo()

    def OnKeyUnselectedList(self, event):
        if event.GetKeyCode() == WXK_UP:
            if self.leftindex > 0:
                self.leftindex -= 1

⌨️ 快捷键说明

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