Generalizzato ancora di più decifra per importazione. Creazione di una Gui con GTK e Glade.

This commit is contained in:
Emiliano Vavassori 2018-02-23 00:48:36 +01:00
parent 4015b7bfc2
commit 6a3a9e4c2f
3 changed files with 223 additions and 2 deletions

View File

@ -36,5 +36,6 @@ def decifra(testo, rotazione = 5):
return risultato
# Usare in questa maniera:
if __name__ == '__main__':
testo = 'HNFT F YZYYN!'
print decifra(testo, 5)

180
gui.glade Normal file
View File

@ -0,0 +1,180 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkApplicationWindow" id="window1">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Decifra ROTx</property>
<property name="icon_name">security-medium</property>
<property name="show_menubar">False</property>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xpad">20</property>
<property name="ypad">10</property>
<property name="label" translatable="yes">Decifra il testo inserito con la rotazione indicata</property>
<property name="ellipsize">end</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="grid1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xpad">20</property>
<property name="ypad">10</property>
<property name="label" translatable="yes">Testo cifrato</property>
<property name="justify">center</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xpad">20</property>
<property name="ypad">10</property>
<property name="label" translatable="yes">Rotazione</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xpad">20</property>
<property name="ypad">10</property>
<property name="label" translatable="yes">Testo decifrato</property>
<property name="justify">fill</property>
<property name="ellipsize">end</property>
<property name="width_chars">15</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="fldTestoCifrato_in">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="width_chars">0</property>
<property name="caps_lock_warning">False</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="lblRisultato">
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Risultato decifrato</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="fldRotazione_in">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">center</property>
<property name="hexpand">True</property>
<property name="max_length">2</property>
<property name="width_chars">2</property>
<property name="max_width_chars">2</property>
<property name="xalign">0.5</property>
<property name="progress_pulse_step">0</property>
<property name="input_purpose">number</property>
<property name="climb_rate">1</property>
<property name="numeric">True</property>
<property name="value">5</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButtonBox" id="buttonbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">10</property>
<property name="layout_style">center</property>
<child>
<object class="GtkButton" id="btnQuit">
<property name="label">gtk-quit</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="margin_bottom">1</property>
<property name="relief">none</property>
<property name="use_stock">True</property>
<property name="image_position">right</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="btnQuit_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnDecifra">
<property name="label">gtk-convert</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="image_position">right</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="btnDecifra_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

40
gui.py Normal file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env python
import sys, decifra
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class DecifraGui:
def on_window1_destroy(self, object, data=None):
Gtk.main_quit()
def btnQuit_clicked(self, object, data=None):
Gtk.main_quit()
def btnDecifra_clicked(self, object, data=None):
self.risultato.hide()
testo = self.testocifrato.get_text()
rotazione = self.rotazione.get_value_as_int()
self.risultato.set_text(decifra.decifra(testo, rotazione))
self.risultato.show()
def __init__(self):
self.gladefile = "gui.glade"
self.builder = Gtk.Builder()
self.builder.add_from_file(self.gladefile)
self.builder.connect_signals(self)
self.window = self.builder.get_object("window1")
self.window.set_wmclass("Decifra ROTx", "Decifra ROTx")
self.testocifrato = self.builder.get_object("fldTestoCifrato_in")
self.rotazione = self.builder.get_object("fldRotazione_in")
adj = Gtk.Adjustment(1, 1, 99, 1, 1, 1)
self.rotazione.configure(adj, 1, 0)
self.risultato = self.builder.get_object("lblRisultato")
self.risultato.hide()
self.window.show()
if __name__ == '__main__':
main = DecifraGui()
Gtk.main()