forked from charrea6/freevo1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptionBox.py
More file actions
143 lines (110 loc) · 4.27 KB
/
OptionBox.py
File metadata and controls
143 lines (110 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------
# OptionBox.py - A drop-down box.
# -----------------------------------------------------------------------
# $Id$
#
# Notes:
# Todo:
#
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2003 Krister Lagerstrom, et al.
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------
import config
from GUIObject import *
from ListBox import *
from Button import *
class OptionBox(Button):
"""
left x coordinate. Integer
top y coordinate. Integer
width Integer
height Integer
text Letter to hold.
bg_color Background color (Color)
fg_color Foreground color (Color)
selected_bg_color Background color (Color)
selected_fg_color Foreground color (Color)
border Border
bd_color Border color (Color)
bd_width Border width Integer
"""
def __init__(self, text=' ', left=None, top=None, width=100, height=25,
bg_color=None, fg_color=None, selected_bg_color=None,
selected_fg_color=None, border=None, bd_color=None,
bd_width=None):
handler = None
Button.__init__(self, text, handler, left, top, width, height, bg_color,
fg_color, selected_bg_color, selected_fg_color,
border, bd_color, bd_width)
self.max_visible = 5
self.h_spacing = 6
self.h_margin = 6
self.v_margin = 2
self.label.h_align = Align.LEFT
self.list = ListBox(width=self.width, height=self.height*self.max_visible)
self.add_child(self.list)
self.list.visible = 0
def change_item(self, direction):
self.list.sort_items()
self.list.scroll(direction)
if self.list.get_selected_index() >= 0:
self.set_text(self.list.get_selected_item().text)
def add_item(self, text, value=None):
self.list.add_item(None, text, value, h_margin=10)
def toggle_selected_index(self, i):
if self.list:
self.list.toggle_selected_index(i)
def toggle_box(self):
if self.list.is_visible():
self.list.visible = 0
self.selected = 1
else:
self.list.visible = 1
self.selected = 0
def _draw(self):
"""
The actual internal draw function.
"""
if not self.width or not self.height or not self.text:
raise TypeError, 'Not all needed variables set.'
if self.selected:
c = self.selected_bg_color.get_color_sdl()
a = self.selected_bg_color.get_alpha()
else:
c = self.bg_color.get_color_sdl()
a = self.bg_color.get_alpha()
self.surface = self.osd.Surface(self.get_size(), 0, 32)
self.surface.fill(c)
self.surface.set_alpha(a)
ar_1 = (self.width-18, 7)
ar_2 = (self.width-8, 7)
ar_3 = (self.width-13, 18)
if self.selected:
arrow_color = self.selected_fg_color.get_color_sdl()
else:
arrow_color = self.fg_color.get_color_sdl()
self.osd.polygon(self.surface, arrow_color, [ar_1, ar_2, ar_3])
if isinstance(self.list, ListBox):
self.list.set_position(self.left, self.top+self.height)
Container._draw(self)
self.blit_parent()
if self.list:
self.list.draw(self.parent.surface)