checking in I hope

This commit is contained in:
saijanai.kuhn
2009-03-31 02:16:05 +00:00
committed by Salad Dais
parent 84116923c3
commit ade5bf6a16
3 changed files with 439 additions and 0 deletions

View File

@@ -0,0 +1,114 @@
import wx
import pprint
about_txt = """
This demos a login dialog to be used by generic sample scripts for pyogp"""
class DataXferValidator(wx.PyValidator):
def __init__(self, data, key):
wx.PyValidator.__init__(self)
self.data = data
self.key = key
def Clone(self):
"""
Declaring the validator
Licensed to Lawson English <LEnglish5@cox.net>
Using validators to manage data in a dialog 287
Note that every validator must implement the Clone() method.
"""
return DataXferValidator(self.data, self.key)
def Validate(self, win):
textCtrl = self.GetWindow()
text = textCtrl.GetValue()
if ((len(text) == 0) & (self.key != "region")) :
wx.MessageBox("This field must contain some text!", "Error")
textCtrl.SetBackgroundColour("pink")
textCtrl.SetFocus()
textCtrl.Refresh()
return False
else:
textCtrl.SetBackgroundColour(
wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
textCtrl.Refresh()
return True
def TransferToWindow(self):
textCtrl = self.GetWindow()
textCtrl.SetValue(self.data.get(self.key, ""))
return True
def TransferFromWindow(self):
textCtrl = self.GetWindow()
self.data[self.key] = textCtrl.GetValue()
return True
class MyDialog(wx.Dialog):
def __init__(self, data):
wx.Dialog.__init__(self, None, -1, "Validators: data transfer")
self.returnvalue = None
about = wx.StaticText(self, -1, about_txt)
first_name_l = wx.StaticText(self, -1, "First Name:")
last_name_l = wx.StaticText(self, -1, "Last Name:")
password_l = wx.StaticText(self, -1, "Password:")
loginuri_l = wx.StaticText(self, -1, "loginuri:")
region_l = wx.StaticText(self, -1, "region:")
first_name = wx.TextCtrl(self,
validator=DataXferValidator(data, "First Name"))
last_name = wx.TextCtrl(self,
validator=DataXferValidator(data, "Last Name"))
password = wx.TextCtrl(self,
validator=DataXferValidator(data, "Password"))
loginuri = wx.TextCtrl(self,
validator=DataXferValidator(data, "loginuri"))
region = wx.TextCtrl(self,
validator=DataXferValidator(data, "region"))
okay = wx.Button(self, wx.ID_OK)
okay.SetDefault()
cancel = wx.Button(self, wx.ID_CANCEL)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(about, 0, wx.ALL, 5)
sizer.Add(wx.StaticLine(self), 0, wx.EXPAND|wx.ALL, 5)
fgs = wx.FlexGridSizer(3, 2, 5, 5)
fgs.Add(first_name_l, 0, wx.ALIGN_RIGHT)
fgs.Add(first_name, 0, wx.EXPAND)
fgs.Add(last_name_l, 0, wx.ALIGN_RIGHT)
fgs.Add(last_name, 0, wx.EXPAND)
fgs.Add(password_l, 0, wx.ALIGN_RIGHT)
fgs.Add(password, 0, wx.EXPAND)
fgs.Add(loginuri_l, 0, wx.ALIGN_RIGHT)
fgs.Add(loginuri, 0, wx.EXPAND)
fgs.Add(region_l, 0, wx.ALIGN_RIGHT)
fgs.Add(region, 0, wx.EXPAND)
fgs.AddGrowableCol(1)
sizer.Add(fgs, 0, wx.EXPAND|wx.ALL, 5)
btns = wx.StdDialogButtonSizer()
btns.AddButton(okay)
btns.AddButton(cancel)
btns.Realize()
sizer.Add(btns, 0, wx.EXPAND|wx.ALL, 5)
self.SetSizer(sizer)
sizer.Fit(self)
def main():
app = wx.PySimpleApp()
data = { "First Name" : "first", "Last Name" : "last", "Password":"secretsauce",
"loginuri" : "https://login.aditi.lindenlab.com/cgi-bin/login.cgi",
"region" : ""}
dlg = MyDialog(data)
dlg.ShowModal()
print dlg.GetReturnCode()
dlg.Destroy()
wx.MessageBox("You entered these values:\n\n" +
pprint.pformat(data))
app.MainLoop()
if __name__=="__main__":
main()

View File

@@ -0,0 +1,40 @@
#! /usr/bin/python
#
# This file bears no copyright and is placed in the Public Domain by its author.
#
import os
import sys
about_txt = """
Grabs the user's config data from ~/.pyogp/*
This currently only handles ~/.pyogp/login_data.py
Load in other config files and extend instance variables to suit."""
class login_data():
def __init__(self):
default_data = {"Description" : "Default login data",
"First Name" : "First",
"Last Name" : "Last",
"Password" : "secretsauce",
"loginuri" : "https://login.aditi.lindenlab.com/cgi-bin/login.cgi",
"region" : ""}
config = {'logins' : None, 'default_login': None}
logins_config_file = os.environ["HOME"] + '/.pyogp/login_data.py'
if os.path.exists(logins_config_file):
try:
execfile(logins_config_file, {}, config)
except Exception, e:
print "Configuration file %s is not valid Python, fix it --> %s" % (logins_config_file, str(e))
sys.exit(2)
else:
config = {'logins' : [default_data], 'default_login': 0}
self.logins = config['logins']
self.selected_login_number = config['default_login']
self.selected_login_data = self.logins[self.selected_login_number]
def main():
print login_data().selected_login_data
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,285 @@
#!/usr/bin/python
"""
@file sample_agent_login.py
@date 2009-02-16
Contributors can be viewed at:
http://svn.secondlife.com/svn/linden/projects/2008/pyogp/CONTRIBUTORS.txt
$LicenseInfo:firstyear=2008&license=apachev2$
Copyright 2008, Linden Research, Inc.
Licensed under the Apache License, Version 2.0 (the "License").
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
or in
http://svn.secondlife.com/svn/linden/projects/2008/pyogp/LICENSE.txt
$/LicenseInfo$
"""
# standard
import re
import getpass, sys, logging
from optparse import OptionParser
from eventlet import api
# wx
import wx, datetime, time
import testdialog
import user_config
import pprint
# pyogp
from pyogp.lib.base.agent import Agent
from pyogp.lib.base.settings import Settings
class LoggerTextCntl(wx.TextCtrl):
def write(self, text):
"""
Write the text to the LoggerTextCntl instance
If not called in the context of the gui thread then uses
CallAfter to do the work there.
"""
if not wx.Thread_IsMain():
wx.CallAfter(self.__write, text)
else:
self.__write(text)
def __write(self, text):
# helper function for actually writing the text.
self.AppendText(text)
def flush(self):
pass
class TestFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(1200, 700))
panel = wx.Panel(self)
global not_closed_window
not_closed_window = True
self.timertext = LoggerTextCntl(panel, 1, "",
style=wx.TE_MULTILINE|wx.TE_READONLY, size = (150,400))
self.msgtext = LoggerTextCntl(panel, 2, "",
style=wx.TE_MULTILINE|wx.TE_READONLY, pos = (151,0),size = (1049,400))
self.errtext = LoggerTextCntl(panel, 3, "",
style=wx.TE_MULTILINE|wx.TE_READONLY, pos = (151,401),size = (1049,200))
self.mybutton = wx.Button(panel, 4, 'Pause/Resume', (10, 620))
self.Login = wx.Button(panel, 5, 'Login', (10, 650))
self.Bind(wx.EVT_BUTTON, self.OnPause, id=4)
self.Bind(wx.EVT_BUTTON, self.OnLogin, id=5)
self.Centre()
self.eqg = None
self.gotimer =True
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
self.Bind(wx.EVT_CLOSE, self.onCloseWindow)
self.timer.Start(100)
self.Show(True)
def OnTimer(self, event):
wx.GetApp().DoTimer(event)
def OnPause(self, event):
if self.gotimer == True:
self.timer.Stop()
self.gotimer = False
else:
self.timer.Start(100)
self.gotimer = True
def OnLogin(self,event):
wx.MessageBox("Logging in", "OK")
def onCloseWindow(self,event):
#self.timer.Stop()
#self.eqg.contenew = False
#wx.GetApp().avatar_obj.tearDown()
sys.stdout = sys.stderr = wx.GetApp().savedstdio
#i = 0
#while i<20:
#print i
#print self.eqg
#if not self.eqg.isAlive():break
#time.sleep(1)
#i +=1
logging.shutdown()
global not_closed_window
not_closed_window = False
self.Destroy()
def DoLoginDialog():
data = { "First Name" : "First", "Last Name" : "Last", "Password":"secretsauce",
"loginuri" : "https://login.aditi.lindenlab.com/cgi-bin/login.cgi",
"region" : ""}
data = user_config.login_data().selected_login_data
dlg = testdialog.MyDialog(data)
api.spawn(dlg.ShowModal)
while True:
api.sleep(0)
code = dlg.GetReturnCode()
if ((code == 5100 ) or (code == 5101)):
break
dlg.Destroy()
wx.MessageBox("You entered these values:\n\n" +
pprint.pformat(data))
return data
def login():
""" login an to a login endpoint """
logindata = DoLoginDialog()
parser = OptionParser()
logger = logging.getLogger("pyogp.lib.base.example")
parser.add_option("-l", "--loginuri", dest="loginuri", default="https://login.aditi.lindenlab.com/cgi-bin/login.cgi",
help="specified the target loginuri")
parser.add_option("-r", "--region", dest="region", default=None,
help="specifies the region to connect to")
#http://ec2-75-101-203-98.compute-1.amazonaws.com:9000
parser.add_option("-q", "--quiet", dest="verbose", default=True, action="store_false",
help="enable verbose mode")
(options, args) = parser.parse_args()
if options.verbose:
console = logging.StreamHandler()
console.setLevel(logging.DEBUG) # seems to be a no op, set it for the logger
formatter = logging.Formatter('%(asctime)-30s%(name)-30s: %(levelname)-8s %(message)s')
console.setFormatter(formatter)
logging.getLogger('').addHandler(console)
# setting the level for the handler above seems to be a no-op
# it needs to be set for the logger, here the root logger
# otherwise it is NOTSET(=0) which means to log nothing.
logging.getLogger('').setLevel(logging.DEBUG)
else:
print "Attention: This script will print nothing if you use -q. So it might be boring to use it like that ;-)"
# example from a pure agent perspective
settings = Settings()
#First, initialize the agent
client = Agent(settings)
# In this example, let's disable inventory handling
client.settings.ENABLE_INVENTORY_MANAGEMENT = False
# Now let's log it in
#client.login(options.loginuri, args[0], args[1], password, start_location = options.region, connect_region = True)
api.spawn(client.login, logindata["loginuri"], logindata["First Name"], logindata["Last Name"], logindata["Password"], start_location = options.region, connect_region = True)
while client.handler == None:
api.sleep(0) #need to do this to keep print output below happy
#client.login(loginuri, first, last, password, start_location = None, connect_region = True)
print ''
print ''
print 'At this point, we have an Agent object, Inventory dirs, and with a Region attribute'
print 'Agent attributes:'
for attr in client.__dict__:
print attr, ':\t\t\t', client.__dict__[attr]
print ''
print ''
print 'Region attributes:'
for attr in client.region.__dict__:
print attr, ':\t\t\t', client.region.__dict__[attr]
class TestApp(wx.App):
def OnInit(self):
self.savedstdio = sys.stdout
self.loginflag = False
self.loginmethodindex=0
self.place_avatarindex=0
self.frame = TestFrame(None, -1, "TestIt")
self.frame.Show(True)
sys.stdout = sys.stderr = self.frame.errtext
#logging setup could go here instead...
console = logging.StreamHandler(self.frame.timertext)
self.timerlogger = logging.getLogger("Timer")
self.timerlogger.setLevel(logging.DEBUG)
self.timerlogger.addHandler(console)
self.SetTopWindow(self.frame)
#registration.init() #ZCA stuff?
return True
def DoTimer(self,event):
if self.loginflag == False:
api.spawn(login)
self.loginflag = True
else:
api.sleep(0)
self.timerlogger.info( "time = " + str(datetime.datetime.now().microsecond))
def wxmain():
app = TestApp(None)
api.spawn(app.MainLoop)
while not_closed_window:
api.sleep(0)
return
def main():
return wxmain()
#def main():
#return login()
if __name__=="__main__":
main()