KeyError

Indította Deadly2000, 2018-05-27, 17:35:14

Sziasztok , adott egy csatornaváltó, rengetek hiba volt benne ,de ezt nem sikerült megoldanom. :

SwitchChannel.__LoadWindow - error - <type 'exceptions.KeyError'>:'CHANNEL_1_NORMAL'

Az uiScritbe megvan írva hozzá :

{
"name" : "CHANNEL_1_NORMAL",
"type" : "button",

"x" : 8,
"y" : 6,

"text" : uiScriptLocale.SYSTEM_SWITCH_CHANNEL_CH1,

"default_image" : "d:/ymir work/ui/game/myshop_deco/select_btn_01.sub",
"over_image" : "d:/ymir work/ui/game/myshop_deco/select_btn_02.sub",
"down_image" : "d:/ymir work/ui/game/myshop_deco/select_btn_03.sub",
},



Maga a Python kódja pedig így néz ki .


import ui
import chat
import wndMgr
import player
import localeInfo
import net

class OptionDialog(ui.ScriptWindow):

def __init__(self):
self.isLoaded = False
self.channels = 4
self.channel_id = 0
self.ChannelButtonList = []
ui.ScriptWindow.__init__(self)
self.__LoadWindow()

def __del__(self):
ui.ScriptWindow.__del__(self)

def Destroy(self):
self.ChannelButtonList = []
self.isLoaded = False
self.cancelButton = None
self.board = None

def Show(self):
self.__LoadWindow()
for btn in self.ChannelButtonList:
btn.Show()

ui.ScriptWindow.Show(self)

def Close(self):
self.Hide()

def __LoadWindow(self):
if self.isLoaded:
return

self.isLoaded = True

try:
pyScrLoader = ui.PythonScriptLoader()
pyScrLoader.LoadScriptFile(self, "UIScript/SwitchChannel.py")

self.changeButton = self.GetChild("change")
self.cancelButton = self.GetChild("cancel")

#Channel_Buttons_Normal
self.Channel_1_Normal = self.GetChild("CHANNEL_1_NORMAL")
self.Channel_2_Normal = self.GetChild("CHANNEL_2_NORMAL")
self.Channel_3_Normal = self.GetChild("CHANNEL_3_NORMAL")
self.Channel_4_Normal = self.GetChild("CHANNEL_4_NORMAL")

#Channel_Buttons_Select
self.Channel_1_Select = self.GetChild("CHANNEL_1_SELECT")
self.Channel_2_Select = self.GetChild("CHANNEL_2_SELECT")
self.Channel_3_Select = self.GetChild("CHANNEL_3_SELECT")
self.Channel_4_Select = self.GetChild("CHANNEL_4_SELECT")

self.changeButton.SAFE_SetEvent(self.__Channel_switch)
self.cancelButton.SAFE_SetEvent(self.OnPressEscapeKey)

self.board = self.GetChild("board")

self.Channel_1_Normal.SetEvent(ui.__mem_func__(self.__OnClickCh1Button))
self.Channel_2_Normal.SetEvent(ui.__mem_func__(self.__OnClickCh2Button))
self.Channel_3_Normal.SetEvent(ui.__mem_func__(self.__OnClickCh3Button))
self.Channel_4_Normal.SetEvent(ui.__mem_func__(self.__OnClickCh4Button))

self.board.SetCloseEvent(ui.__mem_func__(self.Close))

if self.channels == 1:
self.Channel_1_Normal.Show()
self.Channel_2_Normal.Hide()
self.Channel_3_Normal.Hide()
self.Channel_4_Normal.Hide()

self.Channel_1_Select.Hide()
self.Channel_2_Select.Hide()
self.Channel_3_Select.Hide()
self.Channel_4_Select.Hide()


elif self.channels == 2:
self.Channel_1_Normal.Show()
self.Channel_2_Normal.Show()
self.Channel_3_Normal.Hide()
self.Channel_4_Normal.Hide()

self.Channel_1_Select.Hide()
self.Channel_2_Select.Hide()
self.Channel_3_Select.Hide()
self.Channel_4_Select.Hide()

elif self.channels == 3:
self.Channel_1_Normal.Show()
self.Channel_2_Normal.Show()
self.Channel_3_Normal.Show()
self.Channel_4_Normal.Hide()

self.Channel_1_Select.Hide()
self.Channel_2_Select.Hide()
self.Channel_3_Select.Hide()
self.Channel_4_Select.Hide()

elif self.channels == 4:
self.Channel_1_Normal.Show()
self.Channel_2_Normal.Show()
self.Channel_3_Normal.Show()
self.Channel_4_Normal.Show()

self.Channel_1_Select.Hide()
self.Channel_2_Select.Hide()
self.Channel_3_Select.Hide()
self.Channel_4_Select.Hide()

else:
self.Channel_1_Normal.Show()
self.Channel_2_Normal.Show()
self.Channel_3_Normal.Show()
self.Channel_4_Normal.Show()

self.Channel_1_Select.Hide()
self.Channel_2_Select.Hide()
self.Channel_3_Select.Hide()
self.Channel_4_Select.Hide()

self.Show()
except:
import exception
exception.Abort("SwitchChannel.__LoadWindow - error")

def __OnClickCh1Button(self):
self.channel_id = 1
self.Channel_1_Normal.Hide()
self.Channel_1_Select.Show()


self.Channel_2_Select.Hide()
self.Channel_3_Select.Hide()
self.Channel_4_Select.Hide()

self.Channel_2_Normal.Show()
self.Channel_3_Normal.Show()
self.Channel_4_Normal.Show()

def __OnClickCh2Button(self):
self.channel_id = 2
self.Channel_2_Normal.Hide()
self.Channel_2_Select.Show()

self.Channel_1_Select.Hide()
self.Channel_3_Select.Hide()
self.Channel_4_Select.Hide()

self.Channel_1_Normal.Show()
self.Channel_3_Normal.Show()
self.Channel_4_Normal.Show()

def __OnClickCh3Button(self):
self.channel_id = 3
self.Channel_3_Normal.Hide()
self.Channel_3_Select.Show()

self.Channel_1_Select.Hide()
self.Channel_2_Select.Hide()
self.Channel_4_Select.Hide()

self.Channel_1_Normal.Show()
self.Channel_2_Normal.Show()
self.Channel_4_Normal.Show()

def __OnClickCh4Button(self):
self.channel_id = 4
self.Channel_4_Normal.Hide()
self.Channel_4_Select.Show()

self.Channel_1_Select.Hide()
self.Channel_2_Select.Hide()
self.Channel_3_Select.Hide()

self.Channel_1_Normal.Show()
self.Channel_2_Normal.Show()
self.Channel_3_Normal.Show()

def __Channel_switch(self):
if self.channel_id == 0:
chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.CHANNEL_SWITCH_NOT_SELECT)
elif self.channel_id > self.channels:
chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.CHANNEL_SWITCH_NOT_FIND)
else:
net.SendChatPacket("/ch " + str(self.channel_id))
self.Close()

def OnPressEscapeKey(self):
self.Close()