wxpython/lingvigilo.py
author viric <viriketo@gmail.com>
Sun, 13 Feb 2011 08:27:44 +0100
changeset 4 a3d29fb016c3
parent 0 6371497b4e53
permissions -rwxr-xr-x
Adding handling of tab and enter
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
     1
#!/usr/bin/python
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
     3
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
     4
import sys,time,random,string,MySQLdb,re
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
     5
from wxPython.wx import *
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
     6
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
     7
# Configuració
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
     8
legi_el = 'mysql'
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
     9
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    10
# Conf - mysql
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    11
database = 'lingvigilo'
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    12
dbuser = 'lingvigilouser'
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    13
dbpass = 'carrinclo'
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    14
dbtable_vortoj = 'vortoj_ru_ca'
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    15
dbtable_frazoj = 'frazoj_ru_ca'
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    16
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    17
# Conf - fitxer
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    18
dbasefile = 'vortoj-ru-ca.txt'
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    19
frazodosiero = 'frazoj.txt'
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    20
frazoj_al = 'mysql'
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    21
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    22
# Si s'especifica fitxer, l'origen és el fitxer.
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    23
if (len(sys.argv) > 1):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    24
	dbasefile = sys.argv[1]
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    25
	legi_el = 'file'
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    26
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    27
def StringForSQL(str):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    28
	return re.sub(r"'",r"\'", str)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    29
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    30
# Prendre les paraules d'una base de dades MySQL
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    31
def getMySQL():
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    32
	db = MySQLdb.connect(host='vicerveza',user=dbuser,passwd=dbpass,
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    33
		db=database)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    34
	cursor = db.cursor()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    35
	cursor.execute("SELECT * FROM "+dbtable_vortoj)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    36
	res_vortoj = cursor.fetchall()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    37
	res_vortoj_unicode = []
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    38
	for vorto in res_vortoj:
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    39
		vorto_vorto = unicode(vorto[1],'utf8')
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    40
		vorto_tipo = unicode(vorto[2],'utf8')
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    41
		vorto_traduko = unicode(vorto[3],'utf8')
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    42
		
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    43
		# Paràmetres opcionals
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    44
		if vorto[4] == None:
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    45
			vorto_param1 = ''
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    46
		else:
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    47
			vorto_param1 = unicode(vorto[4],'utf8')
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    48
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    49
		if vorto[5] == None:
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    50
			vorto_param2 = ''
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    51
		else:
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    52
			vorto_param2 = unicode(vorto[5],'utf8')
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    53
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    54
		res_vortoj_unicode.append(
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    55
			(vorto_vorto, vorto_tipo, vorto_traduko,
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    56
			vorto_param1, vorto_param2))
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    57
	db.close()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    58
	return res_vortoj_unicode
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    59
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    60
# Prendre les paraules d'un fitxer
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    61
def getFile():
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    62
	dbase = open(dbasefile,"r")
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    63
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    64
	lines = dbase.readlines()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    65
	dbase.close()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    66
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    67
	res_vortoj = []
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    68
	for line in lines:
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    69
		line = line.rstrip('\n')
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    70
		vortoj = string.split(unicode(line.rstrip('\n'),'utf8'),'\t')
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    71
		res_vortoj.append(vortoj)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    72
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    73
	return res_vortoj
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    74
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    75
if legi_el == 'dosiero':
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    76
	print "Legante vortojn el dosiero..."
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    77
	vortoj = getFile()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    78
elif legi_el == 'mysql':
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    79
	print "Legante vortojn el MySQLa datumbazo..."
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    80
	vortoj = getMySQL()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    81
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    82
print "Legitaj", len(vortoj), "vortoj."
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    83
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    84
def AldoniFrazonDosieren(vorto,teksto):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    85
	outfile = open(frazodosiero,"a")
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    86
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    87
	lineout = vorto + "\t" + teksto +"\n"
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    88
	outfile.write(lineout.encode('utf8'))
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    89
	
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    90
	outfile.close()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    91
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    92
def AldoniFrazonDatumbazen(vorto,teksto):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    93
	db = MySQLdb.connect(host='vicerveza',user=dbuser,passwd=dbpass,
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    94
		db=database)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    95
	cursor = db.cursor()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    96
	cursor.execute("INSERT INTO "+
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    97
		StringForSQL(dbtable_frazoj)+
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    98
		" (vorto, frazo) VALUES('%s', '%s');" %
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    99
		(StringForSQL(vorto.encode('utf8')),
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   100
		StringForSQL(teksto.encode('utf8'))))
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   101
	db.close()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   102
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   103
def AldoniFrazon(vorto,teksto):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   104
	if (frazoj_al == 'mysql'):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   105
		AldoniFrazonDatumbazen(vorto,teksto)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   106
	elif (frazoj_al == 'dosiero'):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   107
		AldoniFrazonDosieren(vorto,teksto)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   108
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   109
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   110
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   111
#def LoopFunction():
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   112
#	index = random.randint(0, len(vortoj)-1)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   113
#	vorto = vortoj[index][0]
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   114
#	teksto = askstring("Frazilon", "Skribu frazon por vorto '%s'" % vorto)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   115
#	if teksto == None:
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   116
#		print 'Fi del programa'
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   117
#		sys.exit()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   118
#	AldoniFrazonDatumbazen(vorto, teksto)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   119
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   120
def Senakcentigi(vorto):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   121
	return re.sub(r"'",r"", vorto)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   122
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   123
class main_window(wxFrame):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   124
	def __init__(self, parent, id, title):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   125
		wxFrame.__init__(self, parent, -1, title, size=(200,100),
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   126
			style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   127
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   128
		# Variables de la classe
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   129
		# (sino no tira)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   130
		self.vorto = ("", "")
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   131
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   132
		# Sizer vertical
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   133
		self.topsizer = wxBoxSizer(wxVERTICAL)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   134
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   135
		# Agefim la pregunta i la textbox
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   136
		self.label = wxStaticText(self, -1,
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   137
			label="Skribu frazon per vorto\n 'provo'",
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   138
			style=wxALIGN_CENTER)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   139
		self.textbox = wxTextCtrl(self, -1)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   140
		self.topsizer.Add(self.label, 1, wxALIGN_CENTER,
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   141
			wxALL, 10)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   142
		self.topsizer.Add(self.textbox, 0, wxEXPAND, wxALL, 10)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   143
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   144
		# Afegim botons
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   145
		self.buttonsizer = wxBoxSizer(wxHORIZONTAL)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   146
		okid = wxNewId()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   147
		cancelid = wxNewId()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   148
		helpid = wxNewId()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   149
		okbutton = wxButton(self, okid, "Konservu")
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   150
		# Botó per defecte (resposta a l'intro)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   151
		okbutton.SetDefault()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   152
		self.buttonsizer.Add(okbutton, 0, wxALL, 10)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   153
		cancelbutton = wxButton(self, cancelid, "Forgesu")
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   154
		self.buttonsizer.Add(cancelbutton, 0, wxALL, 10)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   155
		helpbutton = wxButton(self, helpid, "Helpo")
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   156
		self.buttonsizer.Add(helpbutton, 0, wxALL, 10)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   157
		self.topsizer.Add(self.buttonsizer, 0, wxALIGN_CENTER)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   158
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   159
		# EVENTS DE BOTONS
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   160
		EVT_BUTTON(okbutton, okid, self.KonservuFrazon )
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   161
		EVT_BUTTON(cancelbutton, cancelid, self.ForgesuFrazon )
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   162
		EVT_BUTTON(helpbutton, helpid, self.MontruHelpon )
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   163
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   164
		# Key events
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   165
		EVT_KEY_DOWN(self,self.KeyManager)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   166
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   167
		# Activem el sizer principal
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   168
		self.SetSizer(self.topsizer)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   169
		# Mida mínima de finestra.
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   170
		self.topsizer.SetSizeHints(self)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   171
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   172
		# Focus al text
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   173
		self.textbox.SetFocus()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   174
		
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   175
		self.Show(true)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   176
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   177
		# Actualitzem paraula.
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   178
		self.RenovuVorton()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   179
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   180
	def RenovuVorton(self):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   181
		index = random.randint(0, len(vortoj)-1)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   182
		
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   183
		self.vorto = vortoj[index]
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   184
		#print("Elektita vorto: %s" % self.vorto[0])
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   185
		self.label.SetLabel("Skribu frazon per vorto\n'%s'" %
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   186
			Senakcentigi(self.vorto[0]))
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   187
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   188
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   189
	#	if teksto == None:
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   190
	#		print 'Fi del programa'
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   191
	#		sys.exit()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   192
	#	AldoniFrazonDatumbazen(vorto, teksto)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   193
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   194
	def MontruHelpon(self,event):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   195
		mesagxo = ("Vorto: " + self.vorto[0] + "\n" +
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   196
			"Tipo: " + self.vorto[1] + "\n" +
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   197
			"Traduko: " + self.vorto[2] + "\n")
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   198
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   199
		if (self.vorto[1] == "verb"):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   200
			mesagxo = (mesagxo + "Aspekto: " + self.vorto[3] + "\n")
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   201
			aspekto = self.vorto[3]
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   202
			if (self.vorto[3] == u"нсв"):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   203
				aliaaspekto = u"Св"
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   204
			else:
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   205
				aliaaspekto = u"Нсв"
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   206
			mesagxo = (mesagxo + aliaaspekto + ": " +
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   207
				self.vorto[4] + "\n")
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   208
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   209
		wxMessageDialog(self, mesagxo, "Helpo", style=wxOK).ShowModal()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   210
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   211
	def KonservuFrazon(self,event):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   212
		# No guardem cadenes buides
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   213
		if (self.textbox.GetValue() != ""):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   214
			AldoniFrazon(Senakcentigi(self.vorto[0]),
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   215
				self.textbox.GetValue())
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   216
			self.RenovuVorton()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   217
			self.textbox.Clear()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   218
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   219
	def ForgesuFrazon(self,event):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   220
		self.textbox.Clear()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   221
		self.RenovuVorton()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   222
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   223
	def KeyManager(self,event):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   224
		key = event.GetKeyCode()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   225
		if (key == WXK_ESCAPE):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   226
			print("Elirante...")
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   227
			sys.exit()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   228
		elif (key == WXK_TAB):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   229
			# Igual que ForgesuFrazon(self,event)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   230
			# Puc fer-ho passant un event buit?
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   231
			self.ForgesuFrazon(0)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   232
		elif (key == WXK_F1):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   233
			self.MontruHelpon(0)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   234
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   235
class App(wxApp):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   236
	def OnInit(self):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   237
		frame = main_window(None, -1, "Lingvigilo")
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   238
		self.SetTopWindow(frame)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   239
		return true
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   240
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   241
#def DemandiAlUzanto():
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   242
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   243
# Main program
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   244
app=App(0)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
   245
app.MainLoop()