PHP Code:
#
# PythonLoader Manager by ©Risan aka Zymos
# Version 1.0
# Created: 31.07.2014
#
import ui
import chat
import mouseModule
import sys
import os
import fnmatch
import dbg
import app
PythonLoaderDatas = [
#{"FileName":"test","Path":'D:/Metin2/New Developer Client/ExternPythonScriptsLoader/test'},
]
class FuncWindow(ui.Window):
def __init__(self):
ui.Window.__init__(self)
# module = '\ExternPythonScriptsLoader\test' #not works
# module = 'D:\Metin2\New Developer Client\ExternPythonScriptsLoader\test' #not works
# module = 'D:/Metin2/New Developer Client/ExternPythonScriptsLoader/test' # works
# module = '/ExternPythonScriptsLoader/test' #not works
# module = 'test' # works wenn direkt im hauptverzeicnis
#__import__(module)
width = 110
heigh = 225
self.PythonBoardLoader = ui.BoardWithTitleBar()
self.PythonBoardLoader.SetSize(width+25+100,heigh+20)
self.PythonBoardLoader.SetTitleName('PythonLoader by ©Risan')
self.PythonBoardLoader.SetCenterPosition()
#self.PythonBoardLoader.SetPosition((wndMgr.GetScreenWidth() - self.GetWidth()) / 2 +270, (wndMgr.GetScreenHeight() - self.GetHeight()) / 2 - 130)
self.PythonBoardLoader.AddFlag('movable')
self.PythonBoardLoader.Hide()
self.PythonListBoxLoder = ui.ListBox()
self.PythonListBoxLoder.SetParent(self.PythonBoardLoader)
self.PythonListBoxLoder.SetPosition(55, 35)
self.PythonListBoxLoder.SetSize(width, heigh)
self.PythonListBoxLoder.SetEvent(self.GetDataFromSelectPythonLoader)
self.PythonListBoxLoder.Show()
self.PythonScrollLoader = ui.ScrollBar()
self.PythonScrollLoader.SetParent(self.PythonBoardLoader)
self.PythonScrollLoader.SetPosition(210, 35)
self.PythonScrollLoader.SetScrollBarSize(heigh-30)
self.PythonScrollLoader.SetScrollEvent(ui.__mem_func__(self.OnScrollPythonLoader))
#self.PythonScrollLoader.SetScrollStep(0.10)
self.PythonScrollLoader.Show()
self.PythonLoaderButtonLoad = ui.Button()
self.PythonLoaderButtonLoad.SetParent(self.PythonBoardLoader)
self.PythonLoaderButtonLoad.SetUpVisual("d:/ymir work/ui/public/middle_button_01.sub")
self.PythonLoaderButtonLoad.SetOverVisual("d:/ymir work/ui/public/middle_button_02.sub")
self.PythonLoaderButtonLoad.SetDownVisual("d:/ymir work/ui/public/middle_button_03.sub")
self.PythonLoaderButtonLoad.SetPosition(15, 211)
self.PythonLoaderButtonLoad.SetText("Load")
self.PythonLoaderButtonLoad.SetEvent(self.LoadModulPythonLoader)
self.PythonLoaderButtonLoad.Show()
self.PythonLoaderButtonRefresh = ui.Button()
self.PythonLoaderButtonRefresh.SetParent(self.PythonBoardLoader)
self.PythonLoaderButtonRefresh.SetUpVisual("d:/ymir work/ui/public/middle_button_01.sub")
self.PythonLoaderButtonRefresh.SetOverVisual("d:/ymir work/ui/public/middle_button_02.sub")
self.PythonLoaderButtonRefresh.SetDownVisual("d:/ymir work/ui/public/middle_button_03.sub")
self.PythonLoaderButtonRefresh.SetPosition(15+65, 211)
self.PythonLoaderButtonRefresh.SetText("Refresh")
self.PythonLoaderButtonRefresh.SetEvent(self.LoadList)
self.PythonLoaderButtonRefresh.Show()
self.PythonLoaderButtonEntLoad = ui.Button()
self.PythonLoaderButtonEntLoad.SetParent(self.PythonBoardLoader)
self.PythonLoaderButtonEntLoad.SetUpVisual("d:/ymir work/ui/public/middle_button_01.sub")
self.PythonLoaderButtonEntLoad.SetOverVisual("d:/ymir work/ui/public/middle_button_02.sub")
self.PythonLoaderButtonEntLoad.SetDownVisual("d:/ymir work/ui/public/middle_button_03.sub")
self.PythonLoaderButtonEntLoad.SetPosition(15+65+65, 211)
self.PythonLoaderButtonEntLoad.SetText("Unload")
self.PythonLoaderButtonEntLoad.SetEvent(ui.__mem_func__(self.UnLoadModulPythonLoader))
self.PythonLoaderButtonEntLoad.Show()
self.FirstCountLine = 0
self.LoadList()
def __del__(self):
ui.Window.__del__(self)
def LoadList(self):
self.PythonLoadExternScriptPath = 'ExternPythonScriptsLoader'
self.SelectfileName = ""
self.SelectfilePath = ""
global PythonLoaderDatas
PythonLoaderDatas = { }
PythonLoaderDatas = [ ]
try:
CurrendDirOld = os.path.abspath(".") + "/"+str(self.PythonLoadExternScriptPath + "/") #os.getcwd()
CurrendDir = CurrendDirOld.replace(unichr(92),unichr(47))
#chat.AppendChat(1,"CurrenDir: " + str(CurrendDir))
for file in os.listdir('%s/' % self.PythonLoadExternScriptPath ): #Listet Dateien auf
newfile = file.replace(".py","")
module = CurrendDir+newfile
#chat.AppendChat(1,"module: " + str(module))
if fnmatch.fnmatch(file,"*.py"):
PythonLoaderDatas.append({"FileName":str(newfile), "Path":str(module)})
if len(PythonLoaderDatas) < self.PythonLoaderMaxViewList():
self.PythonScrollLoader.Hide()
else:
self.PythonScrollLoader.Show()
self.PythonScrollLoader.SetMiddleBarSize(float(self.PythonLoaderMaxViewList()) / float(len(PythonLoaderDatas)))
self.OnScrollPythonLoader()
self.RefreshScrollListPythonLoader()
except:
pass
def UnLoadModulPythonLoader(self):
module = str(self.SelectfilePath)
try:
if module in sys.modules:
chat.AppendChat(1,"Unload script file: " + str(self.SelectfileName) + " Module: " + str(module))
del(sys.modules[module])
else:
chat.AppendChat(1,"Is not loaded script file: " + str(self.SelectfileName))
except:
chat.AppendChat(1,"Failed to Unload python script file: %s" % (module))
def LoadModulPythonLoader(self):
module = str(self.SelectfilePath)
try:
chat.AppendChat(1,"Load script file: " + str(self.SelectfileName) + " Module: " + str(module))
if module in sys.modules:
del(sys.modules[module])
__import__(module)
except:
chat.AppendChat(1,"Failed to load python script file: %s" % (module))
def GetDataFromSelectPythonLoader(self,arg1,arg2):
global PythonLoaderDatas
self.SelectfileName = arg2
#chat.AppendChat(1,"GetDataFromSelectPythonLoader: answer")
#chat.AppendChat(1,"GetDataFromSelectPythonLoader: arg1 + FirstCountLine:"+ str(arg1 + (self.FirstCountLine*10) ))
#chat.AppendChat(1,"GetDataFromSelectPythonLoader: arg2:"+ str(arg2))
GetFileName = ""
GetPath = ""
for i in xrange(len(PythonLoaderDatas)):
try:
GetFileName = PythonLoaderDatas[i]["FileName"]
GetPath = PythonLoaderDatas[i]["Path"]
except:
self.SelectfileName = ""
self.SelectfilePath = ""
GetFileName = ""
GetPath = ""
if GetFileName == self.SelectfileName:
self.SelectfilePath = GetPath
#chat.AppendChat(1,"Lade File: " + str(self.SelectfileName) + " Path: " + str(self.SelectfilePath))
return
self.SelectfileName = ""
self.SelectfilePath = ""
def PythonLoaderMaxViewList(self):
return 10
def OnScrollPythonLoader(self):
#chat.AppendChat(1,"OnScrollPythonLoader Count of Datas:" +str(len(PythonLoaderDatas)))
PythonLoderscrollLineCount = max(0, (len(PythonLoaderDatas)) - self.PythonLoaderMaxViewList())
PythonLoaderStartIndex = int(PythonLoderscrollLineCount * self.PythonScrollLoader.GetPos())
#chat.AppendChat(1,"OnScrollPythonLoader PythonLoderscrollLineCount:" +str(PythonLoderscrollLineCount) + " self.PythonScrollLoader.GetPos: " + str(self.PythonScrollLoader.GetPos()) )
#chat.AppendChat(1,"OnScrollPythonLoader PythonLoaderStartIndex:" +str(PythonLoaderStartIndex) + " self.FirstCountLine: " + str(self.FirstCountLine) )
if PythonLoaderStartIndex != self.FirstCountLine: #Refresht nur die anzeige wenn ein neuer Index berechnet worden ist.
self.FirstCountLine = PythonLoaderStartIndex
self.RefreshScrollListPythonLoader()
def RefreshScrollListPythonLoader(self):
#chat.AppendChat(1,"RefreshScrollListPythonLoader anwerr")
self.PythonListBoxLoder.ClearItem()
for i in xrange(self.PythonLoaderMaxViewList()):
#chat.AppendChat(1,"RefreshScrollListPythonLoader i" +str(i))
try:
Name = PythonLoaderDatas[i + self.FirstCountLine ]["FileName"]
#chat.AppendChat(1,"RefreshScrollListPythonLoader Name" +str(Name))
self.PythonListBoxLoder.InsertItem(i,str(Name))
except:
print("ERROR RefreshScrollListPythonLoader of Read")
def Destroy(self):
self.PythonBoardLoader = None
def OpenWindow(self):
SelfFucking = 0
if self.PythonBoardLoader.IsShow():
self.PythonBoardLoader.Hide()
else:
self.PythonBoardLoader.Show()
# if __USE_CYTHON__ or SelfFucking == 1:
# dbg.TraceError("This Binary use CYTHON! Cannot use PythonLoader!")
# dbg.LogBox("This Binary use CYTHON! Cannot use PythonLoader!")
# app.Exit()
def Close(self):
self.PythonBoardLoader.Hide()
def Open(self):
self.PythonBoardLoader.Show()






