コード例 #1
0
ファイル: stage.py プロジェクト: pdinsky/make-snake
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)),
    }
コード例 #2
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)),
    }
コード例 #3
0
ファイル: webapp.py プロジェクト: carriercomm/kano-toolset
    def run(self):
        warnings.simplefilter("ignore")

        self._pipe_name = '/tmp/webapp.pipe'


        self._view = view = webkit.WebView()
        view.connect('navigation-policy-decision-requested',
                     self._api_handler)
        view.connect('close-web-view', self._close)
        view.connect('onload-event', self._onload)

        if self._inspector:
            view.get_settings().set_property("enable-developer-extras", True)

        if hasattr(self.__class__, "_focus_in"):
            view.connect('focus-in-event', self._focus_in)

        if hasattr(self.__class__, "_focus_out"):
            view.connect('focus-out-event', self._focus_out)

        if hasattr(self.__class__, "_download"):
            view.connect('download-requested', self._download)

        splitter = gtk.VPaned()
        sw = gtk.ScrolledWindow()
        sw.add(view)
        splitter.add1(sw)

        inspector = view.get_web_inspector()
        inspector.connect("inspect-web-view", self._activate_inspector, splitter)

        self._win = win = gtk.Window(gtk.WINDOW_TOPLEVEL)
        win.set_title(self._title)
        win.connect("destroy", gtk.main_quit)

        if self._app_icon is not None:
            if os.path.exists(self._app_icon):
                win.set_icon_from_file(self._app_icon)
            else:
                win.set_icon_name(self._app_icon)

        if self._taskbar is False:
            gtk.Window.set_skip_taskbar_hint(win, True)

        win.add(splitter)
        win.realize()
        win.show_all()

        gdk_window_settings(win.window, self._x, self._y,
                            self._width, self._height, self._decoration,
                            self._maximized, self._centered)

        if self._disable_minimize:
            win.connect("window-state-event", self._unminimise_if_minimised)

        view.open(self._index)

        # Start a thread that injects Javascript code coming from a filesystem pipe.
        if self._pipe == True:
            atexit.register (atexit_pipe_cleanup, self._pipe_name)
            thread.start_new_thread (thr_inject_javascript, (self._view, self._pipe_name))

        gtk.main()
コード例 #4
0
    def run(self):
        warnings.simplefilter("ignore")

        self._pipe_name = '/tmp/webapp.pipe'

        self._view = view = webkit.WebView()
        view.connect('navigation-policy-decision-requested',
                     self._nav_req_handler)
        view.connect('close-web-view', self._close)
        view.connect('onload-event', self._onload)

        language = self._get_browser_lang()
        view.execute_script("window.navigator.userLanguage = '%s'" % language)

        if self._inspector:
            view.get_settings().set_property("enable-developer-extras", True)

        if hasattr(self.__class__, "_focus_in"):
            view.connect('focus-in-event', self._focus_in)

        if hasattr(self.__class__, "_focus_out"):
            view.connect('focus-out-event', self._focus_out)

        if hasattr(self.__class__, "_download"):
            view.connect('download-requested', self._download)

        splitter = gtk.VPaned()
        sw = gtk.ScrolledWindow()
        sw.add(view)
        splitter.add1(sw)

        inspector = view.get_web_inspector()
        inspector.connect("inspect-web-view", self._activate_inspector,
                          splitter)

        self._win = win = gtk.Window(gtk.WINDOW_TOPLEVEL)
        win.set_title(self._title)
        win.connect("destroy", gtk.main_quit)

        if self._app_icon is not None:
            if os.path.exists(self._app_icon):
                win.set_icon_from_file(self._app_icon)
            else:
                win.set_icon_name(self._app_icon)

        if self._taskbar is False:
            gtk.Window.set_skip_taskbar_hint(win, True)

        win.add(splitter)
        win.realize()
        win.show_all()

        gdk_window_settings(win.window, self._x, self._y, self._width,
                            self._height, self._decoration, self._maximized,
                            self._centered)

        if self._disable_minimize:
            win.connect("window-state-event", self._unminimise_if_minimised)

        view.open(self._index)

        # Start a thread that injects Javascript code coming from a filesystem
        # pipe.
        if self._pipe is True:
            atexit.register(atexit_pipe_cleanup, self._pipe_name)
            thread.start_new_thread(thr_inject_javascript,
                                    (self._view, self._pipe_name))

        gtk.main()