def __init__(self, content=None, window=None, batch=None, group=None, anchor=ANCHOR_CENTER, offset=(0, 0), parent=None, theme=None, movable=True, on_enter=None, on_escape=None): """ Creates a new dialog. @param content The Widget which we wrap @param window The window to which we belong; used to set the mouse cursor when appropriate. If set, we will add ourself to the window as a handler. @param batch Batch in which we are to place our graphic elements; may be None if we are to create our own Batch @param group Group in which we are to place our graphic elements; may be None @param anchor Anchor point of the window, relative to which we are positioned. If ANCHOR_TOP_LEFT is specified, our top left corner will be aligned to the window's top left corner; if ANCHOR_CENTER is specified, our center will be aligned to the window's center, and so forth. @param offset Offset from the anchor point. A positive X is always to the right, a positive Y to the upward direction. @param theme The Theme which we are to use to generate our graphical appearance. @param movable True if the dialog is able to be moved @param on_enter Callback for when user presses enter on the last input within this dialog, i.e. form submit @param on_escape Callback for when user presses escape """ assert isinstance(theme, dict) Wrapper.__init__(self, content=content) DialogEventManager.__init__(self) self.window = window self.anchor = anchor self.offset = offset self.theme = theme self.is_movable = movable self.on_enter = on_enter self.on_escape = on_escape if batch is None: self.batch = pyglet.graphics.Batch() self.own_batch = True else: self.batch = batch self.own_batch = False self.root_group = DialogGroup(parent=group) self.panel_group = pyglet.graphics.OrderedGroup(0, self.root_group) self.bg_group = pyglet.graphics.OrderedGroup(1, self.root_group) self.fg_group = pyglet.graphics.OrderedGroup(2, self.root_group) self.highlight_group = pyglet.graphics.OrderedGroup(3, self.root_group) self.needs_layout = True self.is_dragging = False if window is None: self.screen = Widget() else: width, height = window.get_size() self.screen = Widget(width=width, height=height) window.push_handlers(self)
def setUp(self): self.widget_store = WidgetStore() self.sample_widget_1 = Widget( name='sample1', num_of_parts=5, created_date='2012-06-14', updated_date='2021-04-25', an_extra_prop=55555, a_complex_extra_prop={'stuff': [4.1, 'eggs', [3, 'spam']]}) self.sample_widget_2 = Widget(name='sample2', num_of_parts=10, created_date='2017-07-04', updated_date='2021-04-25')
def layout(self, x, y): """ Lays out all Widgets within this layout. @param x X coordinate of lower left corner @param y Y coordinate of lower left corner """ Widget.layout(self, x, y) row_index = 0 placement = Widget() placement.y = y + self.height for row in self.content: col_index = 0 placement.x = x placement.height = self.max_heights[row_index] placement.y -= placement.height for cell in row: placement.width = self.max_widths[col_index] if cell is not None: if cell.is_expandable(): cell.expand(placement.width, placement.height) cell.layout(*GetRelativePoint(placement, self.anchor, cell, self.anchor, self.offset)) placement.x += placement.width col_index += 1 row_index += 1
def test_widget_eq(self): equal_widget = Widget( name='sample', num_of_parts=5, created_date='2012-06-14', updated_date='2021-04-25', an_extra_prop=55555, a_complex_extra_prop={'stuff': [4.1, 'eggs', [3, 'spam']]}) non_equal_widget = Widget( name='cheese', num_of_parts=7, created_date='2021-04-14', updated_date='2021-04-14', ) self.assertEqual(self.sample_widget, equal_widget) self.assertNotEqual(self.sample_widget, non_equal_widget)
def setUp(self): self.sample_widget = Widget( name='sample', num_of_parts=5, created_date='2012-06-14', updated_date='2021-04-25', an_extra_prop=55555, a_complex_extra_prop={'stuff': [4.1, 'eggs', [3, 'spam']]})
def layout(self, x, y): self.x, self.y = x, y if self.background is not None: self.background.update(x, y, self.width, self.height) if self.highlight is not None: self.highlight.update(x, y, self.width, self.height) font = self.label.document.get_font() height = font.ascent - font.descent x, y = GetRelativePoint(self, self.anchor, Widget(self.label.content_width, height), self.anchor, (0, 0)) self.label.x = x self.label.y = y - font.descent
def _create_widgets(self): """ Create the widgets and return the one that contains them all. :return: the background widget """ # Create the background widget. bg = self._rm.get_image(BACKGROUND_IMAGE, self.screen.get_size()) bg_widget = ImageWidget((0, 0), self.screen.get_size(), -1, bg) # Create the container for the input widgets. x = (self.screen.get_width() - INPUT_WIDTH - INPUT_PADDING[1] - INPUT_PADDING[3]) / 2 y = self.screen.get_height() / 2 w = INPUT_WIDTH + INPUT_PADDING[1] + INPUT_PADDING[3] h = self.screen.get_height() - y input_container = Widget((x, y), (w, h), 0) bg_widget.add_widget(input_container) # Create the input widgets. username_input = TextInput((0, 0), INPUT_WIDTH, 0, self._font, padding=INPUT_PADDING, color=INPUT_FORE_COLOR, fill=INPUT_FILL_COLOR, default_text="username", default_font=self._default_font) host_input = copy.copy(username_input) host_input.default_text = "host" host_input.position = (0, INPUT_OFFSET) port_input = copy.copy(username_input) port_input.default_text = "port" port_input.position = (0, 2*INPUT_OFFSET) input_container.add_widget(username_input) input_container.add_widget(host_input) input_container.add_widget(port_input) self._text_inputs = {"username": username_input, "host": host_input, "port": port_input} # Create the button widget. btn = special_widgets.simple_button((0, 3*INPUT_OFFSET), (w, 100), "Login", self._font) def btn_clicked(x, y): self._ev_manager.post(events.LoginRequestedEvent()) btn.handle_clicked = btn_clicked input_container.add_widget(btn) # Create the connection failed warning. self._connection_failed_warning = special_widgets.warning_widget(None, (400, 100), "Connection failed", self._font, screen_size=self.screen.get_size()) bg_widget.add_widget(self._connection_failed_warning) self._username_taken_warning = special_widgets.warning_widget(None, (400, 100), "Username already taken", self._font, screen_size=self.screen.get_size()) bg_widget.add_widget(self._username_taken_warning) return bg_widget
def layout(self, x, y): """ Positions the Frame. @param x X coordinate of lower left corner @param y Y coordinate of lower left corner """ self.x, self.y = x, y self.frame.update(x, y, self.width, self.height) # In some cases the frame graphic element may allocate more space for # the content than the content actually fills, due to repeating # texture constraints. Always center the content. x, y, width, height = self.frame.get_content_region() interior = Widget(width, height) interior.x, interior.y = x, y x, y = GetRelativePoint(interior, self.anchor, self.content, self.anchor, self.content_offset) self.content.layout(x, y)
def ask_tricks(self, n): """ Ask the user for the number of tricks. :param n: the maximum number of tricks """ # Create the container with the fade in effect. container = Widget((self.screen.get_width() / 2 - 200, 100), (400, self.screen.get_height() - 120), 40) container.opacity = 0 container.add_action(actions.FadeInAction(0.5)) self._ask_tricks_widget = container self._background_widget.add_widget(container) # Create the question text. text_w = special_widgets.warning_widget((0, 0), (400, 60), "How many tricks do you make?", self._font, close_on_click=False) text_w.visible = True container.add_widget(text_w) # Create the numbers. class ChooseHandler(object): def __init__(self, view, nn): self._view = view self._n = nn def __call__(self, x, y): self._view._handle_say_tricks(self._n) for i in xrange(n + 1): size = (50, 50) pos = ((i % 6) * (size[0] + 20), 80 + (i / 6) * (size[1] + 20)) w = special_widgets.warning_widget(pos, size, str(i), self._font, close_on_click=False) w.visible = True w.handle_clicked = ChooseHandler(self, i) container.add_widget(w)
settings = get_config() # Choosing theme time = datetime.now().timetuple() if time.tm_hour >= settings['time']['dark'] or time.tm_hour < settings['time'][ 'light']: theme_mode = 0 else: theme_mode = 1 # theme_mode = 1 # Rainmeter if settings['rainmeter'][0]: widgets = settings['rainmeter'][1] for widget in widgets: working_widget = Widget(widget) working_widget.switch(theme_mode) # Windows Theme if settings['windows']: registry_keys = ["AppsUseLightTheme", "SystemUsesLightTheme"] for registry_key in registry_keys: working_key = Registry(registry_key) working_key.set(theme_mode) # Wallpaper if settings['wallpaper'][0]: if theme_mode == 1: wallpaper = settings['wallpaper'][1]["light"] elif theme_mode == 0: wallpaper = settings['wallpaper'][1]["dark"]
new_date.setTimeZone(timezone) return new_date def read_data(fname): df = pd.read_csv(fname) df = df.drop(df[df.mag < 0].index) magnitudes = df["mag"] timezone = QTimeZone(b'Europe/Berlin') times = df['time'].apply(lambda x: transform_date(x, timezone)) return times, magnitudes if __name__ == '__main__': options = argparse.ArgumentParser() options.add_argument('-f', '--file', type=str, required=True) args = options.parse_args() data = read_data(args.file) # Qt Application app = QApplication(sys.argv) widget = Widget(data) window = MainWindow(widget) window.show() sys.exit(app.exec_())
def __init__(self, buttonObj): super(Button, self).__init__(buttonObj['widget_id']) self.buttonObj = buttonObj self.btnIcon = self.buttonObj.children[0] self.widget = Widget(buttonObj)
dispatcher = BearEventDispatcher() loop = BearLoop(t, dispatcher) dispatcher.register_listener(ClosingListener(), ['misc_input', 'tick']) t.start() atlas = Atlas( XpLoader(os.path.dirname(__file__) + '/demo_assets/test_atlas.xp'), os.path.dirname(__file__) + '/demo_assets/test_atlas.json') elements = [] positions = [] names = [] x = 1 y = 1 y_step = 0 for element in sorted(atlas.elements.keys()): w = ElementBox(Widget(*atlas.get_element(element)), name=element) elements.append(w) if x + w.width > 45: y += y_step x = 1 y_step = 0 positions.append((x, y)) x += w.width + 1 if w.height + 1 >= y_step: y_step = w.height + 1 view_height = y + y_step if y + y_step > 50 else 50 chars = [[' ' for _ in range(45)] for _ in range(view_height)] colors = copy_shape(chars, 'white') element_view = InputScrollable(chars, colors, view_pos=(0, 0),
def test_construction_bad_args(self): with self.assertRaises( TypeError, msg='constructor should be called with all required args'): Widget(name=10, created_date='2012-06-14', updated_date='2021-04-25') with self.assertRaises(TypeError, msg='name should be type str'): Widget(name=10, num_of_parts=5, created_date='2012-06-14', updated_date='2021-04-25') with self.assertRaises(ValueError, msg='name should be 64 chars or less'): Widget( name= 'sampleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', num_of_parts=5, created_date='2012-06-14', updated_date='2021-04-25') with self.assertRaises(TypeError, msg='num_of_parts should be type int'): Widget(name='sample', num_of_parts='5', created_date='2012-06-14', updated_date='2021-04-25') with self.assertRaises(TypeError, msg='created_date should be type str'): Widget(name='sample', num_of_parts=5, created_date=0, updated_date='2021-04-25') with self.assertRaises(TypeError, msg='updated_date should be type str'): Widget(name=10, num_of_parts=5, created_date='2012-06-14', updated_date=20210425) with self.assertRaises( ValueError, msg='created_date must abide YYYY-MM-DD format'): Widget(name='sample', num_of_parts=5, created_date='2012-6-14', updated_date='2021-04-25') with self.assertRaises( ValueError, msg='updated_date must abide YYYY-MM-DD format'): Widget(name='sample', num_of_parts=5, created_date='2012-06-14', updated_date='04-25-2021') with self.assertRaises( ValueError, msg='every extra widget property must be serializable to json' ): Widget( name='sample', num_of_parts=5, created_date='2012-06-14', updated_date='2021-04-25', a_complex_extra_prop={ 'stuff': [ set([1, 2, 3]), # json doens't have set type 'eggs', [3, 'spam'] ] })