Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

WxPython code - someone look over it and tell me how to improve?


Recommended Posts

Posted

I've crafted a little python script which wraps around FreeRDP, to enable us to use NLA and load balancing on a RDP farm. Basically, it simply takes the username and password and passes them as options. It is used as a custom xsession and GDM simply loads that as the session, with a user logging in automatically and timed.

 

It isn't completely finished (need to sort out the sound plugin for freerdp) but I would love some input from any other python wizards on ways I can improve it.

 

import wx
import wx.xrc
import sys
import os


class BonsaiThinConnectForm ( wx.Frame ):
m_textCtrl1 = None
m_textCtrl2 = None
def __init__( self, parent ):
	wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"Login to MMS RDP", pos = wx.DefaultPosition, 
					 size = wx.Size( 180,170 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
	
	self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
	panel = wx.Panel(self)
	bSizer1 = wx.BoxSizer( wx.VERTICAL )
	
	self.m_staticText1 = wx.StaticText( panel, wx.ID_ANY, u"Username", wx.DefaultPosition, wx.DefaultSize, 0 )
	self.m_staticText1.Wrap( -1 )
	bSizer1.Add( self.m_staticText1, 0, wx.ALL, 5 )
	global m_textCtrl1
	m_textCtrl1 = wx.TextCtrl( panel, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size(150,-1), 0 )
	bSizer1.Add( m_textCtrl1, 0, wx.ALL, 5 )
	
	self.m_staticText2 = wx.StaticText( panel, wx.ID_ANY, u"Password", wx.DefaultPosition, wx.Size(150,-1), 0 )
	self.m_staticText2.Wrap( -1 )
	bSizer1.Add( self.m_staticText2, 0, wx.ALL, 5 )
	global m_textCtrl2
	m_textCtrl2 = wx.TextCtrl( panel, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size(150,-1), wx.TE_PASSWORD )
	bSizer1.Add( m_textCtrl2, 0, wx.ALL, 5 )
	
	self.m_button1 = wx.Button( panel, wx.ID_ANY, u"Login", wx.DefaultPosition, wx.DefaultSize, 0 )
	self.m_button1.SetDefault()
	bSizer1.Add( self.m_button1, 0, wx.ALL, 5 )
	
	panel.SetSizer( bSizer1 )
	self.Layout()
	
	self.Centre( wx.BOTH )
	
	# Connect Events
	self.m_button1.Bind( wx.EVT_BUTTON, self.OnLogin )
	self.Show()
def __del__( self ):
	pass

# Virtual event handlers, overide them in your derived class
def OnLogin( self, event ):
	if m_textCtrl1.Value:
		if m_textCtrl2.Value:
			os.system("xfreerdp -u " + m_textCtrl1.Value + " -p " + m_textCtrl2.Value + " -d SCH4290 -f RDSFarm:3389")
			sys.exit()
		
app = wx.App(False)
frame = BonsaiThinConnectForm(None)
app.MainLoop()

 

So, any tips or pointers? This is my first graphical python script.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...