<commit_before>#!/usr/bin/env python
from gi.repository import Gtk

class MyWindow(Gtk.Window):
  def __init__(self):
    Gtk.Window.__init__(self, title="Hello World")
    
    self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
    self.add(self.box)

    # Add label describing what to do

    # add ID passphrase box (with options show passphrase, generate new ID)

    # add ListBox which contains children rows one per plugin with checkbox to enable/disable

    # add button to create ID for all checked plugins

    self.button1 = Gtk.Button(label="Hello")
    self.button1.connect("clicked", self.on_button1_clicked)
    self.box.pack_start(self.button1, True, True, 0)

    self.button2 = Gtk.Button(label="Goodbye")
    self.button2.connect("clicked", self.on_button2_clicked)
    self.box.pack_start(self.button2, True, True, 0)

  def on_button1_clicked(self, widget):
    print("Hello")

  def on_button2_clicked(self, widget):
    print("Goodbye")

win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()<commit_msg>Electrum passphrase entry<commit_after>#!/usr/bin/env python
from gi.repository import Gtk
import electrum

class PassphraseWidget(Gtk.Grid):
  def __init__(self):
    Gtk.Grid.__init__(self)

    # passphrase field
    self.passphrase = Gtk.Entry(visibility=True, expand=True)
    self.passphrase.connect('cut-clipboard', self.validate)
    self.passphrase.connect('delete-from-cursor', self.validate)
    self.passphrase.connect('insert-at-cursor', self.validate)
    self.passphrase.connect('paste-clipboard', self.validate)
    self.passphrase.get_buffer().connect('deleted-text', self.validate)
    self.passphrase.get_buffer().connect('inserted-text', self.validate)
    self.attach(self.passphrase, 0, 0, 1, 1)

    # show/hide passphrase
    hbox = Gtk.Box()
    self.showhide_l = Gtk.Label('Show passphrase:')
    self.showhide_w = Gtk.Switch(active=True)
    self.showhide_w.connect('notify::active', self.showhide)
    hbox.add(self.showhide_l)
    hbox.add(self.showhide_w)
    self.attach(hbox, 0, 1, 1, 1)

    # new ID button
    #self.newID_w = Gtk.Button('New ID')
    #self.newID_w.connect('clicked', self.newID)
    #self.attach(self.newID_w, 1, 0, 1, 2)

  def newID(self, *args):
    print button

  def showhide(self, *args):
    if(self.showhide_w.get_active()):
      self.passphrase.set_visibility(True)
    else:
      self.passphrase.set_visibility(False)

  def validate(self, *args):
    text = self.passphrase.get_text()
    words = text.split()
    if text.endswith(' '):
      words.append(' ') # so we treat a space as the start of a new word
    frac = min(1, len(words) / 12.0)

    self.passphrase.set_progress_fraction(frac)

    if(len(words) > 12):  # only 12 in electrum seed -- automatic bad
      self.passphrase.set_icon_from_icon_name(Gtk.EntryIconPosition.SECONDARY, 'gtk-no')

    # validate that words are ok ... complex because they aren't ok while being typed
    bad = False
    for word in words[:-1]:
      if word not in electrum.mnemonic.words:
        self.passphrase.set_icon_from_icon_name(Gtk.EntryIconPosition.SECONDARY, 'gtk-no')
        bad = True
        break
    if not bad and len(words) == 12 and words[-1] in electrum.mnemonic.words: # all good
      self.passphrase.set_icon_from_icon_name(Gtk.EntryIconPosition.SECONDARY, 'gtk-yes')
    elif not bad:
      self.passphrase.set_icon_from_icon_name(Gtk.EntryIconPosition.SECONDARY, None)
    #print ('> "%s"' % text), len(text.split()), frac, args

class MyWindow(Gtk.Window):
  def __init__(self):
    Gtk.Window.__init__(self, title="Deterministic ID")
    
    vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
    self.add(vbox)

    # Add label describing what to do
    vbox.pack_start(Gtk.Label("Enter electrum seed:"),
        False, False, 0)

    # add ID passphrase entry (with options show passphrase, generate new ID)
    vbox.pack_start(PassphraseWidget(), False, False, 0)

    # add ListBox which contains children rows one per plugin with switch to enable/disable

    # add button to create ID for all checked plugins

    self.button = Gtk.Button(label="Generate!")
    #self.button.connect("clicked", self.generate?)
    vbox.pack_start(self.button, True, True, 0)

  def generate(self, widget):
    print("Stuff ...")

win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
{'fraction_non_alphanumeric': 0.1267764493570945, 'fraction_numerical': 0.009248815700428605, 'mean_word_length': 3.742245989304813, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4849996', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1477, 'n_words': 335}