예제 #1
0
 def _insertBlock(self, cursor=None, block_type=TextBlock.TYPE_CODE_CONTINUED, content=""):
     if cursor is None:
         cursor = self._currentCursor
     b = TextBlock(cursor, create_new=True, typ=block_type)
     if len(content):
         b.appendText(content)
     return b
예제 #2
0
 def _blocks(self):
     b = TextBlock(self._document.begin())
     ret = []
     while not b.isLast():
         ret.append(b)
         b = b.next()
     ret.append(b)
     return ret
예제 #3
0
 def _appendBlock(self, block_type, content="", html=False):
     b = TextBlock(self._endCursor, create_new=True, typ=block_type)
     if len(content) > 0:
         if html:
             b.appendHtml(content)
         else:
             b.appendText(content)
     return b
예제 #4
0
 def __init__(self):
     self.slack_token = os.environ["SLACK_BOT_TOKEN"]
     self.config = Config()
     self.api_path = self.config.api_path
     self.sc = slack.WebClient(token=self.slack_token)
     self.id = self.get_bot_id()
     self.textblock = TextBlock()
     self.user_email = dict()
     self.awards = list()
예제 #5
0
파일: document.py 프로젝트: yimuchens/doc
 def addTextBlock(self, preBlock=False):
     """
     添加文本块,文本块没有文字,打开文件时使用
     """
     if preBlock is False:  # block可以为None,所以用false判断
         preBlock = GlobalVars.CurrentBlock
     newTextBlock = TextBlock(self, preBlock)
     return newTextBlock
예제 #6
0
def merge_lines(lines, eps, d):
    # Output Text_blocks from lines

    text_blocks = []
    for line in lines:

        # Create a bounding rectangle
        rects = [rect[1] for rect in line[2]]
        x = min(rects, key=lambda point: point.x).x
        w = max(rects, key=lambda point: point.x + point.w).x - x
        y = int(np.median([point.y for point in rects]) - eps)
        h = int(np.median([point.y + point.h for point in rects]) + d) - y
        #        y = min( rects, key=lambda point: point.y ).y
        #        h = max( rects, key=lambda point: point.y+point.h ).x - y

        # Add this rectangle
        text_blocks += [TextBlock((x, y), (x + w, y + h))]

    return text_blocks
예제 #7
0
class Bot:
    def __init__(self):
        self.slack_token = os.environ["SLACK_BOT_TOKEN"]
        self.config = Config()
        self.api_path = self.config.api_path
        self.sc = slack.WebClient(token=self.slack_token)
        self.id = self.get_bot_id()
        self.textblock = TextBlock()
        self.user_email = dict()
        self.awards = list()

    def get_bot_id(self):
        response = self.sc.api_call("users.list")
        members = response['members']
        for member in members:
            if member['real_name'] == "Badges Bot":
                return (f"<@{member['id']}>")

    def list_badges(self, web_client, channel_id):
        #web_client.chat_postMessage(channel=channel_id, text="badge list")
        r = requests.get('http://vituin-chat.iaas.ull.es/api/badges')

        badges = dict()
        for badge_id in r.json():
            uri = 'http://vituin-chat.iaas.ull.es/api/badge/' + badge_id + '/json'
            badges[badge_id] = dict()
            badge = badges[badge_id]
            r2 = requests.get(uri)
            badge_json = r2.json()
            badge['image'] = badge_json['image']
            badge['name'] = badge_json['name']

        badges_block = self.textblock.badges_text_block(badges)
        web_client.chat_postMessage(channel=channel_id, blocks=badges_block)

    async def award_badge(self, user_id, badge_name, wc, cid):
        if user_id not in self.user_email:
            self.user_email[user_id] = await self.get_email(user_id, wc, cid)
        newaward_json = dict()
        newaward_json['email'] = self.user_email[user_id]
        newaward_json['name'] = badge_name
        # Al hacer un award se va a quedar bloqueado también el servidor si se ejecuta en el  mismo proceso
        r = requests.post('http://vituin-chat.iaas.ull.es/api/newaward',
                          json=newaward_json)

        params = dict()
        params['user_id'] = user_id
        params['badge_name'] = badge_name
        params[
            'award_png_url'] = f"http://vituin-chat.iaas.ull.es/api/award/{r.text}/image"
        award_block = self.textblock.award_text_block(**params)
        #for block in award_block:
        #    print(json.dumps(block, indent=True))
        wc.chat_postMessage(channel=cid, blocks=award_block)

    async def get_email(self, user_id, wc, cid):
        response = await self.sc.api_call("users.list")
        members = response['members']
        for member in members:
            if member['id'] in user_id:
                return member['profile']['email']
예제 #8
0
                                       d)

                    # Remember the last remaining right linebox
                    if right:
                        enqueue_lb(queue, sub_linebox, right, relevant_obs, d)

    return acceptor.output()


import sys
import components
from preprocess import preprocess
from textblock import TextBlock
from orient import fixSkew
if __name__ == '__main__':

    global EPSILON_SQR
    EPSILON_SQR = 10

    # Calculate the largest possible linebox
    # image = cv.imread(sys.argv[1])
    # img = preprocess(image)
    # img = fixSkew(img)

    linebox = ([np.pi / 2, np.pi / 2], [np.sqrt(10), 2 * np.sqrt(10)])

    obs = TextBlock((2, 9), (3, 11))

    print only_intersection(linebox, obs)
    print no_intersection(linebox, obs)
예제 #9
0
    def __init__(self, **kwargs):
        super(MainWindow, self).__init__(**kwargs)
        self.width = 1000
        self.height = 800
        self.player = Player()
        self.player.setWindow(self)
        self.enemy = Enemy()
        self.enemy.setWindow(self)
        self.turn = 0  #0 = plahyer turn, 1 = enemy turn

        self.container_text = Container("vertical", 1000, 200, 0.25)
        self.textblock = TextBlock(self.container_text)
        self.pos_text = 1 - (self.textblock.height / self.height)
        self.container_text.pos_hint = {'y': self.pos_text, 'x': 0.0}
        self.container_text.add_widget(self.textblock)

        self.container_picker = Container("horizontal", 500, 50, 0.5)
        self.shippicker = ShipPicker(self.container_picker)
        self.shippicker.setPlayerInstance(self.player)
        self.pos_picker = self.pos_text - (self.shippicker.height /
                                           self.height)
        self.container_picker.pos_hint = {'y': self.pos_picker, 'x': 0.0}
        self.container_picker.add_widget(self.shippicker)

        self.container_infos = Container("horizontal", 1000, 50, 0.5)
        self.container_infos.pos_hint = {'y': 0.0, 'x': 0.0}
        self.bottom_info = Label(text='Place remaining 10 ships.')
        self.container_infos.add_widget(self.bottom_info)

        self.container_markings = Container("horizontal", 1000, 50, 0.75)
        self.markings = BoardMakings(self.container_markings)
        self.markings.createMarkingH()
        self.markings.createMarkingH()
        self.container_markings.pos_hint = {'y': 0.63, 'x': 0.0}
        self.container_markings.add_widget(self.markings)

        self.container_board = Container("horizontal", 1000, 500, 1.0)
        self.container_board.padding = 0
        self.markingv1 = BoardMakings(self.container_board)
        self.markingv2 = BoardMakings(self.container_board)
        self.markingv1.createMarkingV()
        self.markingv2.createMarkingV()
        self.player_board = PlayerBoard()
        self.player.setBoard(self.player_board)
        self.player_board.createTiles()
        self.player_board.setNeighbors()
        self.player_board.setPlayerInstance(self.player)
        self.player_board.setEnemyInstance(self.enemy)
        self.enemy_board = EnemyBoard()
        self.enemy.setBoard(self.enemy_board)
        self.enemy_board.createTiles()
        self.enemy_board.setNeighbors()
        self.enemy_board.setEnemyInstance(self.enemy)
        self.enemy_board.setPlayerInstance(self.player)
        self.container_board.pos_hint = {'y': 0.0, 'x': 0.0}
        self.container_board.add_widget(self.markingv1)
        self.container_board.add_widget(self.player_board)
        self.container_board.add_widget(Spacer())
        self.container_board.add_widget(self.enemy_board)
        self.container_board.add_widget(self.markingv2)

        self.layout = FloatLayout()
        self.layout.size_hint = (None, None)
        self.layout.width = self.width
        self.layout.height = self.height
        self.layout.pos = (0, 0)

        self.end_popup = EndScreen()

        self.layout.add_widget(self.container_text)
        self.layout.add_widget(self.container_picker)
        self.layout.add_widget(self.container_markings)
        self.layout.add_widget(self.container_board)
        self.layout.add_widget(self.container_infos)

        self.add_widget(self.layout)
예제 #10
0
    normalize_headings(text_blocks)
    # Get line values
    key_functor = lambda block: (block.top + block.bot) / 2
    text_blocks = \
    group_values(text_blocks,THRESH_V,key_functor,add_line_value,key_functor)
    # Sort text lines into geometric order using obstacles
    text_blocks = sort_geometric_order(text_blocks, obstacles)
    return text_blocks


if __name__ == '__main__':

    # Get the textblocks from a .csv
    f = open(sys.argv[1])
    text_blocks = \
    [ TextBlock([[int(c) for c in p.split(',')] for p in line.split(';')]) for line in f ]
    # Format what's in the .csv
    img = cv2.imread('mytests/josh1.jpg')
    height, width, c = img.shape
    format(text_blocks, height, width)

    # Draw the rectangles
    scale = max(height / 1080, width / 1920)
    i = 1
    for block in text_blocks:

        tl = [block.indent * width / 80, block.corners[0][1]]
        br = block.corners[2]
        tl[0] *= scale
        tl[1] *= scale
        br[0] *= scale