Skip to content

Instantly share code, notes, and snippets.

@antonsoroko
Last active May 28, 2020 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonsoroko/e1cb53c125425ab62992b2b7f1ac0efd to your computer and use it in GitHub Desktop.
Save antonsoroko/e1cb53c125425ab62992b2b7f1ac0efd to your computer and use it in GitHub Desktop.
Modifiled greeter.py for new PyGObject. https://habr.com/ru/post/420099/
#!/usr/local/opt/python@3.8/bin/python3
# -*- coding: UTF-8 -*-
from datetime import datetime
#from gobject import timeout_add
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib
from gi.repository import Gdk
import os,sys,subprocess #pango,gtk
class GreeterApp:
def __init__( self ):
self.builder = Gtk.Builder()
#self.builder.add_from_file("ui.glade")
self.builder.add_from_string(ui)
self.window = self.builder.get_object ("window")
#watch = Gdk.Cursor(Gdk.CursorType.HAND1)
#gdk_window = self.window.get_root_window()
#gdk_window.set_cursor(watch)
self.pass_field = self.builder.get_object ("pass_field")
self.passct = self.builder.get_object ("pass")
self.contrl = self.builder.get_object ("control")
#self.pass_field.modify_font(pango.FontDescription('Sans Bold 36'))
#self.passwd = datetime.now().strftime("%m%d")
self.passwd = "0000"
#self.rdp_server = open("/tmp/rdp_server").read().split(',')[0]
#self.rdp_user = open("/tmp/rdp_user").read()
#self.rdp_passwd = open("/tmp/rdp_passwd").read()
self.process = None
#timeout_add(5000, self.timeout)
self.screenvar = Gdk.Screen.get_default()
self.timeout_id = GLib.timeout_add(5000, self.timeout, None)
if self.window:
self.window.connect("destroy", Gtk.main_quit)
self.contrl.set_visible(False)
self.window.set_size_request(self.screenvar.get_width(),self.screenvar.get_height())
self.builder.connect_signals(self)
def hide(self, widget):
self.contrl.set_visible(False)
self.passct.set_visible(True)
self.window.move(0,0)
self.window.set_size_request(self.screenvar.get_width(),self.screenvar.get_height())
if self.process:
self.process.terminate()
self.process = None
def timeout(self, _):
if self.window:
self.window.set_keep_above(True)
self.window.set_modal(True)
#watch = Gdk.Cursor(Gdk.CursorType.HAND1)
#gdk_window = self.window.get_root_window()
#gdk_window.set_cursor(watch)
return True
return False
def check_pass(self, widget, *args):
if self.pass_field.get_text() == self.passwd:
self.pass_field.set_text("")
self.passct.set_visible(False)
self.contrl.set_visible(True)
self.window.set_size_request(50,50)
self.window.move(0,self.screenvar.get_height()-50)
#sys.exit()
#self.process = subprocess.Popen(["xfreerdp","/v:"+self.rdp_server,"/f","/cert-ignore","/u:"+self.rdp_user,"/p:"+self.rdp_passwd])
#window = Gtk.Window(title="Hello World")
#watch = Gdk.Cursor(Gdk.CursorType.HAND1)
#gdk_window = window.get_root_window()
#gdk_window.set_cursor(watch)
#window.connect("destroy", Gtk.main_quit)
#window.show()
Gtk.main_quit()
def clear_pass(self, widget):
self.pass_field.set_text("")
def num_press(self, widget):
self.pass_field.set_text(self.pass_field.get_text()+widget.get_tooltip_text())
self.check_pass(self, widget)
def on_destroy(self, widget):
Gtk.main_quit()
sys.exit()
if __name__ == "__main__":
settings = Gtk.Settings.get_default()
#settings.props.gtk_button_images = True
settings.props.gtk_enable_tooltips = False
ui = """
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.24"/>
<object class="GtkWindow" id="window">
<property name="can_focus">False</property>
<property name="type">window</property>
<property name="title" translatable="yes">MyGreeter</property>
<property name="resizable">False</property>
<signal name="destroy" handler="on_destroy" swapped="no"/>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkHBox" id="control">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton" id="power1">
<property name="use_action_appearance">False</property>
<property name="width_request">50</property>
<property name="height_request">42</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="hide" swapped="no"/>
<property name="tooltip_text" translatable="yes">"HELLO"</property>
<child>
<object class="GtkImage" id="image4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-no</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkTable" id="pass">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="n_rows">6</property>
<property name="n_columns">3</property>
<child>
<object class="GtkEntry" id="pass_field">
<property name="width_request">240</property>
<property name="height_request">60</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="visibility">False</property>
<property name="invisible_char">●</property>
<property name="xalign">1</property>
<property name="invisible_char_set">True</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
<signal name="preedit-changed" handler="check_pass" swapped="no"/>
<signal name="activate" handler="check_pass" swapped="no"/>
</object>
<packing>
<property name="right_attach">3</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_SHRINK</property>
<property name="y_options">GTK_SHRINK</property>
</packing>
</child>
<child>
<object class="GtkButton" id="b_0">
<property name="use_action_appearance">False</property>
<property name="width_request">80</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">0</property>
<signal name="clicked" handler="num_press" swapped="no"/>
<child>
<object class="GtkLabel" id="l_0">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">0</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="size" value="40000"/>
</attributes>
</object>
</child>
</object>
<packing>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
<property name="x_options">GTK_SHRINK</property>
<property name="y_options">GTK_SHRINK</property>
</packing>
</child>
<child>
<object class="GtkButton" id="b_1">
<property name="use_action_appearance">False</property>
<property name="width_request">80</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">1</property>
<signal name="clicked" handler="num_press" swapped="no"/>
<child>
<object class="GtkLabel" id="l_1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">1</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="size" value="40000"/>
</attributes>
</object>
</child>
</object>
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">GTK_SHRINK</property>
<property name="y_options">GTK_SHRINK</property>
</packing>
</child>
<child>
<object class="GtkButton" id="b_2">
<property name="use_action_appearance">False</property>
<property name="width_request">80</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">2</property>
<signal name="clicked" handler="num_press" swapped="no"/>
<child>
<object class="GtkLabel" id="l_2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">2</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="size" value="40000"/>
</attributes>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">GTK_SHRINK</property>
<property name="y_options">GTK_SHRINK</property>
</packing>
</child>
<child>
<object class="GtkButton" id="b_3">
<property name="use_action_appearance">False</property>
<property name="width_request">80</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">3</property>
<signal name="clicked" handler="num_press" swapped="no"/>
<child>
<object class="GtkLabel" id="l_3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">3</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="size" value="40000"/>
</attributes>
</object>
</child>
</object>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">GTK_SHRINK</property>
<property name="y_options">GTK_SHRINK</property>
</packing>
</child>
<child>
<object class="GtkButton" id="b_4">
<property name="use_action_appearance">False</property>
<property name="width_request">80</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">4</property>
<signal name="clicked" handler="num_press" swapped="no"/>
<child>
<object class="GtkLabel" id="l_4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">4</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="size" value="40000"/>
</attributes>
</object>
</child>
</object>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_SHRINK</property>
<property name="y_options">GTK_SHRINK</property>
</packing>
</child>
<child>
<object class="GtkButton" id="b_5">
<property name="use_action_appearance">False</property>
<property name="width_request">80</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">5</property>
<signal name="clicked" handler="num_press" swapped="no"/>
<child>
<object class="GtkLabel" id="l_5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">5</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="size" value="40000"/>
</attributes>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_SHRINK</property>
<property name="y_options">GTK_SHRINK</property>
</packing>
</child>
<child>
<object class="GtkButton" id="b_6">
<property name="use_action_appearance">False</property>
<property name="width_request">80</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">6</property>
<signal name="clicked" handler="num_press" swapped="no"/>
<child>
<object class="GtkLabel" id="l_6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">6</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="size" value="40000"/>
</attributes>
</object>
</child>
</object>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_SHRINK</property>
<property name="y_options">GTK_SHRINK</property>
</packing>
</child>
<child>
<object class="GtkButton" id="b_7">
<property name="use_action_appearance">False</property>
<property name="width_request">80</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">7</property>
<signal name="clicked" handler="num_press" swapped="no"/>
<child>
<object class="GtkLabel" id="l_7">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">7</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="size" value="40000"/>
</attributes>
</object>
</child>
</object>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_SHRINK</property>
<property name="y_options">GTK_SHRINK</property>
</packing>
</child>
<child>
<object class="GtkButton" id="b_8">
<property name="use_action_appearance">False</property>
<property name="width_request">80</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">8</property>
<signal name="clicked" handler="num_press" swapped="no"/>
<child>
<object class="GtkLabel" id="l_8">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">8</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="size" value="40000"/>
</attributes>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_SHRINK</property>
<property name="y_options">GTK_SHRINK</property>
</packing>
</child>
<child>
<object class="GtkButton" id="b_9">
<property name="use_action_appearance">False</property>
<property name="width_request">80</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">9</property>
<signal name="clicked" handler="num_press" swapped="no"/>
<child>
<object class="GtkLabel" id="l_9">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">9</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="size" value="40000"/>
</attributes>
</object>
</child>
</object>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_SHRINK</property>
<property name="y_options">GTK_SHRINK</property>
</packing>
</child>
<child>
<object class="GtkButton" id="b_ent">
<property name="use_action_appearance">False</property>
<property name="width_request">80</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="check_pass" swapped="no"/>
<child>
<object class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-yes</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
<property name="x_options">GTK_SHRINK</property>
<property name="y_options">GTK_SHRINK</property>
</packing>
</child>
<child>
<object class="GtkButton" id="b_del">
<property name="use_action_appearance">False</property>
<property name="width_request">80</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="clear_pass" swapped="no"/>
<child>
<object class="GtkImage" id="image3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-no</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
<property name="x_options">GTK_SHRINK</property>
<property name="y_options">GTK_SHRINK</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
"""
app = GreeterApp()
app.window.show()
#app.window.connect("destroy", Gtk.main_quit)
Gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment