Exemplo n.º 1
0
    def mouse_event(self, msg):
        # drag start
        if msg.command == yutani.MouseEvent.DOWN and msg.buttons & yutani.MouseButton.BUTTON_LEFT:
            self.drag_start()

        if msg.buttons & yutani.MouseButton.BUTTON_RIGHT:
            if not self.menus:

                def set_face(x):
                    self.watchface = self.watchfaces[x]

                faces = [
                    MenuEntryAction(x, None, set_face, x)
                    for x in self.watchfaces.keys()
                ]
                menu_entries = [
                    MenuEntrySubmenu("Watchface", faces, icon='clock'),
                    MenuEntryAction(f"About {app_name}", "star", self.about,
                                    None),
                    MenuEntryDivider(),
                    MenuEntryAction("Exit", "exit", self.exit, None),
                ]
                menu = MenuWindow(menu_entries,
                                  (self.x + msg.new_x, self.y + msg.new_y),
                                  root=self)
Exemplo n.º 2
0
    def reinit_menus(self):
        accessories = [
            MenuEntryAction("Calculator", "calculator", launch_app,
                            "calculator.py"),
            MenuEntryAction("Clock Widget", "clock", launch_app, "clock.py"),
            MenuEntryAction("File Browser", "folder", launch_app,
                            "file_browser.py"),
            MenuEntryAction("Terminal", "utilities-terminal", launch_app,
                            "terminal"),
        ]
        accessories.extend(self.extra('accessories'))
        demos = [
            MenuEntrySubmenu("Cairo", [
                MenuEntryAction("Cairo Demo", "cairo-demo", launch_app,
                                "cairo-demo"),
                MenuEntryAction("Cairo Snow", "snow", launch_app,
                                "make-it-snow"),
                MenuEntryAction("Pixman Demo", "pixman-demo", launch_app,
                                "pixman-demo"),
            ]),
            MenuEntrySubmenu("Mesa (swrast)", [
                MenuEntryAction("Gears", "gears", launch_app, "gears"),
                MenuEntryAction("Teapot", "teapot", launch_app, "teapot"),
            ]),
            MenuEntryAction("Draw Lines", "drawlines", launch_app,
                            "drawlines"),
            MenuEntryAction("Julia Fractals", "julia", launch_app, "julia"),
            MenuEntryAction("Plasma", "plasma", launch_app, "plasma"),
        ]
        demos.extend(self.extra('demos'))
        games = [
            MenuEntryAction("Mines", "mines", launch_app, "mines.py"),
        ]
        games.extend(self.extra('games'))
        graphics = [
            MenuEntryAction("ToaruPaint", "applications-painting", launch_app,
                            "painting.py"),
        ]
        graphics.extend(self.extra('graphics'))
        settings = [
            MenuEntryAction("Package Manager", "package", launch_app,
                            "gsudo package_manager.py"),
            MenuEntryAction("Select Wallpaper", "select-wallpaper", launch_app,
                            "select_wallpaper.py"),
        ]
        settings.extend(self.extra('settings'))

        self.menu_entries = [
            MenuEntrySubmenu("Accessories", accessories),
            MenuEntrySubmenu("Demos", demos),
            MenuEntrySubmenu("Games", games),
            MenuEntrySubmenu("Graphics", graphics),
            MenuEntrySubmenu("Settings", settings),
            MenuEntryDivider(),
            MenuEntryAction("Help", "help", launch_app, "help-browser.py"),
            MenuEntryAction("About ToaruOS", "star", launch_app,
                            "about-applet.py"),
            MenuEntryAction("Log Out", "exit", logout_callback, ""),
        ]
Exemplo n.º 3
0
    def __init__(self, decorator, path):
        super(PaintingWindow,
              self).__init__(self.base_width + decorator.width(),
                             self.base_height + decorator.height(),
                             title=app_name,
                             icon="applications-painting",
                             doublebuffer=True)
        self.move(100, 100)
        self.x = 100
        self.y = 100
        self.decorator = decorator
        self.picker = None
        self.last_color = (0, 0, 0)
        self.modifiers = None
        self.checkpattern = self.checkerboard(24)

        def about_window(action):
            AboutAppletWindow(self.decorator, f"About {app_name}",
                              "/usr/share/icons/48/applications-painting.png",
                              _description, "applications-painting")

        def help_browser(action):
            subprocess.Popen(["help-browser.py", "painting.trt"])

        def close_picker():
            self.last_color = self.picker.color
            self.picker = None

        def open_file(action):
            OpenFileDialog(self.decorator,
                           "Open...",
                           glob="*.png",
                           callback=self.load_buffer,
                           window=self)

        def new_surface(action):
            # TODO: prompt for size
            if self.buf:
                self.buf.destroy()
            self.new_buffer(*action)
            self.draw()

        def new_prompt(action):
            def input_callback(input_window):
                width = int(input_window.tr.text)
                input_window.close()

                def second_callback(input_window):
                    height = int(input_window.tr.text)
                    input_window.close()
                    new_surface((width, height))

                TextInputWindow(self.decorator,
                                "Height?",
                                "new",
                                text="500",
                                callback=second_callback,
                                window=self)

            TextInputWindow(self.decorator,
                            "Width?",
                            "new",
                            text="500",
                            callback=input_callback,
                            window=self)

        def save_file(action):
            self.modified = False
            path = '/tmp/painting.png'
            self.set_title(f'{os.path.basename(path)} - {app_name}', self.icon)
            self.surface.write_to_png(path)

        def select_color(action):
            if self.picker:
                return
            else:
                self.picker = ColorPickerWindow(self.decorator, close_picker)
                self.picker.draw()

        def clear_everything(action):
            self.draw_ctx.save()
            self.draw_ctx.set_operator(cairo.OPERATOR_SOURCE)
            self.draw_ctx.rectangle(0, 0, self.surface.get_width(),
                                    self.surface.get_height())
            self.draw_ctx.set_source_rgba(0, 0, 0, 0)
            self.draw_ctx.fill()
            self.draw_ctx.restore()

        menus = [
            ("File", [
                MenuEntrySubmenu("New...", [
                    MenuEntryAction("500×500", "new", new_surface, (500, 500)),
                    MenuEntryAction("800×600", "new", new_surface, (800, 600)),
                    MenuEntryAction("Custom...", "new", new_prompt, None),
                ],
                                 icon="new"),
                MenuEntryAction("Open", "open", open_file, None),
                MenuEntryAction("Save", "save", save_file, None),
                MenuEntryDivider(),
                MenuEntryAction("Exit", "exit", self.exit_app, None),
            ]),
            ("Tools", [
                MenuEntryAction("Color", None, select_color, None),
                MenuEntryAction("Clear Everything", None, clear_everything,
                                None),
            ]),
            ("Help", [
                MenuEntryAction("Contents", "help", help_browser, None),
                MenuEntryDivider(),
                MenuEntryAction(f"About {app_name}", "star", about_window,
                                None),
            ]),
        ]

        self.menubar = MenuBarWidget(self, menus)

        self.menus = {}
        self.hovered_menu = None

        if not path:
            self.new_buffer(500, 500)
        else:
            self.load_buffer(path)

        self.hilighted = None
        self.was_drawing = False
        self.line_width = 2.0
        self.curs_x = None
        self.curs_y = None
        self.moving = False
        self.scale = 1.0
        self.modified = False
Exemplo n.º 4
0
    def __init__(self, decorator):
        super(HelpBrowserWindow,
              self).__init__(self.base_width + decorator.width(),
                             self.base_height + decorator.height(),
                             title=app_name,
                             icon="help",
                             doublebuffer=True)
        self.move(100, 100)
        self.decorator = decorator
        self.current_topic = "0_index.trt"
        self.text_buffer = None
        self.text_offset = 0
        self.scroll_offset = 0
        self.tr = None
        self.size_changed = False

        self.special = {}
        self.special['contents'] = self.special_contents
        self.special['demo'] = self.special_demo
        self.down_text = None
        self.cache = {}
        self.history = []
        self.history_index = 0

        def herp(action):
            print(action)

        self.history_menu = MenuEntrySubmenu('History...',
                                             [MenuEntryDivider()])

        def exit_app(action):
            menus = [x for x in self.menus.values()]
            for x in menus:
                x.definitely_close()
            self.close()
            sys.exit(0)

        def about_window(action):
            AboutAppletWindow(self.decorator, f"About {app_name}",
                              "/usr/share/icons/48/help.png", _description,
                              "help")

        menus = [
            (
                "File",
                [
                    #MenuEntryAction("Open...",None,print_derp,None),
                    #MenuEntryDivider(),
                    MenuEntryAction("Exit", "exit", exit_app, None),
                ]),
            ("Go", [
                MenuEntryAction("Home", "home", self.go_page, "0_index.trt"),
                MenuEntryAction("Topics", "bookmark", self.go_page,
                                "special:contents"),
                MenuEntryDivider(),
                self.history_menu,
                MenuEntryAction("Back", "back", self.go_back, None),
                MenuEntryAction("Forward", "forward", self.go_forward, None),
            ]),
            ("Help", [
                MenuEntryAction("Contents", "help", self.go_page,
                                "help_browser.trt"),
                MenuEntryDivider(),
                MenuEntryAction(f"About {app_name}", "star", about_window,
                                None),
            ]),
        ]

        self.menubar = MenuBarWidget(self, menus)

        self.menus = {}
        self.hovered_menu = None

        self.update_text_buffer()
        self.navigate("0_index.trt")
Exemplo n.º 5
0
    def __init__(self, decorator):
        super(MinesWindow, self).__init__(self.base_width + decorator.width(), self.base_height + decorator.height(), title=app_name, icon="mines", doublebuffer=True)
        self.move(100,100)
        self.decorator = decorator
        self.button_width = {}
        self.button_height = 0

        def exit_app(action):
            menus = [x for x in self.menus.values()]
            for x in menus:
                x.definitely_close()
            self.close()
            sys.exit(0)
        def about_window(action):
            AboutAppletWindow(self.decorator,f"About {app_name}","/usr/share/icons/48/mines.png",_description,"mines")
        def help_browser(action):
            subprocess.Popen(["help-browser.py","mines.trt"])
        def custom_game(action):
            def input_callback(input_window):
                size = int(input_window.tr.text)
                input_window.close()
                def second_callback(input_window):
                    mines = int(input_window.tr.text)
                    input_window.close()
                    self.new_game((size,mines))

                TextInputWindow(self.decorator,"How many mines?","mines",text="90",callback=second_callback,window=self)
            TextInputWindow(self.decorator,"How wide/tall?","mines",text="20",callback=input_callback,window=self)

        menus = [
            ("File", [
                MenuEntrySubmenu("New Game...",[
                    MenuEntryAction("9×9, 10 mines",None,self.new_game,(9,10)),
                    MenuEntryAction("16×16, 40 mines",None,self.new_game,(16,40)),
                    MenuEntryAction("20×20, 90 mines",None,self.new_game,(20,90)),
                    MenuEntryAction("Custom...",None,custom_game,None),
                ],icon="new"),
                MenuEntryDivider(),
                MenuEntryAction("Exit","exit",exit_app,None),
            ]),
            ("Help", [
                MenuEntryAction("Contents","help",help_browser,None),
                MenuEntryDivider(),
                MenuEntryAction(f"About {app_name}","star",about_window,None),
            ]),
        ]

        self.menubar = MenuBarWidget(self,menus)

        self.tr = text_region.TextRegion(self.decorator.left_width()+5,self.decorator.top_height()+self.menubar.height,self.base_width-10,40)
        self.tr.set_font(toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF,18))
        self.tr.set_alignment(2)
        self.tr.set_valignment(2)
        self.tr.set_one_line()
        self.tr.set_ellipsis()


        self.error = False

        self.hover_widget = None
        self.down_button = None

        self.menus = {}
        self.hovered_menu = None
        self.modifiers = 0

        self.new_game((9,10))