localzuk Posted November 26, 2014 Posted November 26, 2014 So, I have a script written in Python, which utilises WXPython to create a simple form (its a basic login form). The form, on submit, passes the username and password to a command line program as switches. The problem I've got is this - the form won't submit when a user has a £ symbol in it. If I comment out the os.system line and instead get it to simply put the contents of one text field into one of the labels, it works fine. If I manually type out the command line command, manually typing the username and password as options, that runs fine too. It just fails when I combine the 2! Anyone got any ideas how I can get this thing to work?
jinnantonnixx Posted November 26, 2014 Posted November 26, 2014 (edited) Add this to the start of your source code. # -*- coding: utf-8 -*- The problem is that the '£' sign isn't part of the 8-bit ASCII set that Python uses to encode strings. The above declaration tells it to use unicode. https://docs.python.org/2.7/howto/unicode.html Edited November 26, 2014 by jinnantonnixx
localzuk Posted November 26, 2014 Author Posted November 26, 2014 It does indeed look like a pain. :/ Question is - do I figure it all out in python (a language that, to be honest, I don't like), or do I look at a different language, such as c# using Mono and GTK#? The question then is, how big are the files needed to run Mono and GTK#?
jinnantonnixx Posted November 26, 2014 Posted November 26, 2014 I found a solution and edited my post with a simple fix, which I'm sure you'll like.
localzuk Posted November 26, 2014 Author Posted November 26, 2014 I already have that in place, no change.
localzuk Posted November 26, 2014 Author Posted November 26, 2014 This is the code I'm using: #!/usr/bin/python # -*- coding: utf-8 -*- 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 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 ) m_textCtrl1.SetFocus() 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 DOMAIN -f --plugin rdpsnd RDSFARMADDRESS:3389") sys.exit() app = wx.App(False) frame = BonsaiThinConnectForm(None) app.MainLoop() Only thing I have thought to do is try str() wrapping the m_textCtrl1.Value/m_textCtrl2.Value sections in the os.system line. My brain is struggling with this one.
jinnantonnixx Posted November 26, 2014 Posted November 26, 2014 (edited) See if decoding the unicode to byte string works. Try the mods in red ink. # 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 " + [color="#FF0000"]m_textCtrl1.Value.decode("utf-8")[/color] + " -p " + [color="#FF0000"]m_textCtrl2.Value.decode("utf-8")[/color] + " -d DOMAIN -f --plugin rdpsnd RDSFARMADDRESS:3389") sys.exit() If if crashes when you call your RDP, try decoding the variables further upstream. Edited November 26, 2014 by jinnantonnixx
localzuk Posted November 26, 2014 Author Posted November 26, 2014 Sadly, no change. Same thing - just doesn't do anything. :/
jinnantonnixx Posted November 26, 2014 Posted November 26, 2014 I realised it wouldn't work and deleted the post. Not sure what to suggest....
localzuk Posted November 26, 2014 Author Posted November 26, 2014 Its not exactly a huge script, so I'll rewrite using something else with better UTF-8 support.
localzuk Posted November 29, 2014 Author Posted November 29, 2014 Ended up rewriting it using c#/mono.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now