Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
30
rated 0 times [  30] [ 0]  / answers: 1 / hits: 678  / 1 Year ago, sun, february 26, 2023, 6:37:29

I have two kids that love Ubuntu so much so that they are not doing their Math homework. So in the spirit of Monty Python, I would like to present them with something like:



"Stop. Who would cross the Bridge of Death must answer me these questions three, ere the other side he see."



at the login in.



They would have to solve a few math problems before they can login.



My question is: can this type of thing be done?


More From » gnome

 Answers
3

The following is tested with Ubuntu 13.04 and system's Python, using Gtk bindings (PyGobject).



Here is one way a bit dirty though and it needs more investigation:



Summary




  • Add a .desktop file at /usr/share/xsessions we will name it custom


  • Add an .xsession file at the user in question (your kids) we will name their user as kid


  • Create the Python GUI application for the math puzzle and run it from .xsession, we will name it as puzzle.py




Details




  • sudo vi /usr/share/xsessions/custom.desktop



Add the following in the file:



[Desktop Entry]
Name=Custom
Comment=This session logs you into your managed desktop environment
Exec=/etc/X11/Xsession
X-Ubuntu-Gettext-Domain=gnome-session-3.0



  • vi /home/kid/.xsession



Add the following in the file:



#!/bin/bash
lightdm &
exec /home/kid/puzzle.py



  • vi /home/kid/puzzle.py



Add the following in the file:



#!/usr/bin/python
# -*- coding: utf-8 -*-
import subprocess
import random
from gi.repository import Gtk


#----------------------------------------------------------------------
class PuzzleWindow(Gtk.Window):

def __init__(self):
Gtk.Window.__init__(self, title="Math Puzzle", resizable=False)

super(PuzzleWindow, self).set_position(Gtk.WindowPosition.CENTER)
super(PuzzleWindow, self).maximize()

self.a_number = random.randint(1, 5)
self.b_number = random.randint(1, 5)
self.result = self.a_number + self.b_number

self.vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)

self.label = Gtk.Label("What is the sum of the numbers bellow?")
self.number_label = Gtk.Label("{num_a} + {num_b}".format(
num_a=self.a_number, num_b=self.b_number))

self.entry = Gtk.Entry()
self.button = Gtk.Button(label="Check answer!")
self.button.connect("clicked", self.on_button_clicked)

self.vbox.pack_start(self.label, True, True, 0)
self.vbox.pack_start(self.number_label, True, True, 0)
self.vbox.pack_start(self.entry, True, True, 0)
self.vbox.pack_start(self.button, True, True, 0)
self.add(self.vbox)

def on_button_clicked(self, widget):

if int(self.entry.get_text()) == self.result:
subprocess.call("unity &", shell=True)
else:
self.label.set_text("Wrong answer, try again.")
#----------------------------------------------------------------------
def main():
"""Application's entry point"""
win = PuzzleWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()

if __name__ == "__main__":
main()


Results:




  • If you logout, at the login screen you will see a new session named Custom.

  • By choosing the custom session and after successful login you will presented by a small PyGtk (using pygobject) window asking for a math puzzle. There will be no top bar, launcher and the rest of the default desktop widgets:



Custom access to Unity




  • If you answer correctly, Unity will load...



It needs further research though but i hope that it helps as a starting point.


[#29762] Monday, February 27, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
onomicsiberated

Total Points: 217
Total Questions: 98
Total Answers: 107

Location: Luxembourg
Member since Sun, May 28, 2023
1 Year ago
;