Jump to content

Recommended Posts

Posted

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?

Posted

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#?

Posted

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.

Posted (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 by jinnantonnixx

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...