示例#1
0
    def __init__(self,text="",password=False,placeholder="",width=200,height=20):
        self.font = toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF, 13, self.color)
        self.tr = text_region.TextRegion(0,0,200,20,font=self.font)
        self.width = width
        self.height = height

        self.placeholder = placeholder
        self.ph_font = toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF, 13, self.ph_color)
        self.ph_tr = text_region.TextRegion(0,0,200,20,font=self.ph_font)
        self.ph_tr.set_text(placeholder)

        self.is_password = password
        self.tr.set_one_line()
        self.tr.break_all = True
        self.update_text(text)
        self.is_focused = False
        self.cursor_index = len(self.text)
        self.cursor_x = self.tr.get_offset_at_index(self.cursor_index)[1][1]

        if password:
            self.ctrl_chars = []

        self.x = 0
        self.y = 0

        self.text_changed = None

        self.submit = None
        self.tab_handler = None
示例#2
0
    def __init__(self, raw):
        self.ttl = time.time() + raw.ttl
        strings = ctypes.addressof(raw) + toast.ToastMessage.strings.offset
        self.title = ctypes.cast(strings, ctypes.c_char_p).value
        self.content = ctypes.cast(strings + 1 + len(self.title),
                                   ctypes.c_char_p).value
        flags = yutani.WindowFlag.FLAG_NO_STEAL_FOCUS | yutani.WindowFlag.FLAG_DISALLOW_DRAG | yutani.WindowFlag.FLAG_DISALLOW_RESIZE
        super(Notification, self).__init__(self.base_width,
                                           self.base_height,
                                           flags=flags,
                                           doublebuffer=True)
        self.update_location(len(notifications) * (self.base_height + 8))

        self.title_tr = text_region.TextRegion(10,
                                               10,
                                               self.width - 20,
                                               15,
                                               font=title_font)
        self.title_tr.set_text(self.title.decode('utf-8'))

        self.content_tr = text_region.TextRegion(10,
                                                 30,
                                                 self.width - 20,
                                                 self.height - 40 - 5,
                                                 font=content_font)
        self.content_tr.set_line_height(16)
        self.content_tr.set_richtext(self.content.decode('utf-8'))
        self.draw()
示例#3
0
    def draw(self):
        surface = self.get_cairo_surface()
        ctx = cairo.Context(surface)

        ctx.set_operator(cairo.OPERATOR_SOURCE)
        ctx.rectangle(0,0,self.width,self.height)
        ctx.set_source_rgba(0,0,0,0)
        ctx.fill()

        ctx.set_operator(cairo.OPERATOR_OVER)
        rounded_rectangle(ctx,0,0,self.width,self.height,10)
        ctx.set_source_rgba(0,0,0,0.7)
        ctx.fill()

        icon = self.match_icon()
        if icon:

            ctx.save()
            ctx.translate(20,20)
            if icon.get_width() != self.icon_width:
                ctx.scale(self.icon_width/icon.get_width(),self.icon_width/icon.get_width())
            ctx.set_source_surface(icon,0,0)
            ctx.paint()
            ctx.restore()

        font = self.font
        tr = text_region.TextRegion(0,20,self.width,30,font=font)
        tr.set_one_line()
        tr.set_ellipsis()
        tr.set_alignment(2)
        tr.set_richtext(html.escape(self.data) + '<color 0x888888>' + html.escape(self.complete) + '</color>')
        tr.draw(self)


        self.flip()
示例#4
0
    def __init__(self, decorator):
        super(CalculatorWindow, self).__init__(self.base_width + decorator.width(), self.base_height + decorator.height(), title=app_name, icon="calculator", doublebuffer=True)
        self.move(100,100)
        self.decorator = decorator

        def add_string(button):
            self.add_string(button.text)

        def clear(button):
            self.clear_text()

        def calculate(button):
            self.calculate()

        self.buttons = [
            [Button("C",clear),      None,                   Button("(",add_string), Button(")",add_string)],
            [Button("7",add_string), Button("8",add_string), Button("9",add_string), Button("/",add_string)],
            [Button("4",add_string), Button("5",add_string), Button("6",add_string), Button("*",add_string)],
            [Button("1",add_string), Button("2",add_string), Button("3",add_string), Button("-",add_string)],
            [Button("0",add_string), Button(".",add_string), Button("=",calculate),  Button("+",add_string)],
        ]

        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/calculator.png",_description,"calculator")
        def help_browser(action):
            subprocess.Popen(["help-browser.py","calculator.trt"])
        menus = [
            ("File", [
                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(self)+5,self.decorator.top_height(self)+self.menubar.height,self.base_width-10,40)
        self.tr.set_font(toaru_fonts.Font(toaru_fonts.FONT_MONOSPACE,18))
        self.tr.set_text("")
        self.tr.set_alignment(1)
        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
示例#5
0
    def __init__(self):
        self.width = 140
        self.font = toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF_BOLD, 14, self.color)
        self.tr   = text_region.TextRegion(0,0,self.width-self.text_x_offset*2,PANEL_HEIGHT-self.text_y_offset,font=self.font)
        self.tr.set_text("Applications")

        self.reinit_menus()
示例#6
0
    def __init__(self, icon, name, action, data):
        self.name = name
        self.action = action
        self.data = data

        self.x = 0
        self.y = 0

        self.hilighted = False
        self.icon = get_icon(icon,self.icon_width)
        self.icon_hilight = cairo.ImageSurface(self.icon.get_format(),self.icon.get_width(),self.icon.get_height())
        tmp = cairo.Context(self.icon_hilight)
        tmp.set_operator(cairo.OPERATOR_SOURCE)
        tmp.set_source_surface(self.icon,0,0)
        tmp.paint()
        tmp.set_operator(cairo.OPERATOR_ATOP)
        tmp.rectangle(0,0,self.icon_hilight.get_width(),self.icon_hilight.get_height())
        tmp.set_source_rgba(0x8E/0xFF,0xD8/0xFF,1,0.3)
        tmp.paint()

        self.font = toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF, 13, 0xFFFFFFFF)
        self.font.set_shadow((0xFF000000, 2, 1, 1, 3.0))
        self.tr = text_region.TextRegion(0,0,self.width,15,font=self.font)
        self.tr.set_alignment(2)
        self.tr.set_text(self.name)
        self.tr.set_one_line()
示例#7
0
文件: dialog.py 项目: xmonader/ponyos
    def __init__(self, decorator, title, text, icon='help', buttons=DialogButtons.OKAY_CANCEL, callback=None, cancel_callback=None,window=None,cancel_label=True,close_is_cancel=True):
        super(DialogWindow, self).__init__(self.base_width + decorator.width(), self.base_height + decorator.height(), title=title, icon=icon, doublebuffer=True)

        if window:
            # Center window
            self.move(window.x+int((window.width-self.width)/2),window.y+int((window.height-self.height)/2))
        else:
            # Center screen
            self.move(int((yutani.yutani_ctx._ptr.contents.display_width-self.width)/2),int((yutani.yutani_ctx._ptr.contents.display_height-self.height)/2))
        self.decorator = decorator
        self.logo = get_icon(icon,48,'help')
        self.font = toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF, 13, 0xFF000000)
        self.tr = text_region.TextRegion(0,0,self.base_width-60,self.base_height-self.text_offset,font=self.font)
        self.tr.set_richtext(text)

        if cancel_label is not True:
            self.cancel_label = cancel_label

        self.button_ok = Button(self.okay_label,self.ok_click)
        self.button_cancel = Button(self.cancel_label,self.cancel_click)
        self.buttons = [self.button_ok]
        if self.cancel_label:
            self.buttons.append(self.button_cancel)

        self.close_is_cancel = close_is_cancel

        self.hover_widget = None
        self.down_button = None

        self.callback = callback
        self.cancel_callback = cancel_callback
        self.draw()
示例#8
0
    def update_text_buffer(self):
        if self.size_changed or not self.text_buffer:
            if self.text_buffer:
                self.text_buffer.destroy()
            self.text_buffer = yutani.GraphicsBuffer(
                self.width - self.decorator.width(), self.height -
                self.decorator.height() + 80 - self.menubar.height)
        surface = self.text_buffer.get_cairo_surface()
        ctx = cairo.Context(surface)
        ctx.rectangle(0, 0, surface.get_width(), surface.get_height())
        ctx.set_source_rgb(1, 1, 1)
        ctx.fill()

        pad = 10
        if not self.tr:
            self.tr = text_region.TextRegion(pad, 0,
                                             surface.get_width() - pad * 2,
                                             surface.get_height())
            self.tr.set_line_height(18)
            self.tr.base_dir = '/usr/share/help/'
            self.tr.set_richtext(self.get_document_text())
        elif self.size_changed:
            self.size_changed = False
            self.tr.resize(surface.get_width() - pad * 2,
                           surface.get_height() - pad * 2)

        self.tr.scroll = self.scroll_offset
        self.tr.draw(self.text_buffer)
示例#9
0
    def __init__(self):
        _w = yutani.yutani_ctx._ptr.contents.display_width
        _h = yutani.yutani_ctx._ptr.contents.display_height

        self.logo = cairo.ImageSurface.create_from_png(
            '/usr/share/logo_login.png')

        super(InputWindow, self).__init__(272,
                                          self.logo.get_height() + 110 + 50,
                                          doublebuffer=True)
        self.update_position(_w, _h)

        self.username = InputBox(placeholder="Username", width=180)
        self.password = InputBox(password=True,
                                 placeholder="Password",
                                 width=180)
        self.focused_widget = None

        self.username.tab_handler = self.focus_password
        self.password.tab_handler = self.focus_username

        self.username.submit = self.password_or_go
        self.password.submit = self.go

        self.error_font = toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF, 11,
                                           0xFFFF0000)
        self.error_font.set_shadow((0xFF000000, 2, 0, 0, 3.0))
        self.error_tr = text_region.TextRegion(0,
                                               0,
                                               self.width,
                                               20,
                                               font=self.error_font)
        self.error_tr.set_alignment(2)

        self.error = None
示例#10
0
    def draw(self, cr, x, y, width):
        self.x = x
        self.y = y
        self.width = width

        cr.save()
        cr.set_source_rgb(59 / 255, 59 / 255, 59 / 255)
        cr.rectangle(0, 0, width, self.height)
        cr.fill()
        cr.restore()

        menus = self.window.menus

        x_, y_ = cr.user_to_device(x, y)
        offset = 0
        for e in self.entries:
            title, _ = e
            w = self.font.width(title) + 10
            if self.active_menu in menus.values() and e == self.active_entry:
                cr.rectangle(offset + 2, 0, w + 2, self.height)
                cr.set_source(self.gradient)
                cr.fill()
            tr = text_region.TextRegion(
                int(x_) + 8 + offset,
                int(y_) + 2, w, self.height, self.font)
            tr.set_one_line()
            tr.set_text(title)
            tr.draw(self.window)
            offset += w
示例#11
0
 def __init__(self, decorator, title, icon):
     super(ProgressBarWindow, self).__init__(self.base_width + decorator.width(), self.base_height + decorator.height(), title=title, icon=icon, doublebuffer=True)
     self.move(int((yutani.yutani_ctx._ptr.contents.display_width-self.width)/2),int((yutani.yutani_ctx._ptr.contents.display_height-self.height)/2))
     self.decorator = decorator
     self.font = toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF, 13, 0xFF000000)
     self.tr = text_region.TextRegion(0,0,self.base_width-30,self.base_height-self.text_offset,font=self.font)
     self.tr.set_alignment(2)
     self.progress = 0
     self.total = 1
示例#12
0
文件: panel.py 项目: florinp/toaruos
    def draw(self, window, offset, remaining, ctx):
        global windows
        if not len(windows):
            return
        self.window = window
        self.offset = offset
        available_width = remaining - offset
        self.unit_width = min(int(available_width / len(windows)), 180)
        icon_width = self.icon_width
        if self.unit_width < 56:
            self.unit_width = 32
            icon_width = 24

        i = 0
        for w in windows:
            if w.flags & 1:
                ctx.set_source(self.gradient)
                ctx.rectangle(offset + 4, 0, self.unit_width - 4, PANEL_HEIGHT)
                ctx.fill()
            icon = get_icon(w.icon, icon_width)

            ctx.save()
            ctx.translate(offset + self.unit_width - icon_width - 2, 0)
            ctx.rectangle(0, 0, icon_width + 4, PANEL_HEIGHT - 2)
            ctx.clip()
            if icon.get_width() != icon_width:
                ctx.scale(icon_width / icon.get_width(),
                          icon_width / icon.get_width())
            ctx.set_source_surface(icon, 0, 0)
            if self.unit_width < 48:
                ctx.paint()
            else:
                ctx.paint_with_alpha(0.7)
            if i < len(windows) - 1:
                ctx.rectangle(icon_width + 3, 0, 1, PANEL_HEIGHT)
                ctx.set_source(self.divider)
                ctx.fill()
            ctx.restore()

            offset_left = 4
            if self.unit_width > 48:
                font = self.font
                if self.hovered == w.wid:
                    font = self.font_hilight
                tr = text_region.TextRegion(offset + 4 + offset_left,
                                            self.text_y_offset,
                                            self.unit_width - 6 - offset_left,
                                            PANEL_HEIGHT - self.text_y_offset,
                                            font=font)
                tr.set_one_line()
                tr.set_ellipsis()
                tr.set_text(w.name)
                tr.draw(window)

            offset += self.unit_width
            i += 1
示例#13
0
    def draw(self, window, ctx, x, y, w, h):
        self.x, self.y, self.width, self.height = x, y, w, h
        draw_button(ctx, x, y, w, h, self.hilight)

        x_, y_ = ctx.user_to_device(x, y)
        tr = text_region.TextRegion(int(x_), int(y_), w, h)
        tr.set_alignment(2)
        tr.set_valignment(2)
        tr.set_text(self.text)
        tr.draw(window)
示例#14
0
文件: panel.py 项目: florinp/toaruos
 def __init__(self):
     self.font = toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF,
                                  self.font_size, self.color)
     self.tr = text_region.TextRegion(0,
                                      0,
                                      self.width,
                                      PANEL_HEIGHT - self.text_y_offset,
                                      font=self.font)
     self.tr.set_alignment(self.alignment)
     self.offset = 0
示例#15
0
    def update_text_buffer(self):
        if not self.tr:
            self.tr = text_region.TextRegion(0, 0, 100, 100)
            self.tr.set_line_height(18)
            self.tr.base_dir = '/usr/share/help/'
            self.tr.set_richtext(self.get_document_text(), html=self.is_html())
            self.text_scroller.tr = self.tr

        if self.size_changed:
            self.text_scroller.update(self.width - self.decorator.width())
示例#16
0
 def __init__(self):
     self.font = toaru_fonts.Font(toaru_fonts.FONT_MONOSPACE,13,0xFF000000)
     self.tr = text_region.TextRegion(0,0,self.width-20,self.height,font=self.font)
     self.calendar = calendar.TextCalendar(calendar.SUNDAY)
     t = time.localtime(current_time)
     self.tr.set_line_height(17)
     self.tr.set_text(self.calendar.formatmonth(t.tm_year,t.tm_mon))
     for tu in self.tr.text_units:
         if tu.string == str(t.tm_mday):
             tu.set_font(toaru_fonts.Font(toaru_fonts.FONT_MONOSPACE_BOLD,13,0xFF000000))
             break
示例#17
0
 def __init__(self, path, window):
     self.path = path
     self.name = os.path.basename(path)
     self.stat = os.stat(path)
     self.hilight = False
     self.window = window
     self.tr = text_region.TextRegion(0, 0, 100, 20)
     self.tr.set_alignment(2)
     self.tr.set_ellipsis()
     self.tr.set_text(self.name)
     self.x = 0
     self.y = 0
示例#18
0
    def redraw_buf(self, clips=None):
        if self.buf:
            self.buf.destroy()
        w = self.width - self.decorator.width()
        self.buf = yutani.GraphicsBuffer(w, len(self.packages) * 24)

        surface = self.buf.get_cairo_surface()
        ctx = cairo.Context(surface)

        if clips:
            for clip in clips:
                ctx.rectangle(clip.x, clip.y, w, 24)
            ctx.clip()

        ctx.rectangle(0, 0, surface.get_width(), surface.get_height())
        ctx.set_source_rgb(1, 1, 1)
        ctx.fill()

        offset_y = 0

        for f in self.packages:
            f.y = offset_y
            if not clips or f in clips:
                tr = text_region.TextRegion(4, offset_y + 4, w - 4, 20)
                if f.hilight:
                    gradient = cairo.LinearGradient(0, 0, 0, 18)
                    gradient.add_color_stop_rgba(0.0, *hilight_gradient_top,
                                                 1.0)
                    gradient.add_color_stop_rgba(1.0, *hilight_gradient_bottom,
                                                 1.0)
                    ctx.rectangle(0, offset_y + 4, w, 1)
                    ctx.set_source_rgb(*hilight_border_top)
                    ctx.fill()
                    ctx.rectangle(0, offset_y + 4 + 20 - 1, w, 1)
                    ctx.set_source_rgb(*hilight_border_bottom)
                    ctx.fill()
                    ctx.save()
                    ctx.translate(0, offset_y + 4 + 1)
                    ctx.rectangle(0, 0, w, 20 - 2)
                    ctx.set_source(gradient)
                    ctx.fill()
                    ctx.restore()
                    tr.font.font_color = 0xFFFFFFFF
                else:
                    ctx.rectangle(0, offset_y + 4, w, 20)
                    ctx.set_source_rgb(1, 1, 1)
                    ctx.fill()
                    tr.font.font_color = 0xFF000000
                tr.set_richtext(f.text)
                tr.set_one_line()
                tr.set_ellipsis()
                tr.draw(self.buf)
            offset_y += 24
示例#19
0
 def __init__(self, decorator, title, logo, text, icon="star",on_close=None):
     super(AboutAppletWindow, self).__init__(self.base_width + decorator.width(), self.base_height + decorator.height(), title=title, flags=yutani.WindowFlag.FLAG_DISALLOW_RESIZE, icon=icon, doublebuffer=True)
     self.move(int((yutani.yutani_ctx._ptr.contents.display_width-self.width)/2),int((yutani.yutani_ctx._ptr.contents.display_height-self.height)/2))
     self.decorator = decorator
     if logo.endswith('.png'):
         logo = logo.replace('.png','.bmp') # Hope that works
     self.logo = yutani.Sprite.from_file(logo).get_cairo_surface()
     self.font = toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF, 13, 0xFF000000)
     self.tr = text_region.TextRegion(0,0,self.base_width-30,self.base_height-self.text_offset,font=self.font)
     self.tr.set_alignment(2)
     self.tr.set_richtext(text)
     self.on_close = on_close
     self.draw()
示例#20
0
文件: mines.py 项目: florinp/toaruos
 def __init__(self,action,r,c,is_mine,neighbor_mines):
     super(MineButton,self).__init__("",action)
     self.row = r
     self.col = c
     self.tr = text_region.TextRegion(0,0,10,10)
     self.is_mine = is_mine
     self.tr.set_text("")
     self.tr.set_alignment(2)
     self.tr.set_valignment(2)
     self.width = None
     self.revealed = False
     self.mines = neighbor_mines
     self.flagged = False
示例#21
0
文件: dialog.py 项目: xmonader/ponyos
 def __init__(self, path,name=None):
     if not name:
         self.name = os.path.basename(path)
     else:
         self.name = name
     self.path = os.path.normpath(path)
     self.stat = os.stat(path)
     self.y = 0
     self.x = 0
     self.hilight = False
     self.tr = text_region.TextRegion(0,0,400,20)
     self.tr.set_one_line()
     self.tr.set_ellipsis()
     self.tr.set_text(self.name)
示例#22
0
 def __init__(self, decorator, title="Welcome to PonyOS!", icon="star"):
     flags = yutani.WindowFlag.FLAG_DISALLOW_DRAG | yutani.WindowFlag.FLAG_DISALLOW_RESIZE
     super(WizardWindow, self).__init__(640,480, title=title, icon=icon, doublebuffer=True, flags=flags)
     self.center()
     self.decorator = decorator
     hpad = 100
     self.page = 0
     self.button = Button("Next",self.button_click)
     self.hover_widget = None
     self.down_button = None
     self.tr = text_region.TextRegion(hpad+self.decorator.left_width(),10+self.decorator.top_height(),self.width-self.decorator.width()-hpad*2,self.height-self.decorator.height()-20)
     self.tr.line_height = 15
     self.tr.set_alignment(2)
     self.load_page()
示例#23
0
    def __init__(self,
                 decorator,
                 title,
                 icon,
                 text="",
                 text_changed=None,
                 callback=None,
                 window=None):
        super(TextInputWindow,
              self).__init__(self.base_width + decorator.width(),
                             self.base_height + decorator.height(),
                             title=title,
                             icon=icon,
                             doublebuffer=True)
        if window:
            # Center window
            self.move(window.x + int((window.width - self.width) / 2),
                      window.y + int((window.height - self.height) / 2))
        else:
            # Center screen
            self.move(
                int((yutani.yutani_ctx._ptr.contents.display_width -
                     self.width) / 2),
                int((yutani.yutani_ctx._ptr.contents.display_height -
                     self.height) / 2))
        self.decorator = decorator
        self.font = toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF, 13,
                                     0xFF000000)
        self.tr = text_region.TextRegion(0,
                                         0,
                                         self.base_width - 30,
                                         self.base_height - self.text_offset,
                                         font=self.font)
        self.tr.set_one_line()
        self.tr.break_all = True
        self.tr.set_text(text)
        self.is_focused = False
        self.cursor_index = len(self.tr.text)
        self.cursor_x = self.tr.get_offset_at_index(self.cursor_index)[1][1]
        self.text_changed = text_changed
        self.callback = callback
        self.ctrl_chars = [' ', '/']

        self.button_ok = Button(self.okay_label, self.ok_click)
        self.button_cancel = Button(self.cancel_label, self.cancel_click)
        self.buttons = [self.button_ok, self.button_cancel]

        self.hover_widget = None
        self.down_button = None
示例#24
0
    def __init__(self):
        w = yutani.yutani_ctx._ptr.contents.display_width
        h = yutani.yutani_ctx._ptr.contents.display_height

        super(LoginWindow, self).__init__(w, h, doublebuffer=True)
        self.move(0, 0)
        self.set_stack(yutani.WindowStackOrder.ZORDER_BOTTOM)

        self.font = toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF, 11,
                                     0xFFFFFFFF)
        self.font.set_shadow((0xFF000000, 2, 1, 1, 3.0))
        self.tr = text_region.TextRegion(0, 0, 200, 30, font=self.font)
        self.tr.set_text(f"ToaruOS {os.uname().release}")

        self.load_wallpaper()
示例#25
0
    def __init__(self, title, icon, action=None, data=None, rich=False):
        self.title = title
        self.icon = get_icon(icon,16) if icon else None
        self.action = action
        self.data = data
        self.font = toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF,13,0xFF000000)
        self.font_hilight = toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF,13,0xFFFFFFFF)
        self.rich = rich

        self.width = self.font.width(self.title) + self.right_margin # Arbitrary bit of extra space.
        # Fit width to hold title?
        self.tr = text_region.TextRegion(0,0,self.width - 22, 20, self.font)
        self.update_text()
        self.hilight = False
        self.window = None
        self.gradient = cairo.LinearGradient(0,0,0,self.height-2)
        self.gradient.add_color_stop_rgba(0.0,*self.hilight_gradient_top,1.0)
        self.gradient.add_color_stop_rgba(1.0,*self.hilight_gradient_bottom,1.0)
示例#26
0
    def draw(self, window, ctx, x, y, w, h):
        self.x, self.y, self.width, self.height = x, y, w, h

        if self.hilight == 0:
            return

        ctx.rectangle(x, y, w, h)
        if self.hilight == 1:
            ctx.set_source_rgba(0, 0, 0, 0.7)
        elif self.hilight == 2:
            ctx.set_source_rgba(1, 1, 1, 0.7)
        ctx.fill()

        x_, y_ = ctx.user_to_device(x, y)
        font = toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF, 18, 0xFFFFFFFF)
        tr = text_region.TextRegion(int(x_), int(y_), w, h, font=font)
        tr.set_alignment(2)
        tr.set_valignment(2)
        tr.set_text(self.text)
        tr.draw(window)
示例#27
0
    def draw(self):
        surface = self.get_cairo_surface()
        ctx = cairo.Context(surface)

        ctx.set_operator(cairo.OPERATOR_SOURCE)
        ctx.rectangle(0,0,self.width,self.height)
        ctx.set_source_rgba(0,0,0,0)
        ctx.fill()

        ctx.set_operator(cairo.OPERATOR_OVER)
        rounded_rectangle(ctx,0,0,self.width,self.height,10)
        ctx.set_source_rgba(0,0,0,0.7)
        ctx.fill()

        if new_focused >= 0 and new_focused < len(windows_zorder):
            w = windows_zorder[new_focused]

            icon = get_icon(w.icon,self.icon_width)

            ctx.save()
            ctx.translate(int((self.width-self.icon_width)/2),20)
            if icon.get_width() != self.icon_width:
                ctx.scale(self.icon_width/icon.get_width(),self.icon_width/icon.get_width())
            ctx.set_source_surface(icon,0,0)
            ctx.paint()
            ctx.restore()

            font = self.font
            tr = text_region.TextRegion(0,70,self.width,30,font=font)
            tr.set_one_line()
            tr.set_ellipsis()
            tr.set_alignment(2)
            tr.set_text(w.name)
            tr.draw(self)


        self.flip()
示例#28
0
    # Initialize the decoration library.
    d = yutani.Decor()

    # Create a new window.
    w = yutani.Window(600 + d.width(),
                      150 + d.height(),
                      title="Text Layout Demo",
                      doublebuffer=True)

    # We can set window shaping...
    w.update_shape(yutani.WindowShape.THRESHOLD_HALF)

    pad = 4

    tr = text_region.TextRegion(d.left_width() + pad,
                                d.top_height() + pad,
                                w.width - d.width() - pad * 2,
                                w.height - d.height() - pad * 2)
    tr.set_line_height(20)
    bold = toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF_BOLD, 13)
    blue = toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF, 13, 0xFF0000FF)
    #with open('/usr/share/licenses') as f:
    #    tr.set_text(f.read())
    #    for unit in tr.text_units:
    #        if unit.string.startswith("http://") or unit.string.startswith("https://"):
    #            unit.set_font(blue)
    #        if unit.string == "Software":
    #            unit.set_font(bold)
    #    tr.reflow()
    #tr.set_text(ipsum)
    if len(sys.argv) > 1:
        with open(sys.argv[1]) as f:
示例#29
0
    def redraw_buf(self,clips=None):
        if self.buf:
            self.buf.destroy()
        w = self.width - self.decorator.width()
        self.buf = yutani.GraphicsBuffer(w,len(self.packages)*package_height)

        surface = self.buf.get_cairo_surface()
        ctx = cairo.Context(surface)

        if clips:
            for clip in clips:
                ctx.rectangle(clip.x,clip.y,w,package_height)
            ctx.clip()

        ctx.rectangle(0,0,surface.get_width(),surface.get_height())
        ctx.set_source_rgb(1,1,1)
        ctx.fill()

        offset_y = 0

        button = Button('Install', None)

        for f in self.packages:
            f.y = offset_y
            if not clips or f in clips:
                tr = text_region.TextRegion(64,offset_y+4,w-64 - 120,package_height-4)
                tr.line_height = 19
                if False and f.hilight:
                    gradient = cairo.LinearGradient(0,0,0,18)
                    gradient.add_color_stop_rgba(0.0,*hilight_gradient_top,1.0)
                    gradient.add_color_stop_rgba(1.0,*hilight_gradient_bottom,1.0)
                    ctx.rectangle(0,offset_y+4,w,1)
                    ctx.set_source_rgb(*hilight_border_top)
                    ctx.fill()
                    ctx.rectangle(0,offset_y+package_height-1,w,1)
                    ctx.set_source_rgb(*hilight_border_bottom)
                    ctx.fill()
                    ctx.save()
                    ctx.translate(0,offset_y+4+1)
                    ctx.rectangle(0,0,w,package_height-6)
                    ctx.set_source(gradient)
                    ctx.fill()
                    ctx.restore()
                    tr.font.font_color = 0xFFFFFFFF
                else:
                    ctx.rectangle(0,offset_y+4,w,package_height-4)
                    ctx.set_source_rgb(1,1,1)
                    ctx.fill()
                    tr.font.font_color = 0xFF000000
                if f.installed:
                    package_icon = get_icon(f.icon if f.icon else 'package',48,'package')
                else:
                    if f.hilight:
                        button.hilight = f.hilight
                    else:
                        button.hilight = 0
                    button.draw(self.buf,ctx,w-110,offset_y+11,100,32)
                    package_icon = get_icon('package-uninstalled',48)
                ctx.set_source_surface(package_icon,8,11+offset_y)
                ctx.paint()
                tr.set_richtext(f.text)
                tr.set_ellipsis()
                tr.set_max_lines(3)
                tr.draw(self.buf)
            offset_y += package_height
示例#30
0
文件: mines.py 项目: florinp/toaruos
    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))