示例#1
0
 def __init__(self, width=None, height=None):
     if not width:
         width = gdk.screen_width()
     self.width = width
     if not height:
         height = gdk.screen_height()
         self.height = height
示例#2
0
    def setupUi(self):
        self.MainWindow.setObjectName("MainWindow")
        self.MainWindow.resize(screen_width(), screen_height() - 10)
        self.MainWindow.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.centralwidget = QtWidgets.QWidget(self.MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.pose_y_value = self.MainWindow.size().height(
        ) / 2 - self.image_height / 2
        self.pose_x_value = self.MainWindow.size().width(
        ) / 2 - self.image_width / 2
        self.label.setGeometry(
            QtCore.QRect(self.pose_x_value, self.pose_y_value,
                         self.image_width, self.image_height))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.label.sizePolicy().hasHeightForWidth())
        self.label.setSizePolicy(sizePolicy)
        self.label.setStyleSheet(
            "border-image: url(/home/roombot/ros_workspaces/behavior_ws/src/roombot_gui/ui/img/eyes.svg) 0 0 0 0 stretch stretch;\n"
        )
        self.label.setFrameShape(QtWidgets.QFrame.Box)
        self.label.setText("")
        self.label.setObjectName("label")
        self.MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi()
        QtCore.QMetaObject.connectSlotsByName(self.MainWindow)
示例#3
0
    def screen_dpi(self):
        if not self._screen_dpi:
            dpi_x = screen_width() / (screen_width_mm() / 25.4)
            dpi_y = screen_height() / (screen_height_mm() / 25.4)

            self._screen_dpi = (dpi_x + dpi_y) / 2.0

        return self._screen_dpi
示例#4
0
	def screen_dpi(self):
		if not self._screen_dpi:
			dpi_x = screen_width() / (screen_width_mm() / 25.4)
			dpi_y = screen_height() / (screen_height_mm() / 25.4)

			self._screen_dpi = (dpi_x + dpi_y) / 2.0

		return self._screen_dpi
示例#5
0
 def __init__(self, app, top, progress=None):
     self.progress = progress
     self._cb_max = gdk.screen_height() / 24
     # create menus
     menubar = self.createMenubar()
     self.top.table.attach(menubar, 0, 3, 0, 1, gtk.EXPAND | gtk.FILL, 0, 0,
                           0)
     menubar.show()
示例#6
0
    def show(self, text, x, y):
        """
        Show the window with the given text, its top-left corner at x-y.
        Decide on initial size.
        """
        # The initial size is the minimum of:
        # * N_COLS*N_ROWS
        # * Whatever fits into the screen
        # * The actual content

        tv = self.textview
        vs = self.vscrollbar
        win = self.window

        text = text.replace('\0', '')  # Fixes bug #611513

        win.hide()
        tv.get_buffer().set_text(text)

        f_width = self.char_width * N_COLS
        f_height = self.char_height * N_ROWS

        s_width = gdk.screen_width() - x
        s_height = gdk.screen_height() - y

        # Get the size of the contents
        layout = tv.create_pango_layout(text)
        p_width, p_height = layout.get_size()
        c_width = pango.PIXELS(p_width)
        c_height = pango.PIXELS(p_height)
        del layout

        add_width = vs.size_request()[0] + 5
        width = int(min(f_width, s_width, c_width) + add_width)
        height = int(min(f_height, s_height, c_height))

        # Don't show the vertical scrollbar if the height is short enough.
        vs.props.visible = (height > vs.size_request()[1])

        win.resize(width, height)

        win.move(x, y)

        self.hscrollbar.props.adjustment.props.value = 0
        self.vscrollbar.props.adjustment.props.value = 0

        self.sourceview.handler_unblock(self.keypress_handler)
        self.keypress_handler_blocked = False

        win.show()

        # This has to be done after the textview was displayed
        if not self.was_displayed:
            self.was_displayed = True
            hand = gdk.Cursor(gdk.HAND1)
            tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(hand)
            br_corner = gdk.Cursor(gdk.BOTTOM_RIGHT_CORNER)
            self.resizegrip.window.set_cursor(br_corner)
示例#7
0
    def show(self, text, x, y):
        """
        Show the window with the given text, its top-left corner at x-y.
        Decide on initial size.
        """
        # The initial size is the minimum of:
        # * N_COLS*N_ROWS
        # * Whatever fits into the screen
        # * The actual content

        tv = self.textview
        vs = self.vscrollbar
        win = self.window

        text = text.replace("\0", "")  # Fixes bug #611513

        win.hide()
        tv.get_buffer().set_text(text)

        f_width = self.char_width * N_COLS
        f_height = self.char_height * N_ROWS

        s_width = gdk.screen_width() - x
        s_height = gdk.screen_height() - y

        # Get the size of the contents
        layout = tv.create_pango_layout(text)
        p_width, p_height = layout.get_size()
        c_width = pango.PIXELS(p_width)
        c_height = pango.PIXELS(p_height)
        del layout

        add_width = vs.size_request()[0] + 5
        width = int(min(f_width, s_width, c_width) + add_width)
        height = int(min(f_height, s_height, c_height))

        # Don't show the vertical scrollbar if the height is short enough.
        vs.props.visible = height > vs.size_request()[1]

        win.resize(width, height)

        win.move(x, y)

        self.hscrollbar.props.adjustment.props.value = 0
        self.vscrollbar.props.adjustment.props.value = 0

        self.sourceview.handler_unblock(self.keypress_handler)
        self.keypress_handler_blocked = False

        win.show()

        # This has to be done after the textview was displayed
        if not self.was_displayed:
            self.was_displayed = True
            hand = gdk.Cursor(gdk.HAND1)
            tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(hand)
            br_corner = gdk.Cursor(gdk.BOTTOM_RIGHT_CORNER)
            self.resizegrip.get_window().set_cursor(br_corner)
示例#8
0
    def do_size_request(self, req):
        if self.is_vertical():
            req.height = gdk.screen_height()
            req.width = style.GRID_CELL_SIZE + style.LINE_WIDTH
        else:
            req.width = gdk.screen_width()
            req.height = style.GRID_CELL_SIZE + style.LINE_WIDTH

        self.get_child().size_request()
示例#9
0
    def do_size_request(self, req):
        if self.is_vertical():
            req.height = gdk.screen_height()
            req.width = style.GRID_CELL_SIZE + style.LINE_WIDTH
        else:
            req.width = gdk.screen_width()
            req.height = style.GRID_CELL_SIZE + style.LINE_WIDTH

        self.get_child().size_request()
示例#10
0
 def __init__(self, app, top, progress=None):
     self.progress = progress
     self._cb_max = gdk.screen_height()/24
     # create menus
     menubar = self.createMenubar()
     self.top.table.attach(menubar,
                           0, 3,                    0, 1,
                           gtk.EXPAND | gtk.FILL,   0,
                           0,                       0)
     menubar.show()
示例#11
0
 def __init__(self,
              style='standard',
              title="New Window",
              movable=1,
              closable=1,
              hidable=None,
              resizable=1,
              zoomable=1,
              **kwds):
     self._all_menus = []
     modal = style in _modal_styles
     if hidable is None:
         hidable = not modal
     self._resizable = resizable
     gtk_win = gtk.Window(gtk.WINDOW_TOPLEVEL)
     gtk_win.set_gravity(gdk.GRAVITY_STATIC)
     gtk_win.set_decorated(style <> 'fullscreen'
                           and (movable or closable or hidable or zoomable))
     gtk_win.set_resizable(resizable)
     gtk_win.set_modal(style in _modal_styles)
     gtk_content = gtk.Layout()
     gtk_content.show()
     if style in _dialog_styles:
         gtk_win.set_type_hint(gdk.WINDOW_TYPE_HINT_DIALOG)
         gtk_win.add(gtk_content)
     else:
         self._gtk_create_menubar()
         gtk_box = gtk.VBox()
         gtk_box.show()
         gtk_box.pack_start(self._gtk_menubar, expand=0, fill=0)
         gtk_box.pack_end(gtk_content, expand=1, fill=1)
         gtk_win.add(gtk_box)
     self._need_menubar_update = 1
     self._gtk_connect(gtk_win, 'configure-event',
                       self._gtk_configure_event)
     self._gtk_connect(gtk_win, 'key-press-event',
                       self._gtk_key_press_event)
     self._gtk_connect(gtk_win, 'delete-event', self._gtk_delete_event)
     GWindow.__init__(self,
                      _gtk_outer=gtk_win,
                      _gtk_inner=gtk_content,
                      _gtk_focus=gtk_content,
                      _gtk_input=gtk_content,
                      style=style,
                      title=title,
                      closable=closable)
     if style == 'fullscreen':
         size = (gdk.screen_width(), gdk.screen_height())
     else:
         size = (_default_width, _default_height)
     self.set_size(size)
     self.set(**kwds)
     self.become_target()
示例#12
0
def init():
    global size, width, height, padding, boundaries, passSize

    # Get containing terminal window and set it to maximised
    pid = os.getpid()
    win = _get_window_by_child_pid(pid)
    gdk_window_settings(win, maximized=True)
    time.sleep(0.1)
    available_size = (width, height) = console.getTerminalSize()

    try:
        # Check for screen resolution
        h = gdk.screen_height()

        # Select a set of sizes depending on the screen resolution
        if h > 1024:
            chosen_size = config.game_sizes_big[parser.args.board]
        elif h <= 1024 and h > 720:
            chosen_size = config.game_sizes_medium[parser.args.board]
        else:
            chosen_size = config.game_sizes_small[parser.args.board]
        passSize = parser.args.board
    except Exception:
        from kano.logging import logger
        logger.error("Can't find board size: {}".format(parser.args.board))
        __main__.exit()

    # Calculate width
    if chosen_size[0] > available_size[0] / 2:
        width = (available_size[0] / 2) - 3
    else:
        width = chosen_size[0]
    # Calculate height
    if chosen_size[1] > available_size[1]:
        height = available_size[1]
    else:
        height = chosen_size[1]

    size = (width, height)

    padding_x = int(math.floor(available_size[0] - width) / 4)
    padding_y = int(math.floor(available_size[1] - height) / 2)

    padding = (padding_y, padding_x, padding_y, padding_x)

    boundaries = {
        "bottom": int(math.floor(height / 2)),
        "left": int(math.floor(-width / 2)),
        "right": int(math.floor(width / 2)),
        "top": int(math.floor(-height / 2)),
    }
示例#13
0
    def __init__(self, media_view, controls_hbox):
        self._media_view = media_view
        self._controls_hbox = controls_hbox
        self._show_title = False
        self._controls_hbox_height = 0
        super(RecordContainer, self).__init__()

        for widget in (self._media_view, self._controls_hbox):
            if widget.flags() & gtk.REALIZED:
                widget.set_parent_window(self.window)

            widget.set_parent(self)

        ar = gdk.screen_width() * 100 / gdk.screen_height()
        self._ar_legacy = ar < 134
示例#14
0
def init():
    global size, width, height, padding, boundaries, chosen_theme, resolution

    # Get containing terminal window and set it to maximised
    pid = os.getpid()
    win = _get_window_by_child_pid(pid)
    gdk_window_settings(win, maximized=True)
    time.sleep(0.1)
    available_size = (width, height) = console.getTerminalSize()

     # Check for screen resolution
    resolution = gdk.screen_height()

    # Select a set of sizes depending on the screen resolution
    if resolution > 768:
        chosen_size = (20, 15)
    else:
        chosen_size = (10, 5)

    # Calculate width
    if chosen_size[0] > available_size[0] / 2:
        width = available_size[0] / 2
    else:
        width = chosen_size[0]
    # Calculate height
    if chosen_size[1] > available_size[1]:
        height = available_size[1]
    else:
        height = chosen_size[1]

    size = (width, height)

    padding_x = int(math.floor(available_size[0] - width) / 4)
    padding_y = int(math.floor(available_size[1] - height) / 2)

    padding = (padding_y, padding_x, padding_y, padding_x)

    boundaries = {
        "bottom": int(math.floor(height / 2)),
        "left": int(math.floor(-width / 2)),
        "right": int(math.floor(width / 2)),
        "top": int(math.floor(-height / 2)),
    }
示例#15
0
    def __init__(self, name):
        self.name = name

        self.fullscreen = 0
        self.cats = {}
        self.ext = {}
        self.img_file = {}
        self.img_menu = {}
        
        self.image_bg = 'images/bg.jpg'
        
        if self.fullscreen:
            self.width = gdk.screen_width()
            self.height = gdk.screen_height()
        else:
            self.width = 1280
            self.height = 720
        
        self.browse_maxline = 11

        self.cmd_video = 'mplayer'
        self.cmd_video_opt = '-ao alsa -vo x11 -nojoystick -nolirc -quiet -zoom'

        self.cats['PICTURES'] = '/mnt/data/images/wallpaper'
        self.ext['PICTURES'] = ('png', 'jpg', 'jpeg', 'gif', 'svg', ' bmp')
        self.img_file['PICTURES'] = 'images/image-x-generic.svg'
        self.img_menu['PICTURES'] = 'images/folder-pictures.svg'
        
        self.cats['VIDEO'] = '/mnt/data/video'
        self.ext['VIDEO'] = ('avi', 'mpg', 'mpeg', 'mov', 'divx', 'wmv', 'vob',
                             'flv', '3gp', 'mp4', 'webm', 'ogv')
        self.img_file['VIDEO'] = 'images/video-x-generic.svg'
        self.img_menu['VIDEO'] = 'images/folder-videos.svg'
        
        
        self.cats['MUSIC'] = '/mnt/data/musique'
        self.ext['MUSIC'] = ('mp3', 'ogg', 'wav', 'wma')
        self.img_file['MUSIC'] = 'images/audio-x-generic.svg'
        self.img_menu['MUSIC'] = 'images/folder-music.svg'

        self.img_menu['PROGRAMS'] = 'images/text-x-python.svg'
        self.img_menu['SYSTEM'] = 'images/applications-system.svg'
示例#16
0
    def __init__(self, name):
        self.name = name

        self.fullscreen = 0
        self.cats = {}
        self.ext = {}
        self.img_file = {}
        self.img_menu = {}

        self.image_bg = 'images/bg.jpg'

        if self.fullscreen:
            self.width = gdk.screen_width()
            self.height = gdk.screen_height()
        else:
            self.width = 1280
            self.height = 720

        self.browse_maxline = 11

        self.cmd_video = 'mplayer'
        self.cmd_video_opt = '-ao alsa -vo x11 -nojoystick -nolirc -quiet -zoom'

        self.cats['PICTURES'] = '/mnt/data/images/wallpaper'
        self.ext['PICTURES'] = ('png', 'jpg', 'jpeg', 'gif', 'svg', ' bmp')
        self.img_file['PICTURES'] = 'images/image-x-generic.svg'
        self.img_menu['PICTURES'] = 'images/folder-pictures.svg'

        self.cats['VIDEO'] = '/mnt/data/video'
        self.ext['VIDEO'] = ('avi', 'mpg', 'mpeg', 'mov', 'divx', 'wmv', 'vob',
                             'flv', '3gp', 'mp4', 'webm', 'ogv')
        self.img_file['VIDEO'] = 'images/video-x-generic.svg'
        self.img_menu['VIDEO'] = 'images/folder-videos.svg'

        self.cats['MUSIC'] = '/mnt/data/musique'
        self.ext['MUSIC'] = ('mp3', 'ogg', 'wav', 'wma')
        self.img_file['MUSIC'] = 'images/audio-x-generic.svg'
        self.img_menu['MUSIC'] = 'images/folder-music.svg'

        self.img_menu['PROGRAMS'] = 'images/text-x-python.svg'
        self.img_menu['SYSTEM'] = 'images/applications-system.svg'
示例#17
0
 def __init__(self, style = 'standard', title = "New Window",
         movable = 1, closable = 1, hidable = None, resizable = 1,
         zoomable = 1, **kwds):
     self._all_menus = []
     modal = style in _modal_styles
     if hidable is None:
         hidable = not modal
     self._resizable = resizable
     gtk_win = gtk.Window(gtk.WINDOW_TOPLEVEL)
     gtk_win.set_gravity(gdk.GRAVITY_STATIC)
     gtk_win.set_decorated(style <> 'fullscreen'
         and (movable or closable or hidable or zoomable))
     gtk_win.set_resizable(resizable)
     gtk_win.set_modal(style in _modal_styles)
     gtk_content = gtk.Layout()
     gtk_content.show()
     if style in _dialog_styles:
         gtk_win.set_type_hint(gdk.WINDOW_TYPE_HINT_DIALOG)
         gtk_win.add(gtk_content)
     else:
         self._gtk_create_menubar()
         gtk_box = gtk.VBox()
         gtk_box.show()
         gtk_box.pack_start(self._gtk_menubar, expand = 0, fill = 0)
         gtk_box.pack_end(gtk_content, expand = 1, fill = 1)
         gtk_win.add(gtk_box)
     self._need_menubar_update = 1
     self._gtk_connect(gtk_win, 'configure-event', self._gtk_configure_event)
     self._gtk_connect(gtk_win, 'key-press-event', self._gtk_key_press_event)
     self._gtk_connect(gtk_win, 'delete-event', self._gtk_delete_event)
     GWindow.__init__(self, _gtk_outer = gtk_win, _gtk_inner = gtk_content, 
         _gtk_focus = gtk_content, _gtk_input = gtk_content,
         style = style, title = title, closable = closable)
     if style == 'fullscreen':
         size = (gdk.screen_width(), gdk.screen_height())
     else:
         size = (_default_width, _default_height)
     self.set_size(size)
     self.set(**kwds)
     self.become_target()
示例#18
0
def gdk_window_settings(win,
                        x=None,
                        y=None,
                        width=None,
                        height=None,
                        decoration=None,
                        maximized=False,
                        centered=False):
    '''
    Applies appeareance and position modifications to the Window identified by win    
    '''
    # Screen dimensions
    scr_width = gdk.screen_width()
    scr_height = gdk.screen_height() - BOTTOM_BAR_HEIGHT

    # Window dimensions and position
    old_x, old_y = win.get_root_origin()
    old_width, old_height = win.get_geometry()[2:4]

    # Sort out the decorations
    if decoration is not None:
        if decoration is False:
            # Resize if the window was decorated before
            if _is_decorated(win):
                dw, dh = _get_decoration_size(win)
                old_width += dw
                old_height += dh

                win.set_decorations(0)
                gdk.window_process_all_updates()
                gdk.flush()
        else:
            # Resize if the window was not decorated before
            if not _is_decorated(win):
                win.set_decorations(1)
                gdk.flush()

                dw, dh = _get_decoration_size(win)
                old_width -= dw
                old_height -= dh

    # Resizing is irrelevant when maximizing, so just return afterwards
    if maximized:
        win.maximize()
        gdk.window_process_all_updates()
        gdk.flush()
        return

    # Initialize the target values
    new_x, new_y, new_width, new_height = old_x, old_y, old_width, old_height

    # Window position
    if x is not None:
        if x <= 1:
            new_x = scr_width * x
        else:
            new_x = x

    if y is not None:
        if y <= 1:
            new_y = scr_height * y
        else:
            new_y = y

    # Window dimensions
    if width is not None:
        if width <= 1:
            new_width = scr_width * width
        else:
            new_width = width

        if decoration is True:
            new_width -= _get_decoration_size(win)[0]

    if height is not None:
        if height <= 1:
            new_height = scr_height * height
        else:
            new_height = height

        if decoration is True:
            new_height -= _get_decoration_size(win)[1]

    # Should the window be centered?
    if centered:
        dec_w, dec_h = _get_decoration_size(win)
        new_x = (scr_width - new_width - dec_w) / 2
        new_y = (scr_height - new_height - dec_h) / 2

    # Do all the resizing at once
    win.move_resize(int(new_x), int(new_y), int(new_width), int(new_height))
    gdk.window_process_all_updates()
    gdk.flush()
示例#19
0
def gdk_window_settings(win, x=None, y=None, width=None, height=None,
                        decoration=None, maximized=False, centered=False):
    '''
    Applies appeareance and position modifications to the Window identified by win    
    '''
    # Screen dimensions
    scr_width = gdk.screen_width()
    scr_height = gdk.screen_height() - BOTTOM_BAR_HEIGHT

    # Window dimensions and position
    old_x, old_y = win.get_root_origin()
    old_width, old_height = win.get_geometry()[2:4]

    # Sort out the decorations
    if decoration is not None:
        if decoration is False:
            # Resize if the window was decorated before
            if _is_decorated(win):
                dw, dh = _get_decoration_size(win)
                old_width += dw
                old_height += dh

                win.set_decorations(0)
                gdk.window_process_all_updates()
                gdk.flush()
        else:
            # Resize if the window was not decorated before
            if not _is_decorated(win):
                win.set_decorations(1)
                gdk.flush()

                dw, dh = _get_decoration_size(win)
                old_width -= dw
                old_height -= dh

    # Resizing is irrelevant when maximizing, so just return afterwards
    if maximized:
        win.maximize()
        gdk.window_process_all_updates()
        gdk.flush()
        return

    # Initialize the target values
    new_x, new_y, new_width, new_height = old_x, old_y, old_width, old_height

    # Window position
    if x is not None:
        if x <= 1:
            new_x = scr_width * x
        else:
            new_x = x

    if y is not None:
        if y <= 1:
            new_y = scr_height * y
        else:
            new_y = y

    # Window dimensions
    if width is not None:
        if width <= 1:
            new_width = scr_width * width
        else:
            new_width = width

        if decoration is True:
            new_width -= _get_decoration_size(win)[0]

    if height is not None:
        if height <= 1:
            new_height = scr_height * height
        else:
            new_height = height

        if decoration is True:
            new_height -= _get_decoration_size(win)[1]

    # Should the window be centered?
    if centered:
        dec_w, dec_h = _get_decoration_size(win)
        new_x = (scr_width - new_width - dec_w) / 2
        new_y = (scr_height - new_height - dec_h) / 2

    # Do all the resizing at once
    win.move_resize(int(new_x), int(new_y), int(new_width), int(new_height))
    gdk.window_process_all_updates()
    gdk.flush()
示例#20
0
 def _screen_rect(self):
     w = gdk.screen_width()
     h = gdk.screen_height()
     return (0, 0, w, h)
示例#21
0
    def __init__(self, w=None, h=None):
        self._w = w if w else gdk.screen_width()
        self._h = h if h else gdk.screen_height()

        self._window = gdk.get_default_root_window()
        self._pb = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, self._w, self._h)
示例#22
0
try:
    from gtk import gdk
    HEIGHT = gdk.screen_height() - 200
except:
    HEIGHT = 600
# game options/settings
TITLE = "Jumpy!"
WIDTH = 480
CENTERX = WIDTH / 2
SIZE = (WIDTH, HEIGHT)

TOT_PLATFORMS = int(HEIGHT / 100) - 1
FPS = 60
FONT_NAME = 'arial'
HS_FILE = "highscore.txt"
SPRITESHEET = "spritesheet_jumper.png"

# Player properties
PLAYER_ACC = 0.5
PLAYER_FRICTION = -0.12
PLAYER_GRAV = 0.8
PLAYER_JUMP = 20

# SUn properties
SUN_SPEED = 200
SUN_SIZE = int(WIDTH / 3)

# Coins properties
COIN_SPEED = 100
COINS_VALUE = {"gold": 5, "silver": 2, "bronze": 1}
COIN_SPAWN_PCT = 20
示例#23
0
 def winfo_screenheight(self):
     return gdk.screen_height()
示例#24
0
#!/usr/bin/env python

from gtk.gdk import screen_width, screen_height

from puush import screenshot


screenshot(0, 0, screen_width(), screen_height())
示例#25
0
 def _screen_rect(self):
     w = gdk.screen_width()
     h = gdk.screen_height()
     return (0, 0, w, h)
示例#26
0
 def _update_size(self):
     if self._position == gtk.POS_TOP or self._position == gtk.POS_BOTTOM:
         self.resize(gdk.screen_width(), self.size)
     else:
         self.resize(self.size, gdk.screen_height())
示例#27
0
def launch_cam():
    print 'launch'
    BLACK = 0, 0, 0
    GREEN = 0, 255, 0
    RED = 255, 0, 0

    if not os.getenv('SDL_FBDEV'):
        os.putenv('SDL_FBDEV', '/dev/fb1')

    if not os.getenv('SDL_VIDEODRIVER'):
        os.putenv('SDL_VIDEODRIVER', 'fbcon')

    # disables autofocus for Microsoft LifeCam
    os.system("uvcdynctrl --set='Focus, Auto' 0")

    screen_size = (gdk.screen_width(), gdk.screen_height())
    pygame.init()
    size = (640, 480)
    lcd = pygame.display.set_mode((0, 0))
    pygame.mouse.set_visible(False)
    lcd.fill(BLACK)
    pygame.display.update()

    pygame.camera.init()

    cam = pygame.camera.Camera('/dev/video0', size, 'RGB')

    cam.start()
    font_big = pygame.font.Font(None, 100)
    surf = pygame.Surface(size)

    sensor = DistanceSensor(echo=17, trigger=4, max_distance=5)
    colour = GREEN
    image_loc = (screen_size[0] / 2 - size[0] / 2, 0)  #top center

    while True:
        lcd.fill(BLACK)
        cam.get_image(surf)
        lcd.blit(surf, (image_loc[0], image_loc[1]))  #top and center
        cm = int(sensor.distance * 100)
        if cm < 30:
            colour = RED

            text_surface = font_big.render('STOP', True, colour)
            rect = text_surface.get_rect(center=(image_loc[0] + size[0] / 2,
                                                 image_loc[1] + size[1] / 2))
            lcd.blit(text_surface, rect)

        if cm < 120:
            pygame.draw.circle(
                lcd, colour,
                (image_loc[0] + size[0] / 2, image_loc[1] + size[1] / 2),
                (150 - cm), 5)

        if cm > 120:
            colour = GREEN

        text_surface = font_big.render('%dcm' % cm, True, colour)
        rect = text_surface.get_rect(center=(image_loc[0] + size[0] / 2,
                                             image_loc[1] + size[1] + 100))
        lcd.blit(text_surface, rect)

        pygame.display.update()

    return 0
示例#28
0
 def winfo_screenheight(self):
     return gdk.screen_height()
示例#29
0
def lqr_wpset(path):
	random.seed()
	w, h = gdk.screen_width(), gdk.screen_height()

	path_source, cache_path, cached = path, None, False
	if conf.cache_dir:
		cache_key = os.path.realpath(path), os.stat(path).st_mtime, w, h
		cache_path = os.path.join(conf.cache_dir, b'{0}.png'.format(
			re.sub( r'[\n=+/]', '',
				hashlib.sha256(b'\0'.join(map(bytes, cache_key)))\
					.digest().encode('base64') )[:20] ))
		if not conf.recache and os.path.exists(cache_path):
			path_source, cached = cache_path, True

	try: image = pdb.gimp_file_load(path_source, path_source)
	except RuntimeError: # failed to load - e.g. corrupted file
		cached, image = False, pdb.gimp_file_load(path, path)
	image_orig = image if not cached else pdb.gimp_file_load(path, path)

	layer_image = image.active_layer
	bak_colors = pdb.gimp_context_get_foreground(), pdb.gimp_context_get_background()
	diff_scale = False
	try:
		if not cached:
			image_crop(image, layer_image)

			## Check whether size/aspect difference isn't too great
			aspects = float(w)/h, float(image.width)/image.height
			diff_aspect = abs(aspects[0] - aspects[1])
			diff_size = [
				float(image.width)/w, float(image.height)/h,
				float(image.width * image.height) / (w*h) ]
			diff_size_chk = list((1.0 / getattr( conf,
				'max_size_diff_{}'.format(k) )) for k in ['w', 'h', 'area'])
			if diff_aspect > conf.max_aspect_diff\
					or any((v < chk) for v, chk in zip(diff_size, diff_size_chk)):
				if not conf.diff_w_scale_to_h\
						or diff_size[1] < diff_size_chk[1]\
						or aspects[0] - aspects[1] < 0: # aspect_diff < 0 = too wide image
					pdb.gimp_message(
						( 'Aspect diff: {:.2f} (max: {:.2f}), size'
							' diff (w/h/area): {:.2f}/{:.2f}/{:.2f} (min: {:.2f}/{:.2f}/{:.2f})' )\
						.format(diff_aspect, conf.max_aspect_diff, *(diff_size + diff_size_chk)) )
					pdb.gimp_message('WPS-ERR:next')
					return
				diff_scale, cache_path = True, None

		meta = image_meta(path, image_orig)

		if not cached:
			## Try to convert color profile to a default (known-good) one, to avoid libpng errors
			# Issue is "lcms: skipping conversion because profiles seem to be equal",
			#  followed by "libpng error: known incorrect sRGB profile" for e.g. IEC61966-2.1
			# See also: https://wiki.archlinux.org/index.php/Libpng_errors
			# Requires lcms support, I think. 0 = GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL
			try:
				pdb.plug_in_icc_profile_apply_rgb(image, 0, False) # lcms seem to skip that often
				pdb.plug_in_icc_profile_set_rgb(image) # force-unsets profile in case of lcms being lazy
			except gimp.error: pass # missing plugin

			if not diff_scale:
				image_rescale( image, layer_image, w, h,
					(diff_size[2] > conf.min_prescale_diff) and aspects )
			else:
				layer_image = image_rescale_to_part(image, layer_image, w, h, aspects[1])

			if cache_path:
				pdb.gimp_file_save(image, layer_image, cache_path, cache_path)

		## Do the random horizontal flip of the image layer, if specified
		if not diff_scale and conf.hflip_chance > 0 and random.random() < conf.hflip_chance:
			pdb.gimp_item_transform_flip_simple(
				layer_image, ORIENTATION_HORIZONTAL, True, 0 )

		layer_image = image_add_label(image, layer_image, meta)

		## Save image to a temporary file and set it as a bg, cleanup older images
		old_files = glob.glob(conf.result_path)
		prefix, suffix = conf.result_path.split('*', 1)
		tmp_dir, prefix = prefix.rsplit('/', 1)
		fd, tmp_file_path = mkstemp(prefix=prefix, suffix=suffix, dir=tmp_dir)
		pdb.gimp_file_save(image, layer_image, tmp_file_path, tmp_file_path)
		set_background(tmp_file_path)
		os.close(fd)
		for tmp_file_path in old_files:
			with open(tmp_file_path, 'wb'): pass # truncate files first, in case something holds open fd
			os.unlink(tmp_file_path)

	finally:
		## Restore gimp state
		pdb.gimp_image_delete(image)
		pdb.gimp_context_set_foreground(bak_colors[0])
		pdb.gimp_context_set_background(bak_colors[1])

	## Cache cleanup
	if conf.cache_dir and random.random() < (conf.cache_cleanup / 100.0):
		files = list()
		for p in map(ft.partial(os.path.join, conf.cache_dir), os.listdir(conf.cache_dir)):
			try: s = os.stat(p)
			except (OSError, IOError):
				pdb.gimp_message('WPS-WARN: Unable to access cache path: {!r}'.format(p))
				continue
			files.append((s.st_mtime, s.st_size, p))
		files = sorted(files, reverse=True)
		while files and sum(map(op.itemgetter(1), files)) > conf.cache_size:
			mtime, size, p = files.pop() # oldest one
			os.unlink(p)
示例#30
0
文件: gosd.py 项目: 337240552/tools
def popup(text, bgcolor=None, fgcolor=None, fontdesc=None, use_markup=False):
    assert isinstance(fontdesc, pango.FontDescription)
    win = gtk.Window(gtk.WINDOW_POPUP)
    win.set_border_width(0)
    frame = gobject.new(gtk.Frame, shadow_type=gtk.SHADOW_ETCHED_OUT,
                        visible=True)
    win.add(frame)
    label = gobject.new(gtk.Label, use_markup=True, label=text, visible=True)
    label.modify_font(fontdesc)
    
    frame.add(label)

    win.show()
    win.width, win.height = win.allocation.width, win.allocation.height
    return win


if __name__ == '__main__':
    w = osd("<i>Hello</i> <span size='larger' weight='bold'>World</span>"
            "<span foreground='red'>!</span> sad adasd asd asd as das asd"
            " asdasdasdashdjasdlasl dkasdaskdjakaskdjasdlsajldj", "#000000", "#80ff80",
            pango.FontDescription("sans serif 48"),
            use_markup=True, drop_shadow=True, debug_frame = True, ellipsize=pango.ELLIPSIZE_END)
    w.move(gdk.screen_width()/2 - w.width/2, gdk.screen_height() - w.height - 10)
    def motion(wid, ev):
        print "enter notify!"
    w.connect("enter-notify-event", motion)
    w.show()
    gtk.main()

示例#31
0
 def _update_size(self):
     if self._position == gtk.POS_TOP or self._position == gtk.POS_BOTTOM:
         self.resize(gdk.screen_width(), self.size)
     else:
         self.resize(self.size, gdk.screen_height())
示例#32
0
文件: gosd.py 项目: uncia/tools-1
    label.modify_font(fontdesc)

    frame.add(label)

    win.show()
    win.width, win.height = win.allocation.width, win.allocation.height
    return win


if __name__ == '__main__':
    w = osd(
        "<i>Hello</i> <span size='larger' weight='bold'>World</span>"
        "<span foreground='red'>!</span> sad adasd asd asd as das asd"
        " asdasdasdashdjasdlasl dkasdaskdjakaskdjasdlsajldj",
        "#000000",
        "#80ff80",
        pango.FontDescription("sans serif 48"),
        use_markup=True,
        drop_shadow=True,
        debug_frame=True,
        ellipsize=pango.ELLIPSIZE_END)
    w.move(gdk.screen_width() / 2 - w.width / 2,
           gdk.screen_height() - w.height - 10)

    def motion(wid, ev):
        print "enter notify!"

    w.connect("enter-notify-event", motion)
    w.show()
    gtk.main()
示例#33
0
import gtk.gdk as gdk
import time

w = gdk.screen_width()
h = gdk.screen_height()

sg = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, w, h)

start = time.clock()

pb = sg.get_from_drawable(gdk.get_default_root_window(),
                          gdk.colormap_get_system(), 0, 0, 0, 0, w, h)

print(time.clock() - start)