Add config and fullscreen/save password checkboxes

This commit is contained in:
2017-09-03 19:15:48 +03:00
parent 44de72e414
commit 0837319572
3 changed files with 91 additions and 16 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
pyGtkRDP version 0.99 pyGtkRDP version 1.0
Simple GUI application for freerdp or rdesktop connection Simple GUI application for freerdp or rdesktop connection
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 13 KiB

+90 -15
View File
@@ -1,38 +1,50 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# example table.py
import pygtk import pygtk
pygtk.require('2.0') pygtk.require('2.0')
import gtk import gtk
import subprocess import subprocess
import base64
import ConfigParser
from os import path
# ===== Connection settings: ====== # ===== Connection settings: ======
# ===== freerdp-x11: # ===== freerdp-x11:
string_l = "xfreerdp /drive:share,/media /f /bpp:15 /jpeg /cert-ignore /v:192.168.1.128" string_l = "xfreerdp /drive:share,/media /bpp:15 /jpeg /cert-ignore /v:192.168.1.128"
string_r = "xfreerdp /drive:share,/media /f /bpp:8 /jpeg /cert-ignore /v:external.domain:3389" string_r = "xfreerdp /drive:share,/media /bpp:8 /jpeg /cert-ignore /v:external.domain:3389"
# ===== rdesktop: # ===== rdesktop:
#string_l = "rdesktop -z -a 15 -k en-us -r disk:share=/media -f 192.168.1.128" #string_l = "rdesktop -z -a 15 -k en-us -r disk:share=/media 192.168.1.128"
#string_r = "rdesktop -z -a 8 -k en-us -r disk:share=/media -f external.domain:3389" #string_r = "rdesktop -z -a 8 -k en-us -r disk:share=/media external.domain:3389"
# ==============================
conf_file = path.expanduser("~") + '/.config/pygtkrdesktop.conf'
class Table: class Table:
def callback(self, widget, data=None): def Connect(self, widget, data=None):
name = login_entry.get_text() name = login_entry.get_text()
password = password_entry.get_text() password = password_entry.get_text()
SaveLogin(name, password)
if ( data == "local" ): if ( data == "local" ):
# ===== freerdp-x11:
string = string_l + " /u:" + name + " /p:" + password string = string_l + " /u:" + name + " /p:" + password
# ===== rdesktop: # ===== rdesktop:
# string = string_l + " -u " + name + " -p " + password # string = string_l + " -u " + name + " -p " + password
if ( data == "remote" ): if ( data == "remote" ):
# ===== freerdp-x11:
string = string_r + " /u:" + name + " /p:" + password string = string_r + " /u:" + name + " /p:" + password
# ===== rdesktop: # ===== rdesktop:
# string = string_r + " -u " + name + " -p " + password # string = string_r + " -u " + name + " -p " + password
if fullscreen_check.get_active():
string += " /f"
# ===== rdesktop:
# string += " -f"
else:
string += " /w:800 /h:600"
# ===== rdesktop:
# string += ""
p = subprocess.Popen(string, shell=True, stderr=subprocess.PIPE, ) p = subprocess.Popen(string, shell=True, stderr=subprocess.PIPE, )
streamdata = p.communicate()[0] streamdata = p.communicate()[0]
rc = p.returncode rc = p.returncode
@@ -48,6 +60,18 @@ class Table:
# Uncomment to check errorcode: # Uncomment to check errorcode:
# print "Error code", rc # print "Error code", rc
def LoginEnterPressed(self, widget, event):
if gtk.gdk.keyval_name(event.keyval) == 'Return':
password_entry.grab_focus()
return True
return False
def PasswordEnterPressed(self, widget, event):
if gtk.gdk.keyval_name(event.keyval) == 'Return':
self.Connect(widget, "local")
return True
return False
def delete_event(self, widget, event, data=None): def delete_event(self, widget, event, data=None):
gtk.main_quit() gtk.main_quit()
return False return False
@@ -57,7 +81,7 @@ class Table:
self.window.set_title("Connection...") self.window.set_title("Connection...")
self.window.connect("delete_event", self.delete_event) self.window.connect("delete_event", self.delete_event)
self.window.set_border_width(10) self.window.set_border_width(10)
table = gtk.Table(7, 2, True) table = gtk.Table(9, 2, True)
self.window.add(table) self.window.add(table)
login_entry_label = gtk.Label ("Username:") login_entry_label = gtk.Label ("Username:")
@@ -66,7 +90,10 @@ class Table:
login_entry.set_max_length(20) login_entry.set_max_length(20)
table.attach(login_entry, 0, 2, 1, 2) table.attach(login_entry, 0, 2, 1, 2)
if conf.has_option("login", "saved"):
login_entry.set_text(conf.get("login", "saved"))
login_entry.show() login_entry.show()
login_entry.connect('key-press-event', self.LoginEnterPressed)
password_entry_label = gtk.Label ("Password:") password_entry_label = gtk.Label ("Password:")
table.attach(password_entry_label, 0, 2, 2, 3) table.attach(password_entry_label, 0, 2, 2, 3)
@@ -76,28 +103,70 @@ class Table:
password_entry.set_visibility(False) password_entry.set_visibility(False)
table.attach(password_entry, 0, 2, 3, 4) table.attach(password_entry, 0, 2, 3, 4)
password_entry.show() password_entry.show()
if conf.has_option("login", "saved"):
password_entry.grab_focus()
if conf.has_option("login", "password"):
password_entry.set_text(base64.b32decode(base64.b16decode(base64.b64decode(conf.get("login", "password")))))
password_entry.connect('key-press-event', self.PasswordEnterPressed)
table.attach(status_entry_label, 0, 2, 4, 5) table.attach(status_entry_label, 0, 2, 4, 5)
status_entry_label.show() status_entry_label.show()
fullscreen_check.set_tooltip_text("If checked remote connection will be fullscreen, if no windowed. Press CTRL+ALT+ENTER to toggle fullscreen.")
if conf.has_option("login", "fullscreen"):
if conf.get("login", "fullscreen") == 'True':
fullscreen_check.set_active(True)
else:
fullscreen_check.set_active(False)
else:
fullscreen_check.set_active(True)
table.attach(fullscreen_check, 0, 2, 5, 6)
fullscreen_check.show()
password_check.set_tooltip_text("If checked passwrod will be saved in file. It's unsafe feature, please, be careful.")
if conf.has_option("login", "savepassword"):
if conf.get("login", "savepassword") == 'True':
password_check.set_active(True)
else:
password_check.set_active(False)
else:
password_check.set_active(False)
table.attach(password_check, 0, 2, 6, 7)
password_check.show()
local_button = gtk.Button("Local connection") local_button = gtk.Button("Local connection")
local_button.connect("clicked", self.callback, "local") local_button.set_tooltip_text("Connection via LAN (using internal IP.")
table.attach(local_button, 0, 1, 5, 6) local_button.connect("clicked", self.Connect, "local")
table.attach(local_button, 0, 1, 7, 8)
local_button.show() local_button.show()
remote_button = gtk.Button("External connection") remote_button = gtk.Button("External connection")
remote_button.connect("clicked", self.callback, "remote") remote_button.set_tooltip_text("Connection via WAN (using external IP).")
table.attach(remote_button, 1, 2, 5, 6) remote_button.connect("clicked", self.Connect, "remote")
table.attach(remote_button, 1, 2, 7, 8)
remote_button.show() remote_button.show()
button = gtk.Button("Exit") button = gtk.Button("Exit")
button.connect("clicked", lambda w: gtk.main_quit()) button.connect("clicked", lambda w: gtk.main_quit())
table.attach(button, 0, 2, 6, 7) table.attach(button, 0, 2, 8, 9)
button.show() button.show()
table.show() table.show()
self.window.show() self.window.show()
def SaveLogin(login, password):
if not conf.has_section("login"):
conf.add_section("login")
conf.set("login", "saved", login)
conf.set("login", "fullscreen", fullscreen_check.get_active())
conf.set("login", "savepassword", password_check.get_active())
if password_check.get_active():
conf.set("login", "password",
base64.b64encode(base64.b16encode(base64.b32encode(password))))
else:
conf.remove_option("login", "password")
conf.write(open(conf_file, "w"))
def main(): def main():
gtk.main() gtk.main()
return 0 return 0
@@ -105,7 +174,13 @@ def main():
login_entry = gtk.Entry() login_entry = gtk.Entry()
password_entry = gtk.Entry() password_entry = gtk.Entry()
status_entry_label = gtk.Label ("CTRL+ALT+ENTER - toggle fullscreen") status_entry_label = gtk.Label ("CTRL+ALT+ENTER - toggle fullscreen")
fullscreen_check = gtk.CheckButton ("Fullscreen mode")
password_check = gtk.CheckButton ("Save password (unsafe)")
if __name__ == "__main__": if __name__ == "__main__":
conf = ConfigParser.RawConfigParser()
if not path.exists(conf_file):
open(conf_file, 'w')
conf.read(conf_file)
Table() Table()
main() main()