def __init__( self, section, title_text, value_text='', title_text_format=textformat.TextFormat(slo.slo['appearance']['font'], 18, color.text), value_text_format=textformat.TextFormat(slo.slo['appearance']['font'], 14, color.text)): self.section = section self.title_text = title_text self.value_text = value_text self.title_text_format = title_text_format self.value_text_format = value_text_format self.title_surface = self.title_text_format.render(self.title_text) self.value_surface = self.value_text_format.render(self.value_text) self.line_surface = pygame.Surface( (2, self.title_surface.get_height() + self.value_surface.get_height())) self.line_surface.fill(color.text) self.text_x = 36 + self.section.setting.x self.y = 0 # 처음 텍스트의 y 시작좌표 self.first = True self.height = self.title_surface.get_height( ) + self.value_surface.get_height()
def __init__(self, setting, name: str, *elements): self.setting = setting self.name = name self.arguments = elements self.is_open = False self.x = self.setting.gap - 4 self.elements = [] for argument in self.arguments: self.elements.append(argument[0](self, *argument[1])) self.header_width = self.setting.width - 25 self.header = pygame.Surface((self.header_width, self.header_height)) self.header.fill(slo.setting['color']['background']) self.header.set_alpha(slo.setting['opacity']['background']) self.less_icon_surface = pygame.transform.smoothscale( pygame.image.load('./res/image/icon/less.png'), (18, 18)) self.less_surface = self.less_icon_surface self.less_surface_position = [0, 0] self.less_angle = 0 self.less_angle_target = 0 self.less_angle_moving = False self.rect_height = (len(self.elements) + 1) * 20 for element in self.elements: self.rect_height += element.height self.element_background_surface = pygame.Surface( (self.header.get_width(), self.rect_height)) self.element_background_surface.fill( slo.setting['color']['background']) self.element_background_surface.set_alpha( slo.setting['opacity']['elements_background']) self.name_surface = textformat.TextFormat( slo.slo['appearance']['font'], 17, color.text).render(self.name) self.height = self.header_height self.index = 0 self.y = 0
def __init__(self): self.background_surface = pygame.Surface((self.width, self.height)) self.background_surface.fill(slo.setting['color']['background']) self.background_surface.set_alpha(slo.setting['opacity']['background']) self.header_surface = pygame.Surface((self.width, 40)) self.header_surface.fill(color.white) self.header_surface.set_alpha(10) self.x = -self.width - self.gap self.x_moving = True self.x_target = self.gap self.y = self.gap self.setting_logo_surface = pygame.transform.smoothscale(pygame.image.load('./res/image/icon/setting.png'), (19, 19)).convert_alpha() self.setting_text_surface = textformat.TextFormat(slo.slo['appearance']['font'], 17, color.text).render('설정') self.back_button_surface = pygame.transform.smoothscale(pygame.image.load('./res/image/icon/left_arrow.png'), (19, 19)).convert_alpha() self.setting_logo_position = (self.x + 12, self.gap + 10) self.setting_text_position = (self.x + 38, self.gap + 7) self.back_button_position = (self.x + self.width - 32, self.gap + 10) self.quit = False self.sections = [ section.Section( self, '시스템 정보', (text.Text, ('시스템 버전', slo.slo['metadata']['version'])), (text.Text, ('개발', 'Я ШTEЛO의 SloOS 팀')) ), section.Section( self, '디자인', (text.Text, ('버커', 'Bucker')), (text.Text, ('잠금화면 ', 'Lock Screen')), (text.Text, ('테마', 'Theme')) ), section.Section( self, '독' ), section.Section( self, '테스트', (slider.Slider, ('테스트 슬라이더', ('안녕', '반가워'))) ) ]
def __init__(self, x=None, y=None, width=None, height=None, value=None, text_format=None, background_color=None, writable=None, window=None): super().__init__(window) self.x = x self.y = y self.width = width self.height = height self.value = value self.text_format = text_format self.background_color = background_color self.writable = writable if self.x is None: self.x = 0 if self.y is None: self.y = 0 if self.width is None: self.width = self.window.width if self.height is None: self.height = self.window.height if self.value is None: self.value = '' if self.text_format is None: self.text_format = textformat.TextFormat( slo.slo['appearance']['domino_font'], 18, color.text) if self.background_color is None: self.background_color = color.background if self.writable is None: self.writable = True self.surface = pygame.Surface((self.width, self.height))
def __init__(self, x=None, y=None, text=None, text_format=None, window=None): super().__init__(window) self.x = x self.y = y self.text = text self.text_format = text_format if self.x is None: self.x = 0 if self.y is None: self.y = 0 if self.text is None: self.text = '' if self.text_format is None: self.text_format = textformat.TextFormat( slo.slo['appearance']['font'], 18, color.background) self.surface = self.text_format.render(self.text)
def build_program(self, path): def exception(message): rootobject.add_object( alert.Alert( self.title, f'현재 실행하고 있는 프로그램의 {line_number + 1}번째 줄에 다음과 같은 오류가 발견되었습니다: \n' + str(message))) raise SyntaxError(message) try: code = open(path, 'r').read().split('\n') except UnicodeDecodeError: code = open(path, 'r', encoding='utf-8').read().split('\n') variables = {} for line_number in range(len(code)): line = code[line_number] if '?' in line: line = line[:line.index('?')] if len(line) <= 0: continue while line[-1] == ' ': line = line[:-1] sline = line.split() if sline[0] == 'set-raw': if len(sline) < 3: exception('set-raw 구문의 변수 이름 또는 변수 값이 지정되어 있지 않습니다.') try: variables[sline[1]] = eval(' '.join(sline[2:])) except Exception as e: exception(str(e)) elif sline[0] == 'set': if len(sline) < 3: exception('set 구문의 변수 이름 또는 변수 값이 지정되어 있지 않습니다.') if sline[1] == 'TextFormat': keys = ('font', 'size', 'color') arguments = {} for key in keys: arguments[key] = None for _i in range(len(sline)): _i += 3 try: word = sline[_i] except IndexError: break if _i % 2 == 0: if '_' in word: word = word.replace('_', ' ') if '\\ ' in word: word = word.replace('\\ ', '_') if last_key in keys: if word[0] == '$': arguments[last_key] = variables[word] else: arguments[last_key] = eval(word) else: last_key = word arguments['font'] = arguments['font'].replace('|', '/') if arguments['font'][0] == '%': arguments[ 'font'] = self.directory + arguments['font'][1:] variables[sline[2]] = textformat.TextFormat( font=arguments['font'], size=arguments['size'], colour=arguments['color']) elif sline[0] == 'window-set': # noinspection PyBroadException try: if sline[1] == 'x': self.x = eval(' '.join(sline[2:])) elif sline[1] == 'y': self.y = eval(' '.join(sline[2:])) elif sline[1] == 'title_height': self.title_height = eval(' '.join(sline[2:])) elif sline[1] == 'width': self.width = eval(' '.join(sline[2:])) elif sline[1] == 'height': self.height = eval(' '.join(sline[2:])) elif sline[1] == 'title': self.title = eval(' '.join(sline[2:])) elif sline[1] == 'border_color': self.normal_border_color = eval(' '.join(sline[2:])) elif sline[1] == 'background_color': self.background_color = eval(' '.join(sline[2:])) elif sline[1] == 'highlighted_background_color': self.highlighted_border_color = eval(' '.join( sline[2:])) except Exception as e: exception(e) elif sline[0] == 'window-add': if len(sline) < 2: exception('window-add 구문의 변수형이 지정되어 있지 않습니다.') arguments = {} last_key = '' if sline[1] == 'TextArea': keys = ('x', 'y', 'width', 'height', 'value', 'text_format', 'background_color', 'writable') for key in keys: arguments[key] = None for _i in range(len(sline)): _i += 2 try: word = sline[_i] except IndexError: break if _i % 2 == 1: if '_' in word: word = word.replace('_', ' ') if '\\ ' in word: word = word.replace('\\ ', '_') if last_key in keys: if word[0] == '$': arguments[last_key] = variables[word] else: arguments[last_key] = eval(word) else: last_key = word self.elements.append( textarea.TextArea( x=arguments['x'], y=arguments['y'], width=arguments['width'], height=arguments['height'], value=arguments['value'], text_format=arguments['text_format'], background_color=arguments['background_color'], writable=arguments['writable'], window=self)) elif sline[1] == 'Text': keys = ('x', 'y', 'text', 'text_format') for key in keys: arguments[key] = None for _i in range(len(sline)): _i += 2 try: word = sline[_i] except IndexError: break if _i % 2 == 1: if '_' in word: word = word.replace('_', ' ') if '\\ ' in word: word = word.replace('\\ ', '_') if last_key in keys: if word[0] == '$': if word not in variables.keys(): exception( f'{word}라는 변수는 지정되지 않았습니다.\n변수 형에 언더바(_)를 사용했을 가능성이 있습니다.' ) arguments[last_key] = variables[word] else: try: arguments[last_key] = eval(word) except NameError as e: exception(f'{e}') else: last_key = word self.elements.append( text.Text(x=arguments['x'], y=arguments['y'], text=arguments['text'], text_format=arguments['text_format'], window=self)) else: exception(f'변수형 {sline[1]}을(를) 알 수 없습니다.') else: exception(f'명령어 {sline[0]}을(를) 알 수 없습니다.') return False
def __init__(self, title: str, message: str, kind=None, background_color=color.background, background_opacity=127, title_text_format=textformat.TextFormat(slo.slo['appearance']['font'], 32, color.text), text_format=rootobject.default_text_format, gap=20): self.title = title self.messages = message + '\n\n\n화면을 왼쪽 클릭 해서 계속합니다.' self.kind = kind self.background_color = background_color self.background_opacity = background_opacity self.title_text_format = title_text_format self.message_text_format = text_format self.gap = gap self.background_surface = pygame.Surface(root.display.size) self.background_surface.blit(root.window, (0, 0)) black_surface = pygame.Surface(root.display.size) black_surface.fill(self.background_color) black_surface.set_alpha(self.background_opacity) self.background_surface.blit(black_surface, (0, 0)) self.title_surface = self.title_text_format.render(self.title) self.title_x = rootobject.center(root.display.size[0], self.title_surface.get_width()) self.message_surfaces = [] self.message_xs = [] for message in self.messages.split('\n'): self.message_surfaces.append(self.message_text_format.render(message)) self.message_xs.append(rootobject.center(root.display.size[0], self.message_surfaces[-1].get_width())) self.title_y = rootobject.center(root.display.size[1], self.title_surface.get_height() + self.gap + len(self.message_surfaces) * self.message_text_format.size) self.message_ys = [] for I in range(len(self.message_surfaces)): self.message_ys.append(self.title_y + self.title_surface.get_height() + self.gap + I * self.message_surfaces[I].get_height()) audioplayer.playsound('./res/sound/alert.wav')
def __init__(self, text_color, background_color, font=slo.slo['appearance']['font']): self.text_color = text_color self.background_color = background_color self.text_format_time = textformat.TextFormat( font, root.display.size[1] // 5, self.text_color) self.text_format_date = textformat.TextFormat( font, root.display.size[1] // 20, self.text_color) self.x = 0 self.target_x = 0 self.lock = True self.click_start_position = cursor.position self.clicking = False self.background = pygame.Surface(root.display.size) if slo.lockscreen['background']['type'] == 'solid': self.background.fill(self.background_color) else: tmp = pygame.transform.smoothscale( pygame.image.load(slo.lockscreen['background']['image_path']), root.display.size).convert() self.background.blit(tmp, (0, 0)) del tmp immediate = str(datetime.datetime.now()) self.date = immediate.split()[0].split('-')[1:] self.time = immediate.split()[1].split(':')[:2] if self.time[0][0] == '0': self.time[0] = self.time[0][1:] self.date_surface = self.text_format_date.render('월 '.join(self.date) + '일') self.date_position = (self.text_format_date.size + self.x, root.display.size[1] - self.text_format_date.size - self.date_surface.get_height()) self.time_surface = self.text_format_time.render(':'.join(self.time)) self.time_position = (self.date_position[0] + self.x, self.date_position[1] - self.time_surface.get_height() + 36) self.system_shutdown_icon_appear = False self.system_shutdown_icon_pappear = False self.system_shutdown_icon_fappear = False self.system_shutdown_icon_eappear = False self.system_shutdown_icon_surface = pygame.transform.smoothscale( pygame.image.load('./res/image/icon/shutdown.png'), (72, 72)) self.system_shutdown_icon_x = root.display.size[0] self.system_shutdown_icon_y = -72 self.system_shutdown_icon_target_x = 0 self.system_shutdown_icon_target_y = 0 self.system_shutdown_icon_x_moving = False self.system_shutdown_icon_y_moving = False self.system_shutdown_delay = 0.5 self.system_shutdown_time = 0 self.system_shutdown_surface = pygame.Surface(root.display.size) self.system_shutdown_surface.fill(color.black) rootobject.RootObject.highlight = LockScreen
def tick(self): pass def render(self): pass def destroy(self): if self in objects: objects.remove(self) def ahead(self): objects.remove(self) objects.append(self) default_text_format = textformat.TextFormat(slo.slo['appearance']['font'], 18, color.text) def center(x, y): return (x - y) / 2 # V 커서가 가르키고 있는 윈도우를 출력함. def get_on_cursor_window(): banned_areas = [] # [(x, y, width, height)] for I in range(len(objects))[::-1]: this_object = objects[I] try: (this_object.y, this_object.width) except AttributeError:
def __init__(self, section, text, contents, value=None, text_format=textformat.TextFormat( slo.slo['appearance']['font'], 18, color.text)): self.section = section self.text = text self.contents = contents self.value = value self.text_format = text_format if self.value is None: self.value = self.contents[0] self.text_surface = self.text_format.render( f'{self.text}: {self.value}') self.line_surface = pygame.Surface((2, self.text_surface.get_height())) self.line_surface.fill(color.text) self.y = 0 # 처음 텍스트의 y 시작좌표 self.first = True self.height = self.text_surface.get_height() self.open = False self.text_moving = False self.line_moving = False self.text_x = 36 + self.section.setting.x self.line_x = 24 + self.text_x self.text_x_target = 0 self.slider_x = self.section.setting.x_target + self.section.setting.width + self.section.setting.gap self.slider_y = -root.display.size[1] self.slider_y_target = self.slider_y self.slider_moving = False self.slider_open = False self.line_x_target = 0 self.slider_background_surface = pygame.Surface( (self.section.setting.width, self.section.setting.height)) self.slider_header_surface = pygame.Surface( (self.section.setting.width, 40)) self.slider_contents = [] self.setting_logo_surface = pygame.transform.smoothscale( pygame.image.load('./res/image/icon/setting.png'), (19, 19)).convert_alpha() self.setting_text_surface = textformat.TextFormat( slo.slo['appearance']['font'], 17, color.text).render(self.text) self.setting_logo_position = [ self.slider_x + 12, self.section.setting.gap + 10 ] self.setting_text_position = [ self.slider_x + 38, self.section.setting.gap + 7 ] self.slider_background_surface.fill(slo.setting['color']['background']) self.slider_background_surface.set_alpha( slo.setting['opacity']['background']) self.slider_header_surface.fill(color.white) self.slider_header_surface.set_alpha(10) for i in range(len(self.contents)): self.slider_contents.append([ self.text_format.render(self.contents[i]), [ self.slider_x + self.section.setting.gap, i * (self.text_format.size + self.section.setting.gap) ], self.contents[i] ]) self.slider_contents_block_size = ( self.slider_background_surface.get_width(), self.text_format.size + self.section.setting.gap)