Example #1
0
 def __init__(self):
     """定义初始化方法"""
     self.wallx = 400  # 管道所在X轴坐标
     self.pineUp = pygame.image.load(
         utils.resource_path("./assets/top.png"))
     self.pineDown = pygame.image.load(
         utils.resource_path("./assets/bottom.png"))
Example #2
0
def get_status_pixmap(status):
    if status is True:
        return QPixmap(
            utils.resource_path(
                './app/resources/icons/button-green.png')).scaled(
                    16, 16, Qt.KeepAspectRatio)
    else:
        return QPixmap(
            utils.resource_path(
                './app/resources/icons/button-grey.png')).scaled(
                    16, 16, Qt.KeepAspectRatio)
Example #3
0
File: mu.py Project: hoidn/packages
def alphaBetaBranch(element): 
    elementNamesf = utils.resource_path('data/elementNames.csv', pkg_name = PKG_NAME)
    dat = np.genfromtxt(utils.resource_path('data/transition_metal_branching_ratios.txt', pkg_name = PKG_NAME),
        dtype = (float, int,  np.dtype('S4'), float))
        
    elementLabels = np.genfromtxt(elementNamesf, dtype = (np.dtype('S10'), np.dtype('S10')))
    extractedLabel = filter(lambda x : element == x[1], elementLabels)
    if len(extractedLabel) == 0: 
        raise ValueError("Element " + element + "not found. Valid keys \
            are: ")
    atomicN = int(extractedLabel[0][0])
    fLines = filter(lambda x : x[1] == atomicN, dat)
    return fLines
Example #4
0
 def __init__(self):
     self.birdRect = pygame.Rect(65, 50, 50, 50)
     self.birdStatus = [
         pygame.image.load(utils.resource_path("./assets/1.png")),
         pygame.image.load(utils.resource_path("./assets/2.png")),
         pygame.image.load(utils.resource_path("./assets/dead.png")),
     ]
     self.status = 0  # 默认飞行状态
     self.birdX = 120  # 鸟所在X轴坐标,即是向右飞行的速度
     self.birdY = 350  # 鸟所在Y轴坐标,即上下飞行高度
     self.jump = False  # 默认情况小鸟自动降落
     self.jumpSpeed = 10  # 跳跃高度
     self.gravity = 5  # 重力
     self.dead = False  # 默认小鸟生命状态为活着
Example #5
0
def get_status_pixmap(status):
    """Get the coloured LED Pixmap for the given status (where OFF=Grey, ON=Green)

    :param status: a boolean indicating the status of the LED
    :return: a coloured pixmap
    """
    if status is True:
        return QPixmap(
            utils.resource_path(
                './app/resources/icons/button-green.png')).scaled(
                    16, 16, Qt.KeepAspectRatio)
    else:
        return QPixmap(
            utils.resource_path(
                './app/resources/icons/button-grey.png')).scaled(
                    16, 16, Qt.KeepAspectRatio)
Example #6
0
 def __init__(self):
     super(PositionGraph, self).__init__()
     self.setWindowTitle('Anser Position')
     self.setBackgroundColor('w')
     anser_mesh = mesh.Mesh.from_file(
         utils.resource_path('./app/resources/cad/mesh.stl'))
     anser_mesh = gl.MeshData(vertexes=anser_mesh.vectors)
     m = gl.GLMeshItem(meshdata=anser_mesh,
                       shader='shaded',
                       color=(0, 1, 0, 0.1))
     m.rotate(135, 0, 0, 1)
     m.translate(240, 0, -240)
     m.scale(1, 1, 1)
     self.addItem(m)
     gx = gl.GLGridItem()
     gx.setSize(7, 7, 7)
     gx.scale(45, 45, 45)
     gx.rotate(45, 0, 0, 1)
     #self.addItem(gx)
     self.pos = np.empty((MAX_NUM_OF_SENSORS, 3))
     self.color = np.empty((MAX_NUM_OF_SENSORS, 4))
     size = np.empty(MAX_NUM_OF_SENSORS)
     for i in range(MAX_NUM_OF_SENSORS):
         self.pos[i] = (0, 0, 0)
         self.color[i] = (0, 0.0, 0.0, 0.0)
         size[i] = 6
     self.sp1 = gl.GLScatterPlotItem(pos=self.pos,
                                     size=size,
                                     color=self.color[0],
                                     pxMode=True)
     self.sp1.setGLOptions('translucent')
     self.addItem(self.sp1)
     self.setCameraPosition(100, 800, 30)
     self.sp1.rotate(135, 0, 0, 1)
Example #7
0
def setRootParams(root):

    # Icon
    try:
        path = utils.resource_path("assets/logo.png")
        icon = PhotoImage(file=path)
        root.iconphoto(False, icon)
    except:
        print('Error')

    # Title
    root.title("Weather App")

    # Window settings
    w = 400
    h = 600

    screen_w = root.winfo_screenwidth()
    screen_h = root.winfo_screenheight()

    x = (screen_w - w - 10)
    y = (screen_h - h - 75)

    root.geometry('%dx%d+%d+%d' % (w, h, x, y))
    root.resizable(False, False)
Example #8
0
def generate_npc(type, dungeon_level=1, point=None, upgrade_chance=98):
    global names

    if (type == Species.GOBLIN):
        npc = goblin(point)
    elif (type == Species.ORC):
        npc = orc(point)
    elif (type == Species.TROLL):
        npc = troll(point)

    if not npc:
        print(f"No {type} for NPC?")
        return None

    if not names:
        tcod.namegen_parse(resource_path("data/names.txt"))
        names = True

    npc.base_name = tcod.namegen_generate(npc.base_name)

    npc_level = (dungeon_level - 1) + randint(-1, 1)

    if npc_level > 1:
        npc.level.random_level_up(npc_level - 1)

    dice = randint(1, 100)

    if (dice >= upgrade_chance):
        upgrade_npc(npc)
        npc.level.random_level_up(1)

    tweak_npc(npc)

    return npc
Example #9
0
def edge_energy(atomicN):
    """return energy in units of eV"""
    path =  utils.resource_path('data/edges.dat', pkg_name = PKG_NAME)
    if (not type(atomicN) == int) or (atomicN < 4):
        raise ValueError('invalid atomic number: ' + str(atomicN))
    tab = np.genfromtxt(path)
    return 1000 * tab[atomicN - 4]
Example #10
0
def get_status_pixmap_by_ID(statusID):
    if statusID == OFF:
        return QPixmap(
            utils.resource_path(
                './app/resources/icons/button-grey.png')).scaled(
                    16, 16, Qt.KeepAspectRatio)
    elif statusID == FAULT:
        return QPixmap(
            utils.resource_path(
                './app/resources/icons/button-orange.png')).scaled(
                    16, 16, Qt.KeepAspectRatio)
    elif statusID == ON:
        return QPixmap(
            utils.resource_path(
                './app/resources/icons/button-green.png')).scaled(
                    16, 16, Qt.KeepAspectRatio)
Example #11
0
File: mu.py Project: hoidn/packages
def get_Z_elementname_map():
    elementNamesf = utils.resource_path(
        'data/elementNames.csv', pkg_name=PKG_NAME)
    elementLabels = np.genfromtxt(
        elementNamesf, dtype=(np.dtype('S10'), np.dtype('S10')))
    ztoa = {int(k): v for k, v in elementLabels}
    return ztoa
Example #12
0
 def init_tray_icon(self):
     self.tray_icon_menu.addAction(
         QAction('设置', self, triggered=self.show_settings))
     self.tray_icon_menu.addAction(
         QAction('关于', self, triggered=self.show_about))
     self.tray_icon_menu.addAction(QAction('退出', self,
                                           triggered=self.close))
     self.tray_icon.setIcon(QIcon(resource_path('resources/hope-h.png')))
     self.tray_icon.setContextMenu(self.tray_icon_menu)
     self.tray_icon.show()
Example #13
0
def get_status_pixmap_by_ID(statusID):
    """ Get the coloured LED Pixmap for the given ID (where OFF=Grey(0), FAULT=ORANGE(1), ON=Green(2))
    :param statusID: the given ID indicating the status of the LED
    :return: QPixmap : a coloured pixmap
    """
    if statusID == OFF:
        return QPixmap(
            utils.resource_path(
                './app/resources/icons/button-grey.png')).scaled(
                    16, 16, Qt.KeepAspectRatio)
    elif statusID == FAULT:
        return QPixmap(
            utils.resource_path(
                './app/resources/icons/button-orange.png')).scaled(
                    16, 16, Qt.KeepAspectRatio)
    elif statusID == ON:
        return QPixmap(
            utils.resource_path(
                './app/resources/icons/button-green.png')).scaled(
                    16, 16, Qt.KeepAspectRatio)
Example #14
0
 def warning_popup(self, cue_word):
     '''
     @description: 警告框
     @param {str} [cue_word] - 提示词
     @return: {function}
     @author: Senkita
     '''
     warningPopup = sg.Popup(
         '警告!', cue_word, icon=resource_path(Path('./assets/ico').joinpath('sn.ico'))
     )
     if warningPopup in (None, 'OK'):
         return self.user_interface()
Example #15
0
 def popup(status, cue_word):
     '''
     @description: 弹框
     @param {string} [status] - 状态,
            {string} [cue_word] - 提示词
     @return: {Popup}
     @author: Senkita
     '''
     return sg.Popup(
         status,
         cue_word,
         icon=resource_path(Path('./assets/ico').joinpath('sn.ico')),
     )
Example #16
0
    def progress_bar(length):
        '''
        @description: 进度条
        @param {int} [length] - 任务总数
        @return: {obj} [pb_window] - 进度条界面,
                 {obj} [pb] - 进度条
        @author: Senkita
        '''
        layout = [
            [sg.ProgressBar(length, orientation='h', size=(40, 20), key='progressbar')],
        ]

        pb_window = sg.Window('任务完成进度', layout)
        pb_window.SetIcon(icon=resource_path(Path('./assets/ico').joinpath('sn.ico')))
        pb = pb_window['progressbar']
        return pb_window, pb
Example #17
0
    def get_weather_image(self, key, size_change=4):
        key = key.lower()
        path = utils.resource_path("assets/" + key + ".png")

        try:
            img = Image.open(path)
            size = img.size

            img = img.resize(
                (int(size[0] / size_change), int(size[1] / size_change)),
                Image.ANTIALIAS)

            widget = ImageTk.PhotoImage(img)
            return widget
        except:
            # TODO: Log error Image not found
            return None
    def __addText(self, model, sn):
        '''
        @description: 添加S/N号
        @param {str} [model] - 型号,
               {str} [sn] - S/N号
        @return: None
        @author: Senkita
        '''
        img = Image.open(self.temp_dir.joinpath('preprocess.png'))
        draw = ImageDraw.Draw(img)
        ttf_font = str(resource_path(Path('./assets/font').joinpath('times.ttf')))
        model_font = ImageFont.truetype(font=ttf_font, size=119)
        sn_font = ImageFont.truetype(font=ttf_font, size=100)
        # 添加型号
        draw.text((1866, 1117), model, (0, 0, 0), font=model_font)
        # 添加S/N号
        draw.text((4516, 1127), sn, (0, 0, 0), font=sn_font)

        img.save(self.temp_dir.joinpath('postprocess.png'))
Example #19
0
def potion_description(item):
    global potion_random_details

    description = potion_descriptions.get(item.base_name)
    if not description:
        if not potion_random_details:
            tcod.namegen_parse(resource_path("data/liquids.txt"))
            potion_random_details = True
        description = {}
        description['container'] = tcod.namegen_generate('potion_container')
        description['liquid_color'] = tcod.namegen_generate('potion_colours')
        description['liquid_type'] = tcod.namegen_generate('potion_texture')
        potion_descriptions[item.base_name] = description

    item.add_component(
        IdentifiablePotion(container=description['container'],
                           liquid_color=description['liquid_color'],
                           liquid_type=description['liquid_type']),
        "identifiable")

    return item
Example #20
0
 def __init__(self):
     super(PositionGraph, self).__init__()
     self.setWindowTitle('Anser Position')
     self.setBackgroundColor('w')
     # Import the STL of the transmitter board and transform it into a mesh item
     anser_mesh = mesh.Mesh.from_file(
         utils.resource_path('./app/resources/cad/mesh.stl'))
     anser_mesh = gl.MeshData(vertexes=anser_mesh.vectors)
     # re-center the transmitter board mesh item in the position graph
     m = gl.GLMeshItem(meshdata=anser_mesh,
                       shader='shaded',
                       color=(0, 1, 0, 0.1))
     m.rotate(135, 0, 0, 1)
     m.translate(240, 0, -240)
     m.scale(1, 1, 1)
     self.addItem(m)
     # create a virtual grid representing the transmitter board
     gx = gl.GLGridItem()
     gx.setSize(7, 7, 7)
     gx.scale(45, 45, 45)
     gx.rotate(45, 0, 0, 1)
     #self.addItem(gx)
     self.pos = np.empty((MAX_NUM_OF_SENSORS, 3))
     self.color = np.empty((MAX_NUM_OF_SENSORS, 4))
     size = np.empty(MAX_NUM_OF_SENSORS)
     for i in range(MAX_NUM_OF_SENSORS):
         self.pos[i] = (0, 0, 0)
         self.color[i] = (0, 0.0, 0.0, 0.0)
         size[i] = 6
     # create the 3D visualisation graph
     self.sp1 = gl.GLScatterPlotItem(pos=self.pos,
                                     size=size,
                                     color=self.color[0],
                                     pxMode=True)
     self.sp1.setGLOptions('translucent')
     self.addItem(self.sp1)
     # recenter camera position
     self.setCameraPosition(100, 800, 30)
     self.sp1.rotate(135, 0, 0, 1)
Example #21
0
 def user_interface(self):
     '''
     @description: 文件选择界面
     @param {type}
     @return: {str}
     @author: Senkita
     '''
     layout = [
         [sg.T('模板pdf路径:')],
         [
             sg.I(
                 default_text='./template/template.pdf',
                 size=(40, None),
                 disabled=True,
             ),
             sg.FileBrowse(button_text='打开', file_types=(('pdf文件', '*.pdf'),)),
         ],
         [sg.T('SN文件路径:')],
         [
             sg.I(
                 default_text='./template/sn.xlsx', size=(40, None), disabled=True,
             ),
             sg.FileBrowse(button_text='打开', file_types=(('Excel文件', '*.xlsx'),)),
         ],
         [sg.Submit('确定'), sg.Cancel('取消')],
     ]
     window = sg.Window('批量生成质检报告', layout)
     window.SetIcon(icon=resource_path(Path('./assets/ico').joinpath('sn.ico')))
     event, value = window.Read()
     if event == '确定':
         window.Close()
         if '' == value[0] or '' == value[1]:
             self.warning_popup('存在漏填项!')
         else:
             return value[0], value[1]
     elif event in (None, '取消'):
         window.Close()
Example #22
0
import pygame
import sys

from model.pipeLine import Pipeline
from model.bird import Bird
from utils import utils

pygame.init()  # 初始化pygame
pygame.font.init()  # 初始化字体
size = width, height = 400, 650  # 设置窗口大小
screen = pygame.display.set_mode(size)  # 显示窗口
color = (255, 255, 255)

font = pygame.font.SysFont("Arial", 50)  # 设置字体和大小
background = pygame.image.load(utils.resource_path("./assets/background.png"))
clock = pygame.time.Clock()  # 设置时钟
FPS = 30

score = 0
Pipeline = Pipeline()  # 实例化管道类
Bird = Bird()  # 实例化鸟类


def createMap():
    global score
    screen.fill(color)
    screen.blit(background, (0, 0))  # 填入到背景

    # 显示管道
    screen.blit(Pipeline.pineUp, (Pipeline.wallx, -300))  # 上管道坐标位置
    screen.blit(Pipeline.pineDown, (Pipeline.wallx, 500))  # 下管道坐标位置
Example #23
0
def get_logo():
    return utils.resource_path('./app/resources/icons/anser_logo.png')
Example #24
0
import sys

from PySide6 import QtWidgets, QtGui

from utils.utils import resource_path
from views import main

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    app.setWindowIcon(QtGui.QIcon(resource_path('resources/hope.png')))
    ex = main.MainWindow()
    sys.exit(app.exec_())

Example #25
0
def main():
    global current_game, root_console

    equipment.import_armour()
    equipment.import_weapons()

    tcod.console_set_custom_font(
        resource_path(CONFIG.get('font')),
        CONFIG.get('font_type') | tcod.FONT_TYPE_GREYSCALE,
    )

    root_console = tcod.console_init_root(CONFIG.get('full_screen_width'),
                                          CONFIG.get('full_screen_height'),
                                          CONFIG.get('window_title'),
                                          False,
                                          order='F',
                                          vsync=False)

    current_game.start_fresh_game()

    while True:
        root_console.clear(fg=COLORS.get('console_background'))

        if current_game.game_state == GameStates.GAME_EXIT:
            raise SystemExit()
        '''
                if show_main_menu:
                    root_console.clear(fg=(255, 255, 255))

                    main_menu(root_console, main_menu_background_image, CONFIG.get('full_screen_width'),
                              CONFIG.get('full_screen_height'))

                    if show_load_error_message:
                        message_box(map_console, 'No saved game to load', 50, CONFIG.get('full_screen_width'), constants['screen_height'])

                    tcod.console_flush()

                    action = handle_keys(key, GameStates.GAME_START)

                    if len(action) > 0:
                        result_type, result_data = unpack_single_key_dict(action)
                        if show_load_error_message and (result_type == InputTypes.GAME_LOAD):
                            show_load_error_message = False
                        elif result_type == InputTypes.GAME_NEW:
                            player, game_map, message_log, game_state = get_game_variables(constants)
                            game_map.create_floor(player)

                            show_main_menu = False
                        elif result_type == InputTypes.GAME_LOAD:
                            try:
                                player, game_map, message_log, game_state, pubsub.pubsub = load_game()
                                show_main_menu = False
                            except FileNotFoundError:
                                show_load_error_message = True
                        elif result_type == InputTypes.GAME_EXIT:
                            break
        '''
        #if self.game_state == GameStates.GAME_START:
        #    main_menu.on_draw()
        #else:
        current_game.on_draw()
        tcod.console_flush()

        #Uncomment the following line to take a screenshot each turn
        #tcod.sys_save_screenshot()

        if (current_game.game_state == GameStates.ENEMY_TURN
                or current_game.game_state == GameStates.PLAYER_SLEEP):
            current_game.process_turn(None, None)
        else:
            handle_events()
Example #26
0
def import_armour():
    with open(resource_path('data/equipment/armour.json')) as json_file:
        data = json.load(json_file)

        for detail in data:
            armours[detail["Name"]] = detail
Example #27
0
File: mu.py Project: hoidn/packages
def getElementDensities(): 
    elementDatDir = utils.resource_path('data/elementDensities.csv', pkg_name = PKG_NAME)
    f = open(elementDatDir, 'r')
    dat = np.genfromtxt(f, dtype = (int, np.dtype('S5'), float), delimiter = ',')
    return dat
Example #28
0
def import_weapons():
    with open(resource_path('data/equipment/weapons.json')) as json_file:
        data = json.load(json_file)

        for detail in data:
            weapons[detail["Name"]] = detail
Example #29
0
def get_logo():
    """ Get the path of the Anser Logo
    :return: the path of the Anser Logo
    """
    return utils.resource_path('./app/resources/icons/anser_logo.png')