Commit 579f480d authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Initial commit.

parents
*~
*.pyc
*.pyo
.idea
.coverage
BoxLayout:
orientation: 'vertical'
canvas.before:
Color:
rgba: (1.0, 1.0, 1.0, 1.0)
Rectangle:
pos: self.pos
size: self.size
AnchorLayout:
GridLayout:
id: grid
size_hint: (None, None)
width: min(self.parent.width, self.parent.height)
height: min(self.parent.width, self.parent.height)
ScrollView:
BoxLayout:
orientation: 'vertical'
size_hint: (None, None)
size: self.minimum_size
Label:
text: 'ACROSS'
size_hint: (None, None)
font_size: sp(24)
padding: (sp(12), sp(12))
size: self.texture_size
BoxLayout:
id: across_clues
orientation: 'vertical'
size_hint: (None, None)
size: self.minimum_size
Label:
text: 'DOWN'
size_hint: (None, None)
font_size: sp(24)
padding: (sp(12), sp(12))
size: self.texture_size
BoxLayout:
id: down_clues
orientation: 'vertical'
size_hint: (None, None)
size: self.minimum_size
<Label>:
color: (0.0, 0.0, 0.75, 1.0)
<BoxLabel>:
canvas.before:
Color:
rgba: (0.0, 0.0, 0.75, 1.0)
Rectangle:
pos: self.pos
size: self.size
Color:
rgba: (1.0, 1.0, 1.0, 1.0)
Rectangle:
pos: (self.x + 0.1 * self.width, self.y + 0.1 * self.height)
size: (0.8 * self.width, 0.8 * self.height)
text_size: self.size
halign: 'center'
valign: 'center'
<Box>:
canvas.before:
Color:
rgba: (0.0, 0.0, 0.75, 1.0)
Rectangle:
pos: self.pos
size: self.size
BoxLabel:
text: f'{root.character}'
font_size: self.height
size_hint: (1.0, 1.0)
pos_hint: {'x': 0.0, 'y': 0.0}
opacity: 1.0 if root.character is not None else 0.0
BoxLabel:
text: f'{root.number}'
font_size: 0.5 * self.height
size_hint: (1 / 3, 1 / 3)
pos_hint: {'x': 0.0, 'y': 2 / 3}
opacity: 1.0 if root.number is not None else 0.0
<Clue>:
text: f'{root.number}. {root.clue}'
size_hint: (None, None)
padding: (sp(6), sp(6))
size: self.texture_size
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.properties import NumericProperty, StringProperty
from kivy.modules import inspector
from kivy.core.window import Window
class Crossword:
def __init__(self, characters, clues):
self.characters = characters
self.size = len(characters)
self.clues = clues
def __getitem__(self, coordinates):
row, column = coordinates
try:
return self.characters[row][column]
except IndexError:
return None
def _get_clue(self, start_row, start_column, row_step, column_step):
word = ''
row, column = start_row, start_column
while self[row, column] is not None:
word += self[row, column]
row += row_step
column += column_step
return self.clues.get(word)
def get_across_clue(self, row, column):
return self._get_clue(row, column, 0, 1)
def get_down_clue(self, row, column):
return self._get_clue(row, column, 1, 0)
CROSSWORD = Crossword((
(None, None, None, None, None, None),
(None, 'B', 'U', 'G', 'S', None),
(None, 'U', 'N', 'I', 'T', None),
(None, 'G', 'I', 'V', 'E', None),
(None, 'S', 'T', 'E', 'M', None),
(None, None, None, None, None, None),
), {
'BUGS': 'Informal name for software faults',
'UNIT': 'Very traceable software testing',
'GIVE': 'To make a present of something',
'STEM': 'Group of disciplines including SE',
})
class BoxLabel(Label):
pass
class Box(FloatLayout):
number = NumericProperty(None, allownone=True)
character = StringProperty(None, allownone=True)
class Clue(Label):
number = NumericProperty(0)
clue = StringProperty('')
class CrosswordApp(App):
def build(self):
inspector.create_inspector(Window, self)
def _display(self, crossword):
grid = self.root.ids.grid
grid.clear_widgets()
grid.rows = crossword.size
across_clues = self.root.ids.across_clues
across_clues.clear_widgets()
down_clues = self.root.ids.down_clues
down_clues.clear_widgets()
counter = 0
for row in range(crossword.size):
for column in range(crossword.size):
# Create a grid cell:
character = crossword[row, column]
numbered = False
if character is not None:
if crossword[row, column - 1] is None and crossword[row, column + 1] is not None:
numbered = True
if crossword[row - 1, column] is None and crossword[row + 1, column] is not None:
numbered = True
number = None
if numbered:
counter += 1
number = counter
grid.add_widget(Box(number=number, character=character))
# Maybe create an across clue:
across_clue = crossword.get_across_clue(row, column)
if across_clue is not None:
across_clues.add_widget(Clue(number=number, clue=across_clue))
# Maybe create a down clue:
down_clue = crossword.get_down_clue(row, column)
if down_clue is not None:
down_clues.add_widget(Clue(number=number, clue=down_clue))
def on_start(self):
self._display(CROSSWORD)
if __name__ == '__main__':
app = CrosswordApp()
app.run()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment