Advertisement
mwchase

LC:Nobilis Update 1

Apr 23rd, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 11.11 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import collections
  3.  
  4. import wx
  5.  
  6. app = wx.App()
  7.  
  8.  
  9. KeyType = collections.namedtuple('KeyType', 'strength weakness')
  10.  
  11. POWER_KEY = KeyType('heart', 'shadow')
  12. DECEIVER_KEY = KeyType('lie', 'truth')
  13.  
  14. KeyTemplate = collections.namedtuple(
  15.     'KeyTemplate',
  16.     'type flower key_name name_of strength weakness strength_hint '
  17.     'weakness_bullets')
  18.  
  19.  
  20. POWER_TEMPLATES = ()
  21. POWER_TEMPLATES += KeyTemplate(
  22.     POWER_KEY, 'Lotus Flower', 'Key of the Descending Angel', None, 'My Power',
  23.     'My Nature', "how you enact meaningful change in people's lives",
  24.     ('glorious', 'set apart')),
  25. POWER_TEMPLATES += KeyTemplate(
  26.     POWER_KEY, 'Vervain', 'Key of Something Powerful', None, 'My Identity',
  27.     'Burdens', 'who you are when you wield power',
  28.     ('bound by duty', 'set apart')),
  29. POWER_TEMPLATES += KeyTemplate(
  30.     POWER_KEY, 'Acacia', 'Key of Something that Must Be Hidden', None,
  31.     'A Dangerous Secret', '...That Hurts To Keep',
  32.     'what you do when dealing with the secret',
  33.     ('painful silence', 'set apart')),
  34. POWER_TEMPLATES += KeyTemplate(
  35.     POWER_KEY, 'Clematis', 'Key of Something, Given Gifts', None,
  36.     'I Have Witnessed It', 'Why I Doubt',
  37.     'who you are when you are witness to grace', ()),
  38. POWER_TEMPLATES += KeyTemplate(
  39.     POWER_KEY, 'Aconite', 'Key of Rage', None,
  40.     # Not sure how best to represent this.
  41.     "(.*'s )?(Rage|Hatred|Fury)",
  42.     'What Lets Me Oppose It', 'who you are in this drama', ()),
  43. POWER_TEMPLATES += KeyTemplate(
  44.     POWER_KEY, 'Wild Oats', 'Key of Destiny Denied', None, 'Hunger',
  45.     'Why It Feels Empty', 'who you are when indulging in your vice', ()),
  46. POWER_TEMPLATES += KeyTemplate(
  47.     POWER_KEY, 'Star of Bethlehem', 'Key of Something, Changed Forever', None,
  48.     'What it Made Me', 'How It Changed the World',
  49.     "who you are when you're thinking about the mystery",
  50.     ("I can't let go", "I'm committed")),
  51. POWER_TEMPLATES += KeyTemplate(
  52.     POWER_KEY, 'Gorse', 'Key of Something in Thrall', None, 'Held in Thrall',
  53.     'Entangled with my Enemy', 'how you are held in thrall, and by what',
  54.     ("I can't let go", "I'm weak")),
  55. POWER_TEMPLATES += KeyTemplate(
  56.     POWER_KEY, 'Honeysuckle', 'Key of Something, Finally, at Rest', None,
  57.     'My New Life', 'My Old Life', 'who you are and who you were', ()),
  58. POWER_TEMPLATES += KeyTemplate(
  59.     POWER_KEY, 'Chamomile', 'Key of Something Romantic', None, 'The Dream',
  60.     'The Cost', 'who you are', ()),
  61. POWER_TEMPLATES += KeyTemplate(
  62.     POWER_KEY, 'Wild Rose', 'Key of Something Different', None, 'My Nature',
  63.     'My Struggles', 'who you are compared to others',
  64.     ('self-doubt', 'trying to fit in')),
  65. POWER_TEMPLATES += KeyTemplate(
  66.     POWER_KEY, 'Hollyhock', 'Key of Destiny in the Balance', None,
  67.     'My Destiny', 'My Struggles', 'what you are doing as you change',
  68.     ('self-doubt', 'changing hurts')),
  69. POWER_TEMPLATES += KeyTemplate(
  70.     POWER_KEY, 'Mimulus', 'Key of Something Restless', None, 'My Path',
  71.     'Why it Feels Empty', 'who you are when you wander',
  72.     ('self-doubt', "the things I've left behind")),
  73. POWER_TEMPLATES += KeyTemplate(
  74.     POWER_KEY, 'Water Lily', 'Key of Something Spiritual', None, 'My Retreat',
  75.     'Burdens', 'who you are when you separate yourself from the world',
  76.     ('my duties as a Power',)),
  77. POWER_TEMPLATES += KeyTemplate(
  78.     POWER_KEY, 'Oak', "Key of Something That Hasn't Changed", None,
  79.     'My Identity', 'Crisis', 'who you are', ()),
  80. POWER_TEMPLATES += KeyTemplate(
  81.     POWER_KEY, 'Alyssym', 'Key of Destiny Fulfilled', None, 'My Destiny',
  82.     None, 'who you are, in terms of who you were', ()),
  83.  
  84. DECEIVER_TEMPLATES = ()
  85. DECEIVER_TEMPLATES += KeyTemplate(
  86.     DECEIVER_KEY, 'Lotus Flower', 'Key of the Shepherd', 'I BRING MY FLOCK...',
  87.     None, None, 'what people get out of interacting with you',
  88.     ('I love them', 'I listen to them')),
  89. DECEIVER_TEMPLATES += KeyTemplate(
  90.     DECEIVER_KEY, 'Vervain', 'Key of the Dragon', 'THE EXCRUCIAN WAR', None,
  91.     None, 'cool stuff that you could do or have done',
  92.     ('I love them', 'I am their enemy')),
  93. DECEIVER_TEMPLATES += KeyTemplate(
  94.     DECEIVER_KEY, 'Acacia', 'Key of the Crossroads', 'WHY I FALTER', None,
  95.     None, 'your excuse for being kind to mortals and Powers',
  96.     ('I love them', "I've lost sight of what I'm fighting for")),
  97. DECEIVER_TEMPLATES += KeyTemplate(
  98.     DECEIVER_KEY, 'Clematis', 'Key of the Angel', "I'M REACHING OUT TO YOU",
  99.     None, None, "who you pretend to be when you're reaching out to the Powers",
  100.     ()),
  101. DECEIVER_TEMPLATES += KeyTemplate(
  102.     DECEIVER_KEY, 'Aconite', 'Key of the Nemesis', 'THE EXCRUCIAN WAR', None,
  103.     None, "who you are when ruining a Power's life", ()),
  104. DECEIVER_TEMPLATES += KeyTemplate(
  105.     DECEIVER_KEY, 'Wild Oats', 'Key of the Dreamer',
  106.     'WHO I AM, IN THIS YOUR DREAM', None, None,
  107.     'the role you take on in this dream', ()),
  108. DECEIVER_TEMPLATES += KeyTemplate(
  109.     DECEIVER_KEY, 'Star of Bethlehem', 'Key of Burdens', 'IT MARKED ME', None,
  110.     None, "what you do to show you're carrying something with you",
  111.     ("I can't let go", "It's always with me")),
  112. DECEIVER_TEMPLATES += KeyTemplate(
  113.     DECEIVER_KEY, 'Gorse', 'Key of Promises', 'HELD IN THRALL', None, None,
  114.     "the situation you're trapped in", ("I can't let go", "It's killing me")),
  115. DECEIVER_TEMPLATES += KeyTemplate(
  116.     DECEIVER_KEY, 'Periwinkle', 'Key of Legends', 'MY LEGEND', None, None,
  117.     'an impressive thing you did', ()),
  118. DECEIVER_TEMPLATES += KeyTemplate(
  119.     DECEIVER_KEY, 'Chamomile', 'Key of the Mask',
  120.     'WHO I AM, IN THIS YOUR DREAM', None, None, 'who you are', ()),
  121. DECEIVER_TEMPLATES += KeyTemplate(
  122.     DECEIVER_KEY, 'Widow-Rose', 'Key of the Alien', 'MY NATURE', None, None,
  123.     'why you cannot fit in',
  124.     ("I'm an enemy of the world", 'You cannot keep me away')),
  125. DECEIVER_TEMPLATES += KeyTemplate(
  126.     DECEIVER_KEY, 'Milkmay', 'Key Unformed', 'THAT WHICH STIRS', None, None,
  127.     "what form you're likely to take when play begins",
  128.     ("I'm an enemy of the world", 'I am truth preceding form')),
  129. DECEIVER_TEMPLATES += KeyTemplate(
  130.     DECEIVER_KEY, 'Phoenix Posy', 'Self-Creating Key, the',
  131.     'I HAVE MADE MYSELF...', None, None, 'how you fit into the world',
  132.     ("I'm an enemy of the world", 'from nothing')),
  133. DECEIVER_TEMPLATES += KeyTemplate(
  134.     DECEIVER_KEY, 'Water Lily', 'Key of Something Spiritual', 'MY NATURE',
  135.     None, None, 'how your holiness expresses itself in the world',
  136.     ('Excrucian Deceiver',)),
  137. DECEIVER_TEMPLATES += KeyTemplate(
  138.     DECEIVER_KEY, 'Bilberry', 'Key of the Fallen', 'WHAT I BELIEVE', None,
  139.     None, "what you've accepted", ()),
  140. DECEIVER_TEMPLATES += KeyTemplate(
  141.     DECEIVER_KEY, 'Hemlock', 'Key of the Lie', 'WHO I AM, IN THIS YOUR DREAM',
  142.     None, None, "the story you're trying to tell (often part of another Key)",
  143.     ()),
  144.  
  145.  
  146. MIN_SELECTED = 'min_selected'
  147. MAX_SELECTED = 'max_selected'
  148. SELECTED = 'selected'
  149.  
  150.  
  151. class MultiSelect(wx.Panel):
  152.  
  153.     def __init__(self, parent, min_selected=0, max_selected=None):
  154.         super().__init__(parent)
  155.         self._min_selected = min_selected
  156.         self._max_selected = max_selected
  157.         self._selected = 0
  158.         self._sufficient = min_selected == 0
  159.         self._at_maximum = max_selected == 0
  160.         self.sizer = wx.BoxSizer(orient=wx.VERTICAL)
  161.         self.SetSizer(self.sizer)
  162.  
  163.     def add(self, child):
  164.         self.sizer.Add(child, 0, wx.EXPAND, 0)
  165.         self.Fit()
  166.  
  167.     def _emit_sufficient(self):
  168.         new_value = self._selected >= self._min_selected
  169.         if self._sufficient != new_value:
  170.             # Do... something
  171.             self._sufficient = new_value
  172.  
  173.     def _emit_maximum(self):
  174.         new_value = (
  175.             self._max_selected is not None and
  176.             self._selected == self._max_selected)
  177.         if self._at_maximum != new_value:
  178.             if new_value:
  179.                 for child in self.Children:
  180.                     if not child.Value:
  181.                         child.Disable()
  182.             else:
  183.                 for child in self.Children:
  184.                     child.Enable()
  185.             self._at_maximum = new_value
  186.  
  187.     def _set_value(self, value, field):
  188.         min_selected = value if field == MIN_SELECTED else self._min_selected
  189.         max_selected = value if field == MAX_SELECTED else self._max_selected
  190.         selected = value if field == SELECTED else self._selected
  191.         if max_selected is not None:
  192.             if max_selected < selected:
  193.                 raise ValueError(
  194.                     f'selected ({selected}) cannot exceed maximum '
  195.                     f'({max_selected})')
  196.             if max_selected < min_selected:
  197.                 raise ValueError(
  198.                     f'minimum ({min_selected}) cannot exceed maximum '
  199.                     f'({max_selected})')
  200.         setattr(self, f'_{field}', value)
  201.         self._emit_sufficient()
  202.         self._emit_maximum()
  203.  
  204.     @property
  205.     def selected(self):
  206.         return self._selected
  207.  
  208.     @selected.setter
  209.     def selected(self, value):
  210.         self._set_value(value, SELECTED)
  211.  
  212.     @property
  213.     def min_selected(self):
  214.         return self._min_selected
  215.  
  216.     @min_selected.setter
  217.     def min_selected(self, value):
  218.         self._set_value(value, MIN_SELECTED)
  219.  
  220.     @property
  221.     def max_selected(self):
  222.         return self._max_selected
  223.  
  224.     @max_selected.setter
  225.     def max_selected(self, value):
  226.         self._set_value(value, MAX_SELECTED)
  227.  
  228.  
  229. class KeyButton(wx.ToggleButton):
  230.  
  231.     def __init__(self, parent, label):
  232.         super().__init__(parent, label=label)
  233.         self.Bind(wx.EVT_TOGGLEBUTTON, self.on_push)
  234.  
  235.     def on_push(self, event):
  236.         if self.Value:
  237.             self.Parent.selected += 1
  238.         else:
  239.             self.Parent.selected -= 1
  240.  
  241.  
  242. def make_power():
  243.     frame = wx.Frame(None, title='New Power')
  244.     splitter = wx.SplitterWindow(frame)
  245.     components = wx.Listbook(splitter, style=wx.LB_LEFT)
  246.     diagram = wx.Panel(splitter)
  247.     keys_tab = wx.Panel(components)
  248.     keys_sizer = wx.FlexGridSizer(2, 2, 0, 0)
  249.     keys_sizer.Add(wx.StaticText(keys_tab, label='Selected'))
  250.     keys_sizer.Add(wx.StaticText(keys_tab, label='SelectedList'))
  251.     keys_sizer.Add(wx.StaticText(keys_tab, label='All'))
  252.     keys_all_choices = MultiSelect(keys_tab, 2, 2)
  253.     keys_sizer.Add(keys_all_choices)
  254.     for choice in ['Lotus Flower', 'Vervain', 'Acacia', 'Clematis', 'Aconite',
  255.                    'Wild Oats', 'Star of Bethlehem', 'Gorse', 'Honeysuckle',
  256.                    'Chamomile', 'Wild Rose', 'Hollyhock', 'Mimulus',
  257.                    'Water Lily', 'Oak', 'Alyssym']:
  258.         keys_all_choices.add(KeyButton(keys_all_choices, choice))
  259.     keys_tab.SetSizerAndFit(keys_sizer)
  260.     components.AddPage(keys_tab, 'Keys')
  261.     components.AddPage(wx.Panel(components), 'Foundation')
  262.     components.AddPage(wx.Panel(components), 'Estate')
  263.     components.AddPage(wx.Panel(components), 'Origins')
  264.     components.AddPage(wx.Panel(components), 'Contacts')
  265.     components.AddPage(wx.Panel(components), 'Affiliation')
  266.     components.AddPage(wx.Panel(components), 'Background')
  267.     splitter.SplitVertically(components, diagram)
  268.     return frame
  269.  
  270.  
  271. FRAME = make_power()
  272. FRAME.Show()
  273. app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement