Уведомления

Группа в Telegram: @pythonsu

#1 Окт. 5, 2008 18:28:33

124bit
От:
Зарегистрирован: 2008-04-10
Сообщения: 121
Репутация: +  0  -
Профиль   Отправить e-mail  

сортировка.. не всегда) wx

какая то аномалия… первые три колонки сортирует, а четвертую - пишет индекс аут оф ренж.. вот код.. гадкий код, в котором сложно разобраться, но все же жду советов))


import bz2
import wx
import sys
from ConfigParser import SafeConfigParser as Config
from wx.lib.mixins.listctrl import ColumnSorterMixin




class GUI(wx.Dialog):
def __init__(self, parent, id, title):
wx.Dialog.__init__(self, parent, id, title, size=(400, 200))

wx.Button(self, 1, ‘Close’, (50, 130))
wx.Button(self, 2, ‘Add BUX’, (150, 130), (110, -1))

self.Bind(wx.EVT_BUTTON, self.OnClose, id=1)
self.Bind(wx.EVT_BUTTON, self.Open_addBux, id=2)

self.Centre()
self.Show()

def OnClose(self, event):
self.Close(True)

def Open_addBux(self, event):
addBux(None,-1,'11.py')
class FlexGridSizer(wx.Dialog):
def __init__(self):
wx.Dialog.__init__(self,None, -1,'Set proxy', size=(250,210))
proxy = wx.StaticText(self, -1, ‘proxy’,pos=(10,10)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
login = wx.StaticText(self, -1, ‘login’,pos=(10,40)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
password = wx.StaticText(self, -1, ‘password’,pos=(10,70)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
comment = wx.StaticText(self, -1, ‘comment’,pos=(10,100)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
self.tc1 = wx.TextCtrl(self, -1,pos=(80,10),size=(150,-1))
self.tc2 = wx.TextCtrl(self, -1,pos=(80,40))
self.tc3 = wx.TextCtrl(self, -1,pos=(80,70))
self.tc4 = wx.TextCtrl(self, -1,pos=(80,100),size=(-1,40), style=wx.TE_MULTILINE)
wx.Button(self, 100, ‘Ok’, (10, 150),size=(80, -1))
wx.Button(self, 101, ‘Cancel’, (100, 150),size=(80, -1))
self.Bind(wx.EVT_BUTTON, self.OnClose1, id=101)
self.Bind(wx.EVT_BUTTON, self.Apply1, id=100)
self.Centre()
self.ShowModal()
self.Destroy()
def OnClose1(self, event):
self.add=0
self.Close(True)

def Apply1(self, event):
self.proxy_adress=self.tc1.GetValue()
self.proxy_login=self.tc2.GetValue()
self.proxy_password=self.tc3.GetValue()
self.proxy_comment=self.tc4.GetValue()
self.add=1
self.Close(True)
class addBux(FlexGridSizer):
def __init__(self, parent, id):
wx.Dialog.__init__(self, parent, id, ‘Add bux’, size=(500, 485))
panel = wx.Panel(self, -1)
wx.Button(self, 2, ‘Ok’, (389, 380),size=(90, 30))
wx.Button(self, 1, ‘Cancel’, (389, 420),size=(90, -1))
wx.StaticText(self, -1, ‘login’, (165, 14)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
self.login=wx.TextCtrl(self,4,pos=(194,10),size=(115,-1))
wx.StaticText(self, -1, ‘password’, (315, 14)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
self.password=wx.TextCtrl(self,5,pos=(373,10),size=(115,-1))
wx.StaticLine(self, -1, (5, 40), (480,1))
self.choise_bux=wx.ComboBox(self, 6, pos=(10, 10), size=(150, -1), choices=,
style=wx.CB_READONLY | wx.CB_SORT)

self.choise_bux.SetValue('qq')
self.use_proxy=wx.CheckBox(self, 7, ‘Use proxy’, (10, 50))
self.update_list()




self.new = wx.Button(self, 9, ‘New’, size=(70, -1),pos=(415,70))
self.dlt = wx.Button(self, 11, ‘Delete’, size=(70, -1),pos=(415,100))
self.clr = wx.Button(self, 12, ‘Clear’, size=(70, -1),pos=(415,130))
self.proxy_value=wx.StaticText(self, -1, ‘Proxy:’, (12,280)).SetFont(wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.BOLD))
self.proxy_text=wx.StaticText(self, -1, ‘-’, (60,280))
self.proxy_text.SetFont(wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.BOLD))
wx.StaticText(self, -1, ‘Page view min time random’, (10, 315)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
self.timing_viewMin=wx.SpinCtrl(self, 14, ‘30’, (180, 315), (60, -1), min=20, max=120)
wx.StaticText(self, -1, ‘Page view max time random’, (10, 345)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
self.timing_viewMax=wx.SpinCtrl(self, 15, ‘40’, (180, 345), (60, -1), min=20, max=120)
wx.StaticText(self, -1, ‘Between views min time random’, (10, 385)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
self.timing_waitMin=wx.SpinCtrl(self, 16, ‘5’, (207, 385), (60, -1), min=1, max=120)
wx.StaticText(self, -1, ‘Between views max time random’, (10, 415)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
self.timing_waitMax=wx.SpinCtrl(self, 17, ‘10’, (207, 415), (60, -1), min=1, max=120)
self.select = wx.Button(self, 18, ‘Select’, size=(70, 40),pos=(415,230))
self.Bind(wx.EVT_BUTTON, self.NewItem, id=9)

self.Bind(wx.EVT_BUTTON, self.OnDelete, id=11)
self.Bind(wx.EVT_BUTTON, self.OnClear, id=12)
self.Bind(wx.EVT_BUTTON, self.OnSelect, id=18)
self.Bind(wx.EVT_CHECKBOX,self.Proxy_choice, id = 7)
self.Bind(wx.EVT_BUTTON, self.OnClose, id=1)
self.Bind(wx.EVT_BUTTON, self.Apply, id=2)
self.proxy_list.Disable()
self.new.Disable()

self.dlt.Disable()
self.clr.Disable()
self.select.Disable()
self.Centre()
self.Show()
def Proxy_choice(self,event):
if self.use_proxy.GetValue()==True:
self.proxy_list.Enable()
self.new.Enable()

self.dlt.Enable()
self.clr.Enable()
self.select.Enable()
try:
self.proxy
except:
self.proxy='-'
self.proxy_text.SetLabel(self.proxy)

else:
self.proxy_list.Disable()
self.new.Disable()

self.dlt.Disable()
self.clr.Disable()
self.select.Disable()
self.proxy_text.SetLabel('-')
def NewItem(self, event):
proxyadd=FlexGridSizer()
try: proxyadd.add
except: proxyadd.add=0
if proxyadd.add==1:
conf=Config()
conf.read('settings.ini')
if conf.has_section('proxy')==False:
conf.add_section('proxy')
count=1
for proxy in conf.items('proxy'):
if proxy[:proxy.find('^')]==proxyadd.proxy_adress+'@'+proxyadd.proxy_adress+'&'+proxyadd.proxy_password:
count=0
dial = wx.MessageDialog(None, ‘Error: proxy already added’, ‘Error’, wx.OK |
wx.ICON_ERROR)
dial.ShowModal()
dial.Destroy()

if proxyadd.proxy_adress=='' or proxyadd.proxy_adress.find(“:”)==-1:
count=0
dial = wx.MessageDialog(None, ‘Error: invalid proxy address’, ‘Error’, wx.OK |
wx.ICON_ERROR)
dial.ShowModal()
dial.Destroy()

option=1
if count==1:
while conf.has_option('proxy',str(option))==True:
option=option+1
conf.set('proxy',str(option),proxyadd.proxy_adress+'@'+proxyadd.proxy_login+'&'+proxyadd.proxy_password+'^'+proxyadd.proxy_comment)
cf=open('settings.ini','w')
conf.write(cf)
cf.close()
self.proxy_list.ClearAll()
self.update_list()


def OnDelete(self, event):
sel = self.listbox.GetSelection()
if sel != -1:
self.listbox.Delete(sel)

def OnClear(self, event):
dial = wx.MessageDialog(None, ‘Are you sure, you want to clean all proxies?’, ‘Question’,
wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
if dial.ShowModal() == 5103:
count=1
else:
count=0
dial.Destroy()
if count==1:
conf=Config()
conf.read('Settings.ini')
try: conf.remove_section('proxy')
except: pass
conf.add_section('proxy')
sf=open('settings.ini','w')
conf.write(sf)
sf.close
self.update_list()
def OnSelect(self,event):
try:
self.proxy=self.proxy_list.GetItemText(self.get_selected_items(self.proxy_list))
self.proxy_text.SetLabel(self.proxy)
except:
pass

def get_selected_items(self,list_control):
selection =


current = -1
while True:
next = self.GetNextSelected(list_control, current)
if next == -1:
return selection

selection.append(next)
current = next

def GetNextSelected(self,list_control, current):
return list_control.GetNextItem(current,
wx.LIST_NEXT_ALL,
wx.LIST_STATE_SELECTED)

def OnClose(self, event):
self.Close(True)
def prlist(self):
conf=Config()
conf.read('settings.ini')
if conf.has_section('proxy')==False:
conf.add_section('proxy')
proxys={}
count=1
for proxy in conf.items('proxy'):

proxys=(proxy[:proxy.find('@')],proxy[proxy.find('@')+1:proxy.find('&')],
proxy[proxy.find('&')+1:proxy.find('^')],proxy[proxy.find('^')+1:])

count=count+1
k=proxys.items()
return proxys

def Apply(self, event):
conf=Config()
conf.read('settings.ini')
section = self.choise_bux.GetValue()+''+self.login.GetValue()
if self.login.GetValue()=='' or self.password.GetValue() =='' :
message='Error: ‘
if self.login.GetValue()==’':
message=message+ ‘Login missed ’
if self.password.GetValue() =='':
message=message+ ‘Password missed ’
dial = wx.MessageDialog(None, message, ‘Error’, wx.OK |
wx.ICON_ERROR)
dial.ShowModal()
dial.Destroy()
count=0
else: count =1
if count==1:
if self.use_proxy.GetValue()==True:
if self.proxy==“-”:
dial = wx.MessageDialog(None, ‘Error: proxy missed’, ‘Error’, wx.OK |
wx.ICON_ERROR)
dial.ShowModal()
dial.Destroy()
count=0

if count==1:
if conf.has_section(section)==False:
conf.add_section(section)
count=1
else:
dial = wx.MessageDialog(None, ‘There is the same PTC with this login, do you want to change its settings?’, ‘Question’,
wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
if dial.ShowModal() == 5103:
count=1
else:
count=0
dial.Destroy()



if count==1:
conf.set(section,'PTC',self.choise_bux.GetValue())
conf.set(section,'username',self.login.GetValue())
conf.set(section,'password',bz2.compress(self.password.GetValue()))
conf.set(section,'view_timeMin',str(self.timing_viewMin.GetValue()))
conf.set(section,'view_timeMax',str(self.timing_waitMax.GetValue()))
conf.set(section,'between_timeMin',str(self.timing_waitMin.GetValue()))
conf.set(section,'between_timeMax',str(self.timing_waitMax.GetValue()))
if self.use_proxy.GetValue()==True:
if self.proxy!='-':
conf.set(section,'proxy_adress',self.proxy)
if self.use_proxy.GetValue()==False:
conf.set(section,'proxy_adress','None')
conf_file=open('settings.ini','w')
conf.write(conf_file)
conf_file.close()
dial = wx.MessageDialog(None,self.choise_bux.GetValue()+' PTC account ‘+ self.login.GetValue()+’ was added', ‘Info’, wx.OK)
dial.ShowModal()
dial.Destroy()
def update_list(self):
try:self.proxy_list.Destroy()
except: pass
self.proxy_list = SortedListCtrl(self)
self.proxy_list.InsertColumn(0, ‘proxy’, width=125)
self.proxy_list.InsertColumn(1, ‘login’, width=80)
self.proxy_list.InsertColumn(2, ‘password’, width= 80)
self.proxy_list.InsertColumn(4, ‘comment’,width=93)

items=self.prlist().items()
for key, data in items:
index = self.proxy_list.InsertStringItem(sys.maxint, data)
self.proxy_list.SetStringItem(index, 1, data)
self.proxy_list.SetStringItem(index, 2, data)
self.proxy_list.SetStringItem(index, 3, data)
self.proxy_list.SetItemData(index, int(key))
class SortedListCtrl(wx.ListCtrl, ColumnSorterMixin):
def __init__(self, parent):
proxys=self.prlist1()


wx.ListCtrl.__init__(self,parent, 8,pos=(10,70),size=(400,200), style=wx.LC_REPORT |wx.LC_HRULES | wx.LC_VRULES)
ColumnSorterMixin.__init__(self, len(proxys))
self.itemDataMap = proxys
def prlist1(self):
conf=Config()
conf.read('settings.ini')
if conf.has_section('proxy')==False:
conf.add_section('proxy')
proxys={}
count=1
for proxy in conf.items('proxy'):

proxys=(proxy[:proxy.find('@')],proxy[proxy.find('@')+1:proxy.find('&')],
proxy[proxy.find('&')+1:proxy.find('^')],proxy[proxy.find('^')+1:])

count=count+1
return proxys
def GetListCtrl(self):
return self








app = wx.App(0)
addBux(None, -1)
app.MainLoop()



Офлайн

#2 Окт. 5, 2008 18:43:59

Ferroman
От:
Зарегистрирован: 2006-11-16
Сообщения: 2759
Репутация: +  1  -
Профиль   Отправить e-mail  

сортировка.. не всегда) wx

Уже не в первый раз прошу - оформляте код нормально.

Офлайн

#3 Окт. 5, 2008 19:12:11

124bit
От:
Зарегистрирован: 2008-04-10
Сообщения: 121
Репутация: +  0  -
Профиль   Отправить e-mail  

сортировка.. не всегда) wx

гм.. простите)) в след раз учтем..

import bz2
import wx
import sys
from ConfigParser import SafeConfigParser as Config
from wx.lib.mixins.listctrl import ColumnSorterMixin




class GUI(wx.Dialog):
def __init__(self, parent, id, title):
wx.Dialog.__init__(self, parent, id, title, size=(400, 200))

wx.Button(self, 1, 'Close', (50, 130))
wx.Button(self, 2, 'Add BUX', (150, 130), (110, -1))

self.Bind(wx.EVT_BUTTON, self.OnClose, id=1)
self.Bind(wx.EVT_BUTTON, self.Open_addBux, id=2)

self.Centre()
self.Show()

def OnClose(self, event):
self.Close(True)

def Open_addBux(self, event):
addBux(None,-1,'11.py')
class FlexGridSizer(wx.Dialog):
def __init__(self):
wx.Dialog.__init__(self,None, -1,'Set proxy', size=(250,210))
proxy = wx.StaticText(self, -1, 'proxy',pos=(10,10)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
login = wx.StaticText(self, -1, 'login',pos=(10,40)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
password = wx.StaticText(self, -1, 'password',pos=(10,70)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
comment = wx.StaticText(self, -1, 'comment',pos=(10,100)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
self.tc1 = wx.TextCtrl(self, -1,pos=(80,10),size=(150,-1))
self.tc2 = wx.TextCtrl(self, -1,pos=(80,40))
self.tc3 = wx.TextCtrl(self, -1,pos=(80,70))
self.tc4 = wx.TextCtrl(self, -1,pos=(80,100),size=(-1,40), style=wx.TE_MULTILINE)
wx.Button(self, 100, 'Ok', (10, 150),size=(80, -1))
wx.Button(self, 101, 'Cancel', (100, 150),size=(80, -1))
self.Bind(wx.EVT_BUTTON, self.OnClose1, id=101)
self.Bind(wx.EVT_BUTTON, self.Apply1, id=100)
self.Centre()
self.ShowModal()
self.Destroy()
def OnClose1(self, event):
self.add=0
self.Close(True)

def Apply1(self, event):
self.proxy_adress=self.tc1.GetValue()
self.proxy_login=self.tc2.GetValue()
self.proxy_password=self.tc3.GetValue()
self.proxy_comment=self.tc4.GetValue()
self.add=1
self.Close(True)
class addBux(FlexGridSizer):
def __init__(self, parent, id):
wx.Dialog.__init__(self, parent, id, 'Add bux', size=(500, 485))
panel = wx.Panel(self, -1)
wx.Button(self, 2, 'Ok', (389, 380),size=(90, 30))
wx.Button(self, 1, 'Cancel', (389, 420),size=(90, -1))
wx.StaticText(self, -1, 'login', (165, 14)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
self.login=wx.TextCtrl(self,4,pos=(194,10),size=(115,-1))
wx.StaticText(self, -1, 'password', (315, 14)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
self.password=wx.TextCtrl(self,5,pos=(373,10),size=(115,-1))
wx.StaticLine(self, -1, (5, 40), (480,1))
self.choise_bux=wx.ComboBox(self, 6, pos=(10, 10), size=(150, -1), choices=['qq','bb'],
style=wx.CB_READONLY | wx.CB_SORT)

self.choise_bux.SetValue('qq')
self.use_proxy=wx.CheckBox(self, 7, 'Use proxy', (10, 50))
self.update_list()




self.new = wx.Button(self, 9, 'New', size=(70, -1),pos=(415,70))
self.dlt = wx.Button(self, 11, 'Delete', size=(70, -1),pos=(415,100))
self.clr = wx.Button(self, 12, 'Clear', size=(70, -1),pos=(415,130))
self.proxy_value=wx.StaticText(self, -1, 'Proxy:', (12,280)).SetFont(wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.BOLD))
self.proxy_text=wx.StaticText(self, -1, '-', (60,280))
self.proxy_text.SetFont(wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.BOLD))
wx.StaticText(self, -1, 'Page view min time random', (10, 315)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
self.timing_viewMin=wx.SpinCtrl(self, 14, '30', (180, 315), (60, -1), min=20, max=120)
wx.StaticText(self, -1, 'Page view max time random', (10, 345)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
self.timing_viewMax=wx.SpinCtrl(self, 15, '40', (180, 345), (60, -1), min=20, max=120)
wx.StaticText(self, -1, 'Between views min time random', (10, 385)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
self.timing_waitMin=wx.SpinCtrl(self, 16, '5', (207, 385), (60, -1), min=1, max=120)
wx.StaticText(self, -1, 'Between views max time random', (10, 415)).SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
self.timing_waitMax=wx.SpinCtrl(self, 17, '10', (207, 415), (60, -1), min=1, max=120)
self.select = wx.Button(self, 18, 'Select', size=(70, 40),pos=(415,230))
self.Bind(wx.EVT_BUTTON, self.NewItem, id=9)

self.Bind(wx.EVT_BUTTON, self.OnDelete, id=11)
self.Bind(wx.EVT_BUTTON, self.OnClear, id=12)
self.Bind(wx.EVT_BUTTON, self.OnSelect, id=18)
self.Bind(wx.EVT_CHECKBOX,self.Proxy_choice, id = 7)
self.Bind(wx.EVT_BUTTON, self.OnClose, id=1)
self.Bind(wx.EVT_BUTTON, self.Apply, id=2)
self.proxy_list.Disable()
self.new.Disable()

self.dlt.Disable()
self.clr.Disable()
self.select.Disable()
self.Centre()
self.Show()
def Proxy_choice(self,event):
if self.use_proxy.GetValue()==True:
self.proxy_list.Enable()
self.new.Enable()

self.dlt.Enable()
self.clr.Enable()
self.select.Enable()
try:
self.proxy
except:
self.proxy='-'
self.proxy_text.SetLabel(self.proxy)

else:
self.proxy_list.Disable()
self.new.Disable()

self.dlt.Disable()
self.clr.Disable()
self.select.Disable()
self.proxy_text.SetLabel('-')
def NewItem(self, event):
proxyadd=FlexGridSizer()
try: proxyadd.add
except: proxyadd.add=0
if proxyadd.add==1:
conf=Config()
conf.read('settings.ini')
if conf.has_section('proxy')==False:
conf.add_section('proxy')
count=1
for proxy in conf.items('proxy'):
if proxy[1][:proxy[1].find('^')]==proxyadd.proxy_adress+'@'+proxyadd.proxy_adress+'&'+proxyadd.proxy_password:
count=0
dial = wx.MessageDialog(None, 'Error: proxy already added', 'Error', wx.OK |
wx.ICON_ERROR)
dial.ShowModal()
dial.Destroy()

if proxyadd.proxy_adress=='' or proxyadd.proxy_adress.find(":")==-1:
count=0
dial = wx.MessageDialog(None, 'Error: invalid proxy address', 'Error', wx.OK |
wx.ICON_ERROR)
dial.ShowModal()
dial.Destroy()

option=1
if count==1:
while conf.has_option('proxy',str(option))==True:
option=option+1
conf.set('proxy',str(option),proxyadd.proxy_adress+'@'+proxyadd.proxy_login+'&'+proxyadd.proxy_password+'^'+proxyadd.proxy_comment)
cf=open('settings.ini','w')
conf.write(cf)
cf.close()
self.proxy_list.ClearAll()
self.update_list()
def OnDelete(self, event):
try:
for i in self.get_selected_items(self.proxy_list):
address=self.proxy_list.GetItem(i,0)
login=self.proxy_list.GetItem(i,1)
password=self.proxy_list.GetItem(i,2)
coment=self.proxy_list.GetItem(i,3)
ini_value=address.GetText()+'@'+login.GetText()+'&'+password.GetText()+'^'+coment.GetText()
conf=Config()
conf.read('settings.ini')
count=0
for item in conf.items('proxy'):
if item[1]==ini_value:
break
count=count+1
conf.remove_option('proxy',conf.items('proxy')[count][0])
sf=open('settings.ini','w')
conf.write(sf)
sf.close()
self.update_list()
except:
pass
def OnClear(self, event):
dial = wx.MessageDialog(None, 'Are you sure, you want to clean all proxies?', 'Question',
wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
if dial.ShowModal() == 5103:
count=1
else:
count=0
dial.Destroy()
if count==1:
conf=Config()
conf.read('Settings.ini')
try: conf.remove_section('proxy')
except: pass
conf.add_section('proxy')
sf=open('settings.ini','w')
conf.write(sf)
sf.close
self.update_list()
def OnSelect(self,event):
try:
self.proxy=self.proxy_list.GetItemText(self.get_selected_items(self.proxy_list)[0])
self.proxy_text.SetLabel(self.proxy)
except:
pass

def get_selected_items(self,list_control):
selection = []


current = -1
while True:
next = self.GetNextSelected(list_control, current)
if next == -1:
return selection

selection.append(next)
current = next

def GetNextSelected(self,list_control, current):
return list_control.GetNextItem(current,
wx.LIST_NEXT_ALL,
wx.LIST_STATE_SELECTED)

def OnClose(self, event):
self.Close(True)
def prlist(self):
conf=Config()
conf.read('settings.ini')
if conf.has_section('proxy')==False:
conf.add_section('proxy')
proxys={}
count=1
for proxy in conf.items('proxy'):

proxys[str(count)]=(proxy[1][:proxy[1].find('@')],proxy[1][proxy[1].find('@')+1:proxy[1].find('&')],
proxy[1][proxy[1].find('&')+1:proxy[1].find('^')],proxy[1][proxy[1].find('^')+1:])

count=count+1
k=proxys.items()
return proxys

def Apply(self, event):
conf=Config()
conf.read('settings.ini')
section = self.choise_bux.GetValue()+''+self.login.GetValue()
if self.login.GetValue()=='' or self.password.GetValue() =='' :
message='Error: '
if self.login.GetValue()=='':
message=message+ 'Login missed '
if self.password.GetValue() =='':
message=message+ 'Password missed '
dial = wx.MessageDialog(None, message, 'Error', wx.OK |
wx.ICON_ERROR)
dial.ShowModal()
dial.Destroy()
count=0
else: count =1
if count==1:
if self.use_proxy.GetValue()==True:
if self.proxy=="-":
dial = wx.MessageDialog(None, 'Error: proxy missed', 'Error', wx.OK |
wx.ICON_ERROR)
dial.ShowModal()
dial.Destroy()
count=0

if count==1:
if conf.has_section(section)==False:
conf.add_section(section)
count=1
else:
dial = wx.MessageDialog(None, 'There is the same PTC with this login, do you want to change its settings?', 'Question',
wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
if dial.ShowModal() == 5103:
count=1
else:
count=0
dial.Destroy()



if count==1:
conf.set(section,'PTC',self.choise_bux.GetValue())
conf.set(section,'username',self.login.GetValue())
conf.set(section,'password',bz2.compress(self.password.GetValue()))
conf.set(section,'view_timeMin',str(self.timing_viewMin.GetValue()))
conf.set(section,'view_timeMax',str(self.timing_waitMax.GetValue()))
conf.set(section,'between_timeMin',str(self.timing_waitMin.GetValue()))
conf.set(section,'between_timeMax',str(self.timing_waitMax.GetValue()))
if self.use_proxy.GetValue()==True:
if self.proxy!='-':
conf.set(section,'proxy_adress',self.proxy)
if self.use_proxy.GetValue()==False:
conf.set(section,'proxy_adress','None')
conf_file=open('settings.ini','w')
conf.write(conf_file)
conf_file.close()
dial = wx.MessageDialog(None,self.choise_bux.GetValue()+' PTC account '+ self.login.GetValue()+' was added', 'Info', wx.OK)
dial.ShowModal()
dial.Destroy()
def update_list(self):
try:self.proxy_list.Destroy()
except: pass
self.proxy_list = SortedListCtrl(self)
self.proxy_list.InsertColumn(0, 'proxy', width=125)
self.proxy_list.InsertColumn(1, 'login', width=80)
self.proxy_list.InsertColumn(2, 'password', width= 80)
self.proxy_list.InsertColumn(4, 'comment',width=93)

items=self.prlist().items()
for key, data in items:
index = self.proxy_list.InsertStringItem(sys.maxint, data[0])
self.proxy_list.SetStringItem(index, 1, data[1])
self.proxy_list.SetStringItem(index, 2, data[2])
self.proxy_list.SetStringItem(index, 3, data[3])
self.proxy_list.SetItemData(index, int(key))
class SortedListCtrl(wx.ListCtrl, ColumnSorterMixin):
def __init__(self, parent):
proxys=self.prlist1()


wx.ListCtrl.__init__(self,parent, 8,pos=(10,70),size=(400,200), style=wx.LC_REPORT |wx.LC_HRULES | wx.LC_VRULES)
ColumnSorterMixin.__init__(self, len(proxys))
self.itemDataMap = proxys
def prlist1(self):
conf=Config()
conf.read('settings.ini')
if conf.has_section('proxy')==False:
conf.add_section('proxy')
proxys={}
count=1
for proxy in conf.items('proxy'):

proxys[count]=(proxy[1][:proxy[1].find('@')],proxy[1][proxy[1].find('@')+1:proxy[1].find('&')],
proxy[1][proxy[1].find('&')+1:proxy[1].find('^')],proxy[1][proxy[1].find('^')+1:])

count=count+1
return proxys
def GetListCtrl(self):
return self








app = wx.App(0)
addBux(None, -1)
app.MainLoop()



Офлайн

#4 Окт. 5, 2008 19:52:21

Ferroman
От:
Зарегистрирован: 2006-11-16
Сообщения: 2759
Репутация: +  1  -
Профиль   Отправить e-mail  

сортировка.. не всегда) wx

OMG там же есть кнопка “Редактировать”.
Кстати “IndexError: list index out of range” есть и при попытке сортировки 3-й колонки.
В коде трудно разобраться - всё скопом, ни одного комментария. Может кто-то и подскажет где проблема, я сходу не увидел.

Офлайн

#5 Окт. 5, 2008 21:42:35

124bit
От:
Зарегистрирован: 2008-04-10
Сообщения: 121
Репутация: +  0  -
Профиль   Отправить e-mail  

сортировка.. не всегда) wx

Ferroman.. погляди еще, пожауйста… я заметил, что когда елемента 4 или больше - все норм, а когда 3 - последняя колонка не сортирует, когда 2 тоже - третья и четвертая не сортирует … и тп.. когда 1 - все кроме первой.. а когда ноль - с любой колонки вылетает.. ((



Офлайн

#6 Окт. 5, 2008 22:19:08

shiza
От:
Зарегистрирован: 2007-07-03
Сообщения: 1073
Репутация: +  0  -
Профиль   Отправить e-mail  

сортировка.. не всегда) wx

здесь ошибка.

ColumnSorterMixin.__init__(self, len(proxys))
передавать надо не число строк, а число столбцов.
(см. конструктор ColumnSorterMixin в файле \site-packages\wx-2.8-msw-unicode\wx\lib\mixins\listctrl.py )



Отредактировано (Окт. 5, 2008 22:20:22)

Офлайн

#7 Окт. 5, 2008 23:59:14

Ferroman
От:
Зарегистрирован: 2006-11-16
Сообщения: 2759
Репутация: +  1  -
Профиль   Отправить e-mail  

сортировка.. не всегда) wx

Почитал последний комент, тоже подумал что дло в том что не то число переда’тся :)

Офлайн

#8 Окт. 6, 2008 00:22:59

124bit
От:
Зарегистрирован: 2008-04-10
Сообщения: 121
Репутация: +  0  -
Профиль   Отправить e-mail  

сортировка.. не всегда) wx

тю(( пасиба огромное) этаж надо было и разобраться и понять в чем причина!
как меня достает писать этот интэрфэйс(( гуи - самое скучное, что может быть..сам текст программы в два раза короче гуи выходит( ..



Отредактировано (Окт. 6, 2008 00:27:04)

Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version