コード例 #1
0
ファイル: curl.py プロジェクト: miezak/madodl
def curl_to_file(url, fname, proto, port=None):
    _g.conf._fsz    = 0
    _g.conf._time   = 0
    _g.conf._lastdl = 0

    # unicurses doesn't seem to add these manually...
    _g.conf._LINES,_g.conf._COLS = unicurses.getmaxyx(_g.conf._stdscr)

    with open(os.path.join(_g.conf._outdir, fname), 'wb') as fh:
        c = curl_common_init(fh)

        c.setopt(c.URL, url) #'/'.join(rempath, urllib.parse.quote(fname)))
        c.setopt(c.NOPROGRESS, False)
        c.setopt(c.XFERINFOFUNCTION, curl_progress)
        if port:
            c.setopt(c.PORT, port)

        try:
            c.perform()
        except pycurl.error:
            check_curl_error(c, fh, proto, True)
        check_curl_error(c, fh, proto)

        c.close()

    return None
コード例 #2
0
 def render(self, etc=None):
     unicurses.redrawwin(self.screen)
     unicurses.noutrefresh(self.screen)
     (hw, ww) = unicurses.getmaxyx(self.screen)
     (yw, xw) = (max(0, (hw - self.h)/2), max(0, (ww - self.w)/2))
     if yw > 0 and xw > 0:
         unicurses.mvwin(self.frame, yw - 1, xw - 1)
         unicurses.noutrefresh(self.frame)
     unicurses.mvwin(self.win, yw, xw)
     unicurses.noutrefresh(self.win)
     if etc != None:
         (buf, a, b, c, d, e, f) = etc
         (yb, xb) = unicurses.getbegyx(self.win)
         unicurses.prefresh(buf, a, b, c + yb, d + xb, e + yb, f + xb)
     unicurses.doupdate()
コード例 #3
0
ファイル: textuserinterface.py プロジェクト: Chiel92/tfate
    def update_windows(self):
        """Give all windows correct sizes and positions."""
        ymax, xmax = curses.getmaxyx(stdscr)

        # We draw the windows bottom up
        linenumber = ymax

        status_win_height = 1
        linenumber -= status_win_height
        self.status_win.setdimensions(xmax, status_win_height, 0, linenumber)

        log_win_height = 1
        linenumber -= log_win_height
        self.log_win.setdimensions(xmax, log_win_height, 0, linenumber)

        if self.undo_win.enabled:
            undo_win_height = 4
            linenumber -= undo_win_height
            self.undo_win.setdimensions(xmax, undo_win_height, 0, linenumber)

        if self.error_win.enabled:
            error_win_height = 6
            linenumber -= error_win_height
            self.error_win.setdimensions(xmax, error_win_height, 0, linenumber)

        if self.completion_win.enabled:
            completion_win_height = 6
            linenumber -= completion_win_height
            self.completion_win.setdimensions(xmax, completion_win_height, 0, linenumber)

        if self.clipboard_win.enabled:
            clipboard_win_height = 3
            linenumber -= clipboard_win_height
            self.clipboard_win.setdimensions(xmax, clipboard_win_height, 0, linenumber)

        self.text_win.setdimensions(xmax, linenumber - 1, 0, 1)
        self.document_win.setdimensions(xmax, 1, 0, 0)

        self.prompt_win.setdimensions(int(xmax / 2), 2, int(xmax / 2), 4)
コード例 #4
0
    def init_wins(self):
        uc.wclear(stdscr)
        self.max_y, self.max_x = uc.getmaxyx(stdscr)

        border_x = ceil(self.max_x * 2 / 3)
        c = int(self.max_x % 2 == 1)

        self.win_title = uc.newwin(3, self.max_x, 0,
                                   0)  #(h, w, starty, startx)
        self.win_boardarea = uc.newwin(self.max_y - 4, border_x, 3, 0)
        self.win_shipmenu = uc.newwin(self.max_y - 4, self.max_x - border_x, 3,
                                      border_x)
        self.win_statusbar = uc.newwin(1, self.max_x, self.max_y - 1, 0)

        x, y = self.player.board.str_size()
        self.win_board = uc.newwin(y, x + 2, 0, 0)
        self.pan_board = uc.new_panel(self.win_board)

        uc.move_panel(self.pan_board, 3 + (self.max_y - 3) // 2 - y // 2,
                      (border_x - 3) // 2 - x // 2)

        uc.wrefresh(stdscr)
        self.draw()
コード例 #5
0
 def __init__(self):
     # Initialize screen
     self.stdscr = uni.initscr()
     # Hide cursor
     uni.curs_set(0)
     # Characters available one-by-one
     uni.cbreak()
     # Prevent displying user input
     uni.noecho()
     # Allow user input
     uni.keypad(self.stdscr, True)
     # Enable colors
     uni.start_color()
     # Enable mouse
     uni.mouseinterval(0)
     uni.mousemask(uni.ALL_MOUSE_EVENTS)
     # Window dimensions
     y, x = uni.getmaxyx(self.stdscr)
     # Make maxx/maxy the last row/col visible
     self.maxy = y - 1
     self.maxx = x - 1
     # Drawing order of contained widgets
     self.widgets = []
コード例 #6
0
    def input(self):
        self.key = uc.wgetch(stdscr)

        if self.key == uc.KEY_RESIZE:
            self.max_y, self.max_x = uc.getmaxyx(stdscr)
            if self.max_x > 10 and self.max_y > 10:
                self.init_wins()

        if (self.on_menu):
            if (self.key == uc.KEY_UP):
                self.menu_hi -= 1
                if self.menu_hi == -1:
                    self.menu_hi = len(self.menu) - 1

            elif (self.key == uc.KEY_DOWN):
                self.menu_hi += 1
                if self.menu_hi >= len(self.menu):
                    self.menu_hi = 0

            elif (self.key == ord('\n')):
                for ship in self.player.ship_list:
                    if ship.id == self.menu[self.menu_hi].id:
                        ship.placed = True

                self.new_ship_id = self.menu[self.menu_hi].id
                self.new_ship_len = self.menu[self.menu_hi].length

                self.new_ship_x = 0
                self.new_ship_y = 0
                self.new_ship_hor = True

                self.on_menu = False
        else:
            if (self.key == uc.KEY_LEFT):
                if self.new_ship_x - 1 >= 0:
                    self.new_ship_x -= 1

            elif (self.key == uc.KEY_RIGHT):
                if self.new_ship_hor:
                    if self.new_ship_x + self.menu[
                            self.menu_hi].length < self.player.board.size:
                        self.new_ship_x += 1
                else:
                    if self.new_ship_x + 1 < self.player.board.size:
                        self.new_ship_x += 1

            elif (self.key == uc.KEY_UP):
                if self.new_ship_y - 1 >= 0:
                    self.new_ship_y -= 1

            elif (self.key == uc.KEY_DOWN):
                if self.new_ship_hor:
                    if self.new_ship_y + 1 < self.player.board.size:
                        self.new_ship_y += 1
                else:
                    if self.new_ship_y + self.menu[
                            self.menu_hi].length < self.player.board.size:
                        self.new_ship_y += 1

            elif (self.key == ord('r') or self.key == ord('R')):
                if self.new_ship_hor:
                    if self.new_ship_y + self.menu[
                            self.menu_hi].length > self.player.board.size:
                        self.new_ship_y = self.player.board.size - self.menu[
                            self.menu_hi].length
                else:
                    if self.new_ship_x + self.menu[
                            self.menu_hi].length > self.player.board.size:
                        self.new_ship_x = self.player.board.size - self.menu[
                            self.menu_hi].length
                self.new_ship_hor = not self.new_ship_hor

            elif (self.key == ord('s') or self.key == ord('S')):
                s = self.player.board.suggest(self.menu[self.menu_hi].length)
                if type(s) != bool:
                    x, y, h = s
                    self.new_ship_x = x
                    self.new_ship_y = y
                    self.new_ship_hor = h

            elif (self.key == ord('\n')):
                if self.player.board.check_new_ship(
                        self.new_ship_x, self.new_ship_y,
                        self.menu[self.menu_hi].length, self.new_ship_hor):

                    self.player.board.set_new_ship(
                        self.new_ship_x, self.new_ship_y,
                        self.menu[self.menu_hi].id,
                        self.menu[self.menu_hi].length, self.new_ship_hor)

                    self.num_ships_set += 1
                    if not self.all_set():
                        self.on_menu = True

                    self.menu = self.player.left_to_set()
                    self.menu_hi = 0

        if self.key == ord('q') or self.key == ord('Q'):
            self.close()

        if self.key == ord('w') or self.key == ord('W'):
            uc.endwin()
            exit()
コード例 #7
0
# Window
NLINES = 10
NCOLS = 40
#my_wins = [0] * 3

stdscr = uni.initscr()
uni.cbreak()
uni.noecho()
uni.keypad(stdscr, True)
uni.curs_set(0)

uni.start_color()

# Sub window
# Max coords of parent window
maxy, maxx = uni.getmaxyx(stdscr)
menu_height = 3
menu = uni.newwin(menu_height, maxx, 0, 0)
starty, startx = uni.getbegyx(menu)
height, width = uni.getmaxyx(menu)

# Box line
uni.box(menu, 0, 0)
#uni.bkgd(uni.COLOR_PAIR(1))

# Box label

#uni.wattron(menu, uni.COLOR_PAIR(0))
#uni.mvwaddstr(menu, 0, 2, "Garin")
uni.mvwaddstr(menu, 1, 1, "File")
uni.mvwaddstr(menu, 1, len("File") + 2, "Edit")
コード例 #8
0
ファイル: snake_d.py プロジェクト: mawunka/tz
import unicurses as curses
import time
import os
from random import randint, choice

os.environ['ESCDELAY'] = '25'
stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
curses.keypad(stdscr, 1)
curses.wborder(stdscr)
curses.curs_set(0)
middley, middlex = map(lambda x: x // 2, curses.getmaxyx(
    stdscr))  # get middle coordinates depending on the size of the terminal

UP = 259  # ascii key codes
DOWN = 258
LEFT = 261
RIGHT = 260

asci = '''
   _____ _   _          _  ________ 
  / ____| \ | |   /\   | |/ /  ____|
 | (___ |  \| |  /  \  | ' /| |__   
  \___ \| . ` | / /\ \ |  < |  __|  
  ____) | |\  |/ ____ \| . \| |____ 
 |_____/|_| \_/_/    \_\_|\_\______|'''


def reset_game():
    '''
コード例 #9
0
 def _cols(self):
     return uc.getmaxyx(self.stdscr)[1]
コード例 #10
0
 def _rows(self):
     return uc.getmaxyx(self.stdscr)[0]
コード例 #11
0
 def _init_render_window(self, window_name):
     win = self._windows[window_name].window
     uc.werase(win)
     rows, cols = uc.getmaxyx(win)
     return win, rows, cols
コード例 #12
0
ファイル: window.py プロジェクト: Chiel92/tfate
 def height(self):
     """Height of the window."""
     height, _ = curses.getmaxyx(self.win)
     return height
コード例 #13
0
ファイル: window.py プロジェクト: Chiel92/tfate
 def width(self):
     """Width of the window."""
     _, width = curses.getmaxyx(self.win)
     return width
コード例 #14
0
import unicurses
import numpy as np
import math
import wave
import struct
import time

stdscr = unicurses.initscr()
unicurses.cbreak()
unicurses.noecho()
unicurses.curs_set(0)
unicurses.keypad(stdscr, True)
LINES, COLS = unicurses.getmaxyx(stdscr)

height = 16

def drawData(data, x, y):
    for i in range(len(data)):
        v = data[i]
        for j in range(height):
            c = ' '
            if (j <= v - 1):
                c = '#'
            unicurses.mvaddstr(y + height - 1 - j, x + i, c)

# Initialize matrix
matrix = [0, 0, 0, 0, 0, 0, 0, 0]
power = []
weighting = [2, 2, 8, 8, 16, 32, 64, 64] # Change these according to taste

# Set up audio