display seed, add input validation
This commit is contained in:
		
							parent
							
								
									1181e75ea0
								
							
						
					
					
						commit
						a90adbb165
					
				
							
								
								
									
										10
									
								
								bingo.py
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								bingo.py
									
									
									
									
									
								
							@ -5,6 +5,7 @@ from textual.widgets import Header, Footer, Input, Label, Static, Button
 | 
				
			|||||||
from textual.message import Message
 | 
					from textual.message import Message
 | 
				
			||||||
from textual.color import Color
 | 
					from textual.color import Color
 | 
				
			||||||
from textual.containers import Horizontal
 | 
					from textual.containers import Horizontal
 | 
				
			||||||
 | 
					from textual.validation import Number
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from asyncio import sleep
 | 
					from asyncio import sleep
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -69,12 +70,17 @@ class BingoApp(App):
 | 
				
			|||||||
class BingoDisplay(Static):
 | 
					class BingoDisplay(Static):
 | 
				
			||||||
    def compose(self) -> ComposeResult:
 | 
					    def compose(self) -> ComposeResult:
 | 
				
			||||||
        """Create child widgets for the app."""
 | 
					        """Create child widgets for the app."""
 | 
				
			||||||
        yield BingoBoard()
 | 
					        self.board = BingoBoard()
 | 
				
			||||||
 | 
					        yield self.board
 | 
				
			||||||
        input_field = Input(
 | 
					        input_field = Input(
 | 
				
			||||||
 | 
					                str(self.board.seed),
 | 
				
			||||||
                type='integer',
 | 
					                type='integer',
 | 
				
			||||||
                placeholder='UNIX timestamp',
 | 
					                placeholder='UNIX timestamp',
 | 
				
			||||||
                max_length=10,
 | 
					                max_length=10,
 | 
				
			||||||
                classes='seed_input'
 | 
					                classes='seed_input',
 | 
				
			||||||
 | 
					                validators=[
 | 
				
			||||||
 | 
					                    Number(minimum=1000000000, maximum = int(datetime.now().timestamp()))
 | 
				
			||||||
 | 
					                ]
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        input_field.border_title = 'Seed'
 | 
					        input_field.border_title = 'Seed'
 | 
				
			||||||
        yield Horizontal(
 | 
					        yield Horizontal(
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										11
									
								
								bingo.tcss
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								bingo.tcss
									
									
									
									
									
								
							@ -15,11 +15,11 @@ BingoDisplay {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.seed_input {
 | 
					.seed_input {
 | 
				
			||||||
  width: 50%;
 | 
					  width: 70%;
 | 
				
			||||||
  border-title-align: left;
 | 
					  border-title-align: left;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
.roll_btn {
 | 
					.roll_btn {
 | 
				
			||||||
  width: 50%;
 | 
					  width: 30%;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.box {
 | 
					.box {
 | 
				
			||||||
@ -28,3 +28,10 @@ BingoDisplay {
 | 
				
			|||||||
    text-align: center;
 | 
					    text-align: center;
 | 
				
			||||||
    content-align: center middle;
 | 
					    content-align: center middle;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Input.-valid {
 | 
				
			||||||
 | 
					    border: tall $success 60%;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					Input.-valid:focus {
 | 
				
			||||||
 | 
					    border: tall $success;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user