Skip to content

Commit

Permalink
Changed paper_tape to use a listbox
Browse files Browse the repository at this point in the history
  • Loading branch information
mighele committed Aug 11, 2014
1 parent 0368640 commit 1c89af4
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions plover/gui/paper_tape.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ALL_KEYS = ''.join(x[0].strip('-') for x in
sorted(STENO_KEY_ORDER.items(), key=lambda x: x[1]))
REVERSE_NUMBERS = {v: k for k, v in STENO_KEY_NUMBERS.items()}
STROKE_LINES = 30
MAX_STROKE_LINES = 38
STYLE_TEXT = 'Style:'
STYLE_PAPER = 'Paper'
STYLE_RAW = 'Raw'
Expand All @@ -23,7 +23,7 @@
class StrokeDisplayDialog(wx.Dialog):

other_instances = []
strokes = deque(maxlen=STROKE_LINES)
strokes = deque(maxlen=MAX_STROKE_LINES)

def __init__(self, parent, config):
self.config = config
Expand All @@ -33,11 +33,11 @@ def __init__(self, parent, config):
style |= wx.STAY_ON_TOP
pos = (config.get_stroke_display_x(), config.get_stroke_display_y())
wx.Dialog.__init__(self, parent, title=TITLE, style=style, pos=pos)

self.SetBackgroundColour(wx.WHITE)

sizer = wx.BoxSizer(wx.VERTICAL)

self.on_top = wx.CheckBox(self, label=ON_TOP_TEXT)
self.on_top.SetValue(config.get_stroke_display_on_top())
self.on_top.Bind(wx.EVT_CHECKBOX, self.handle_on_top)
Expand All @@ -62,16 +62,14 @@ def __init__(self, parent, config):
border=UI_BORDER)
sizer.Add(wx.StaticLine(self), flag=wx.EXPAND)

self.labels = []
for i in range(STROKE_LINES):
label = MyStaticText(self, label=' ')
self.labels.append(label)
font = label.GetFont()
font.SetFaceName("Courier")
font.SetWeight(wx.FONTWEIGHT_NORMAL)
label.SetFont(font)
sizer.Add(label, border=UI_BORDER,
flag=wx.LEFT | wx.RIGHT | wx.BOTTOM)
self.listbox = wx.ListBox(self, size=wx.Size(210, 500))
font = self.listbox.GetFont()
font.SetFaceName("Courier")
self.listbox.SetFont(font)

sizer.Add(self.listbox,
flag=wx.ALL | wx.FIXED_MINSIZE,
border=3)

self.SetSizer(sizer)
self.SetAutoLayout(True)
Expand Down Expand Up @@ -99,9 +97,8 @@ def on_close(self, event):
event.Skip()

def show_text(self, text):
for i in range(len(self.labels) - 1):
self.labels[i].SetLabel(self.labels[i + 1].GetLabel())
self.labels[-1].SetLabel(text)
self.listbox.Append(text)
self.listbox.SetSelection(self.listbox.Count-1)

def show_stroke(self, stroke):
self.show_text(self.formatter(stroke))
Expand All @@ -113,6 +110,7 @@ def handle_on_top(self, event):
def on_style(self, event=None):
format = self.choice.GetStringSelection()
self.formatter = getattr(self, format.lower() + '_format')
self.listbox.Clear()
for stroke in self.strokes:
self.show_stroke(stroke)
self.header.SetLabel(ALL_KEYS if format == STYLE_PAPER else ' ')
Expand Down Expand Up @@ -152,8 +150,6 @@ def display(parent, config):
StrokeDisplayDialog(parent, config)


# This class exists solely so that the text doesn't get grayed out when the
# window is not in focus.
# This class exists solely so that the text doesn't get grayed out when the
# window is not in focus.
class MyStaticText(wx.PyControl):
Expand Down

0 comments on commit 1c89af4

Please sign in to comment.