[gnome-games] sudoku:Add keybindings to add/remove numbers from notes
- From: Thomas Hindoe Paaboel Andersen <thomashpa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] sudoku:Add keybindings to add/remove numbers from notes
- Date: Sun, 18 Apr 2010 14:05:21 +0000 (UTC)
commit d08d18e6debd1615afdf8726e635c2cb059b4112
Author: Richard Griswold <richgriswold gmail com>
Date: Sun Apr 18 16:03:16 2010 +0200
sudoku:Add keybindings to add/remove numbers from notes
* Ctrl-1 to Ctrl-9: Add the number to the notes at the top of a square, and sort the notes.
* Alt-1 to Alt-9: Remove the number from the notes at the top of a square
* Alt-n, Alt-N: Clear notes at the top of a square
* Alt-m, Alt-M: Clear notes at the bottom of a square
GNOME bug #615769
gnome-sudoku/help/C/gnome-sudoku.xml | 2 +
gnome-sudoku/src/lib/number_box.py | 73 ++++++++++++++++++++++++++--------
2 files changed, 58 insertions(+), 17 deletions(-)
---
diff --git a/gnome-sudoku/help/C/gnome-sudoku.xml b/gnome-sudoku/help/C/gnome-sudoku.xml
index 47cc111..9b9ba15 100644
--- a/gnome-sudoku/help/C/gnome-sudoku.xml
+++ b/gnome-sudoku/help/C/gnome-sudoku.xml
@@ -390,6 +390,8 @@
<para>This will bring up a field in which you can type your notes. Type <keycap>Return</keycap> when you are finished editing your note.</para>
<note><para>You can also take notes in the bottom of the square by clicking in the bottom of the square or by typing <keycap>M</keycap>. However, this area is used when you ask for a <firstterm>hint</firstterm>, so you should not use this area for your own notes if you also plan to use hints.</para></note>
+ <note><para>You can clear the notes at the top of the square by typing <keycap>Alt-N</keycap> and at the bottom of the square by typing <keycap>Alt-M</keycap>.</para></note>
+ <note><para>You can add a number to the notes at the top of the square by typing <keycap>Ctrl-1</keycap> through <keycap>Ctrl-9</keycap> and remove a number from the notes by typing <keycap>Alt-1</keycap> through <keycap>Alt-9</keycap>.</para></note>
</sect2>
<!-- ================ Usage Subsection ================================ -->
<sect2 id="myapp-manipulate-view">
diff --git a/gnome-sudoku/src/lib/number_box.py b/gnome-sudoku/src/lib/number_box.py
index 5be8c2b..f6d86e1 100644
--- a/gnome-sudoku/src/lib/number_box.py
+++ b/gnome-sudoku/src/lib/number_box.py
@@ -194,26 +194,65 @@ class NumberBox (gtk.Widget):
# Make sure we don't trigger on unplugging the A/C charger etc
return
txt = txt.replace('KP_', '')
- if self.get_text() == txt:
- # If there's no change, do nothing
- return
- if txt in ['0', 'Delete', 'BackSpace']:
+
+ # Add the new value if need be
+ if txt in [str(n) for n in range(1, self.upper+1)]:
+ if e.state & gtk.gdk.CONTROL_MASK:
+ self.add_note_text(txt, top = True)
+ elif e.state & gtk.gdk.MOD1_MASK:
+ self.remove_note_text(txt, top = True)
+ elif self.get_text() != txt:
+ # If there's no change, do nothing
+
+ # First do a removal event -- this is something of a
+ # kludge, but it works nicely with old code that was based
+ # on entries, which also behave this way (they generate 2
+ # events for replacing a number with a new number - a
+ # removal event and an addition event)
+
+ if self.get_text():
+ self.set_text_interactive('')
+ # Then add
+ self.set_text_interactive(txt)
+ elif txt in ['0', 'Delete', 'BackSpace']:
self.set_text_interactive('')
elif txt in ['n', 'N']:
- self.show_note_editor(top = True)
+ if e.state & gtk.gdk.MOD1_MASK:
+ self.set_note_text_interactive(top_text = '')
+ else:
+ self.show_note_editor(top = True)
elif txt in ['m', 'M']:
- self.show_note_editor(top = False)
- # And then add the new value if need be
- elif txt in [str(n) for n in range(1, self.upper+1)]:
- # First do a removal event -- this is something of a
- # kludge, but it works nicely with old code that was based
- # on entries, which also behave this way (they generate 2
- # events for replacing a number with a new number - a
- # removal event and an addition event)
- if self.get_text():
- self.set_text_interactive('')
- # Then add
- self.set_text_interactive(txt)
+ if e.state & gtk.gdk.MOD1_MASK:
+ self.set_note_text_interactive(bottom_text = '')
+ else:
+ self.show_note_editor(top = False)
+
+ def add_note_text(self, txt, top = False):
+ if top:
+ note = self.top_note_text
+ else:
+ note = self.bottom_note_text
+ if txt not in note:
+ tmp = list(note)
+ tmp.append(txt)
+ tmp.sort()
+ note = ''.join(tmp)
+ if top:
+ self.set_note_text_interactive(top_text = note)
+ else:
+ self.set_note_text_interactive(bottom_text = note)
+
+ def remove_note_text(self, txt, top = False):
+ if top:
+ note = self.top_note_text
+ else:
+ note = self.bottom_note_text
+ if txt in note:
+ note = note.replace(txt,'')
+ if top:
+ self.set_note_text_interactive(top_text = note)
+ else:
+ self.set_note_text_interactive(bottom_text = note)
def note_changed_cb (self, w, top = False):
if top:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]