Jump to content

Trying to send multiple login saver system to read popups from locale.


Recommended Posts

Hi guys!

I am two steps away from finishing my interface customization and I encounter two situations that I am not able to handle by myself since I am not a programmer. I was hoping that some of you may help me figure it out.

I have a this system implemented and is not built for multilanguage as all the popups are writen in the root part. I'd like to sent all  self.__PopupMessage to localeInfo.

Link for the system I am using:

Multiple Login Saver System - Features & Metin2 Systems - Metin2Dev | M2Dev

The code of my uiselectcredentials.py

import s9s as app
import ui
import localeInfo
import uiScriptLocale
import intrologin

FILE_NAME_LEN = 20
DEFAULT_THEMA = ''

class Item(ui.ListBoxEx.Item):
	def __init__(self, fileName):
		ui.ListBoxEx.Item.__init__(self)
		self.canLoad=0
		self.text=fileName
		self.textLine=self.__CreateTextLine(fileName[:FILE_NAME_LEN])

	def __del__(self):
		ui.ListBoxEx.Item.__del__(self)

	def GetText(self):
		return self.text

	def SetSize(self, width, height):
		ui.ListBoxEx.Item.SetSize(self, 6*len(self.textLine.GetText()) + 4, height)

	def __CreateTextLine(self, fileName):
		textLine=ui.TextLine()
		textLine.SetParent(self)

		if localeInfo.IsARABIC():
			textLine.SetPosition(6*len(fileName) + 6, 0)
		else:
			textLine.SetPosition(0, 0)

		textLine.SetText(fileName)
		textLine.Show()
		return textLine

class PopupDialog(ui.ScriptWindow):
	def __init__(self, parent):
		ui.ScriptWindow.__init__(self)
		self.__Load()
		self.__Bind()

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

	def __Load(self):
		try:
			pyScrLoader = ui.PythonScriptLoader()
			pyScrLoader.LoadScriptFile(self, "UIScript/PopupDialog.py")
		except:
			import exception
			exception.Abort("PopupDialog.__Load")

	def __Bind(self):
		try:
			self.textLine=self.GetChild("message")
			self.okButton=self.GetChild("accept")
		except:
			import exception
			exception.Abort("PopupDialog.__Bind")

		self.okButton.SAFE_SetEvent(self.__OnOK)

	def Open(self, msg):
		self.textLine.SetText(msg)
		self.SetCenterPosition()
		self.Show()
		self.SetTop()

	def __OnOK(self):
		self.Hide()

	def __OnSterge(self):
		self.Hide()

class FileListDialog(ui.ScriptWindow):
	def __init__(self):
		ui.ScriptWindow.__init__(self)

		self.isLoaded=0
		self.selectEvent=None
		self.fileListBox=None
		self.connect=None
	def __del__(self):
		ui.ScriptWindow.__del__(self)

	def Show(self):
		if self.isLoaded==0:
			self.isLoaded=1

			self.__Load()

		ui.ScriptWindow.Show(self)

	def Open(self, type):
		self.Show()

		self.SetCenterPosition()
		self.SetTop()

		if self.fileListBox.IsEmpty():
			type self.__PopupMessage("Nu ai niciun cont salvat!")

	def Close(self):
		self.popupDialog.Hide()
		self.Hide()

	def OnPressEscapeKey(self):
		self.Close()
		return True

	def SAFE_SetSelectEvent(self, event):
		self.selectEvent=ui.__mem_func__(event)

	def __CreateFileListBox(self):
		fileListBox=ui.ListBoxEx()
		fileListBox.SetParent(self)

		if localeInfo.IsARABIC():
			fileListBox.SetPosition( self.GetWidth() - fileListBox.GetWidth() - 10, 50)
		else:
			fileListBox.SetPosition(15, 50)

		fileListBox.Show()
		return fileListBox

	def __Load(self):
		self.popupDialog=PopupDialog(self)

		if localeInfo.IsARABIC():
			self.__Load_LoadScript(uiScriptLocale.LOCALE_UISCRIPT_PATH + "AccountWindow.py")
		else:
			self.__Load_LoadScript("UIScript/AccountListWindow.py")

		self.__Load_BindObject()

		self.refreshButton.SAFE_SetEvent(self.__OnRefresh)
		self.cancelButton.SAFE_SetEvent(self.__OnCancel)
		self.stergeButton.SAFE_SetEvent(self.__OnSterge)
		self.okButton.SAFE_SetEvent(self.__OnOK)
		self.board.SetCloseEvent(ui.__mem_func__(self.__OnCancel))
		self.UpdateRect()

		self.__RefreshFileList()

	def __Load_LoadScript(self, fileName):
		try:
			pyScrLoader = ui.PythonScriptLoader()
			pyScrLoader.LoadScriptFile(self, fileName)
		except:
			import exception
			exception.Abort("AccountListBox.__Load")

	def __Load_BindObject(self):
		try:
			self.fileListBox=self.__CreateFileListBox()
			self.fileListBox.SetScrollBar(self.GetChild("ScrollBar"))

			self.board=self.GetChild("board")
			self.okButton=self.GetChild("ok")
			self.stergeButton=self.GetChild("sterge")
			self.cancelButton=self.GetChild("cancel")
			self.refreshButton=self.GetChild("refresh")

			self.popupText = self.popupDialog.GetChild("message")

		except:
			import exception
			exception.Abort("MusicListBox.__Bind")

	def __PopupMessage(self, msg):
		self.popupDialog.Open(msg)

	def __OnOK(self):
		selItem=self.fileListBox.GetSelectedItem()
		if selItem:
			if self.selectEvent:
				self.selectEvent(selItem.GetText())
			with open('user//preferred','w') as mainpg:
				mainpg.write("{};{}".format(selItem.GetText(),self.GetPwdFromId(selItem.GetText())) )
			self.__PopupMessage("Contul cu numele {} este selectat.".format(selItem.GetText()))
			self.Hide()
		else:
			self.__PopupMessage("Nu ai selectat un cont.")

	def __OnSterge(self):
		selItem=self.fileListBox.GetSelectedItem()
		if selItem:
			if self.selectEvent:
				self.selectEvent(selItem.GetText())
			with open('user//credentials', 'r+') as f:
				data = ''.join([i for i in f if not i.lower().startswith(selItem.GetText())])
				f.seek(0)
				f.write(data)
				f.truncate()
			self.__PopupMessage("{} a fost sters.".format(selItem.GetText()))
			self.__RefreshFileList()
		else:
			self.__PopupMessage("Nu ai ales niciun cont din lista.")

	def __OnCancel(self):
		self.Hide()

	def __OnRefresh(self):
		self.__RefreshFileList()

	def __RefreshFileList(self):
		self.__ClearFileList()
		#self.__AppendFile(DEFAULT_THEMA)
		self.__AppendFileList()

	def __ClearFileList(self):
		self.fileListBox.RemoveAllItems()

	def __AppendFileList(self):
		data = self.CredentialsToDict()
		for id in data:
			self.__AppendFile(id)
		
	def CredentialsToDict(self):
		data = dict()
		try:
			fileList = open('user//credentials','r')	
			for line in fileList:
				if ":" in line:
					key,value = line.split(':',1)
					data[key]=value
			fileList.close()			
			return data		
		except:
			self.__PopupMessage("Nu ai lista cu conturi!")
			return ''

		
	def GetPwdFromId(self, id):
		data = self.CredentialsToDict()
		return (data[id])
		
	def __AppendFile(self, fileName):
		self.fileListBox.AppendItem(Item(fileName))

Your help will be highly appreciated!

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.