Пример #1
0
    def __init__(self, parent=None):
        super(AfelApp, self).__init__(parent)
        self.setGeometry(10, 10, 1000, 1200)
        # self.setStyleSheet("""
        #
        #              font-size: 200;
        #
        #         """)
        # Flags
        self.modes = {
            'outer_window': True,
            'live_mode': False
        }

        self.result_box_group = None
        self.result_box = None

        self.module_btns = []

        mainWindow = QWidget(self)
        self.setCentralWidget(mainWindow)
        mainlay = QHBoxLayout()

        mainWindow.setLayout(mainlay)

        #  load area
        btns_group = QGroupBox()
        btns_lay = QVBoxLayout()
        btns_group.setLayout(btns_lay)
        btns_lay.addStretch(1)
        self.btns_lay = btns_lay

        self.load_modules_btns()

        startbtn = QPushButton('start process')
        startbtn.clicked.connect(self.start_process)
        btns_lay.addWidget(startbtn)



        #  sandbox area
        self.sandbox = SandBox()
        self.sandboxlay = QVBoxLayout()
        # self.sandboxlay.addStretch(209)
        self.sandbox.setLayout(self.sandboxlay)

        mainlay.addWidget(btns_group,1)
        mainlay.addWidget(self.sandbox,10)

        # toolbar
        # toolbar.setIconSize(QSize(16, 16))
        self.toolbar = ToolBar(self)
        self.addToolBar(self.toolbar)
Пример #2
0
def run_battle(bots, challenge):
    # generate run commands
    judge_exec_command = challenge.judging_program.get_run_command().split(" ")
    bots_exec_commands = []
    for bot in bots:
        bots_exec_commands.append(bot.playing_program.get_run_command().split(" "))
    # run sandbox
    sb = SandBox(judge_exec_command, bots_exec_commands, challenge.game_duration, challenge.memory_usage)
    scores = sb.run()
    # save results
    battle = Battle(challenge = challenge)
    battle.save()
    for i in range(0, bots.__len__()):
        battle_result = BattleResult(battle = battle,
                                     bot = bots[i],
                                     comment = scores[i][1],
                                     score = scores[i][0])
        battle_result.save()
Пример #3
0
def run():

    from bloodyhell.game import Game

    game = Game('test shoot', (800, 600),
                os.path.join(os.path.dirname(__file__), 'res'),
                fps=24)
    navigator = game.navigator()
    navigator.set_current_view(SandBox())
    game.run()
Пример #4
0
import os
from sandbox import SandBox, get_mod_name

s = SandBox()
home = os.environ["HOME"]

s.set_mod(mod_name=get_mod_name())
s.set_mod("bin,lib", home + "/soft/office/doublecmd")
s.set_mod("bin", home + "/soft/office/Typora-linux-x64")
s.set_mod("bin", home + "/soft/office/pycharm-community-2020.3/bin")
s.set_mod("pkg", home + "/soft/office/codeblocks-20.03")

s.echo_commands()
Пример #5
0
import os
from sandbox import SandBox, get_mod_name

s = SandBox()
home = os.environ["HOME"]

s.set_mod(mod_name=get_mod_name())
s.set_mod("pkg", home + "/soft/lib/boost-1.75.0")

s.echo_commands()
Пример #6
0
import os
from sandbox import SandBox, get_mod_name


s = SandBox()
home = os.environ["HOME"]

s.set_mod(mod_name=get_mod_name())
s.set_mod("bin", home+"/soft/dft/fleurMaXR3.1-nowan/build.GNU")
s.reset("OMP_NUM_THREADS", 1)

s.echo_commands()
Пример #7
0
from sandbox import SandBox
modules = ["random", "math", "numpy"]
#builtins_allowed = ["range", "xrange"]
objects = {
    'listdir': os.listdir,
    'platform': sys.platform,
    'pprint': pprint.pprint,
    'dict': dict,
    'chr': chr,
    'ord': ord,
    'dir': dir
}
#s = SandBox(modules=modules, builtins_allowed=builtins_allowed, objects=objects)

s = SandBox(modules=modules, builtins_allowed=[], objects=objects)
#s.disable_underscore()
s.set_verbose()


def printc(*args):
    """
    Print text in colored format

    Color tags:
    {r} - red
    {y} - yellow
    {g} - green
    {0} - black
    {m} - magneta
    {w} - white
Пример #8
0
import os
from sandbox import SandBox, get_mod_name


s = SandBox()
home = os.environ["HOME"]

s.set_mod(mod_name=get_mod_name())
s.set_mod("bin,lib", home+"/soft/dft/wannier90-2.1.0")

s.echo_commands()
Пример #9
0
# Source code home: https://github.com/eclipse/paho.mqtt.python#getting-started


from time import sleep

import paho.mqtt.client as mqtt

from sandbox import SandBox


# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
    print(f'Connected with result code {rc}')


sb = SandBox()
sb.authenticate()
topic = sb.get_topic()

client = mqtt.Client(client_id=sb.client_id)
client.on_connect = on_connect
client.username_pw_set(
    username=sb.username,
    password=sb.token
)
client.tls_set()

try:
    client.connect(sb.host, 8883, 60)
    client.loop_start()
Пример #10
0
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
    print(f'Connected with result code {rc}')

    # Subscribing in on_connect() means that if we lose the connection and
    # reconnect then subscriptions will be renewed.
    client.subscribe(userdata.get_topic())


# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
    print(f'Received message from {msg.topic}: {msg.payload}')


sb = SandBox()
sb.authenticate()

client = mqtt.Client(client_id=sb.client_id, userdata=sb)
client.on_connect = on_connect
client.on_message = on_message
client.username_pw_set(username=sb.username, password=sb.token)
client.tls_set()
client.connect(sb.host, 8883, 60)

# Blocking call that processes network traffic, dispatches callbacks and
# handles reconnecting.
# Other loop*() functions are available that give a threaded interface and a
# manual interface.
client.loop_forever()
Пример #11
0
import os
from sandbox import SandBox, get_mod_name

s = SandBox()
home = os.environ["HOME"]

s.set_mod(mod_name=get_mod_name())
s.set_mod("bin,lib", home + "/soft/dft/VESTA-gtk3")
s.set_alias("vesta", "VESTA")

s.echo_commands()
Пример #12
0
import os
from sandbox import SandBox, get_mod_name

s = SandBox()
home = os.environ["HOME"]

s.set_mod(mod_name=get_mod_name())
s.set_mod("bin,lib", home + "/soft/dft/xcrysden-1.6.2-bin-shared")

s.echo_commands()
Пример #13
0
import os
from sandbox import SandBox, get_mod_name

s = SandBox()
home = os.environ["HOME"]
siesta = home + "/soft/dft/siesta-v4.1-b4"

s.set_mod(mod_name=get_mod_name())
s.set_mod("pkg", siesta + "/Docs/build/flook/0.8.1")
s.set_mod("pkg", siesta + "/Docs/build/hdf5/1.8.21")
s.set_mod("pkg", siesta + "/Docs/build/netcdf/4.7.4")
s.set_mod("pkg", siesta + "/Docs/build/zlib/1.2.11")
s.set_mod("bin", siesta + "/Obj")
s.reset("OMP_NUM_THREADS", 1)

s.echo_commands()
Пример #14
0
import os
from sandbox import SandBox, get_mod_name

s = SandBox()
home = os.environ["HOME"]

s.set_mod(mod_name=get_mod_name())
s.set_mod("pkg", home + "/soft/dft/bgw-2.1")
s.reset("OMP_NUM_THREADS", 1)

s.echo_commands()
Пример #15
0
import os
from sandbox import SandBox, get_mod_name

s = SandBox()
home = os.environ["HOME"]

s.set_mod(mod_name=get_mod_name())
s.set_mod("bin", home + "/soft/dft/spex05.00/bin")
s.reset("OMP_NUM_THREADS", 1)

s.echo_commands()
Пример #16
0
class AfelApp(QMainWindow):
    def __init__(self, parent=None):
        super(AfelApp, self).__init__(parent)
        self.setGeometry(10, 10, 1000, 1200)
        # self.setStyleSheet("""
        #
        #              font-size: 200;
        #
        #         """)
        # Flags
        self.modes = {
            'outer_window': True,
            'live_mode': False
        }

        self.result_box_group = None
        self.result_box = None

        self.module_btns = []

        mainWindow = QWidget(self)
        self.setCentralWidget(mainWindow)
        mainlay = QHBoxLayout()

        mainWindow.setLayout(mainlay)

        #  load area
        btns_group = QGroupBox()
        btns_lay = QVBoxLayout()
        btns_group.setLayout(btns_lay)
        btns_lay.addStretch(1)
        self.btns_lay = btns_lay

        self.load_modules_btns()

        startbtn = QPushButton('start process')
        startbtn.clicked.connect(self.start_process)
        btns_lay.addWidget(startbtn)



        #  sandbox area
        self.sandbox = SandBox()
        self.sandboxlay = QVBoxLayout()
        # self.sandboxlay.addStretch(209)
        self.sandbox.setLayout(self.sandboxlay)

        mainlay.addWidget(btns_group,1)
        mainlay.addWidget(self.sandbox,10)

        # toolbar
        # toolbar.setIconSize(QSize(16, 16))
        self.toolbar = ToolBar(self)
        self.addToolBar(self.toolbar)

    def load_modules_btns(self):
        self.clear_modules_btns()
        all_modules, errors = Module.get_all_modules()
        for btn in [ModuleBtn(m) for m in all_modules]:
            self.btns_lay.insertWidget(0, btn)
            self.module_btns.append(btn)
        self.pop_errors(errors)

    def pop_errors(self, errors):
        for e in errors:
            w = QMainWindow(self)
            w.setCentralWidget(AMsgBox(self,e))
            w.show()

    def clear_modules_btns(self):
        [b.deleteLater() for b in self.module_btns]
        self.module_btns = []

    def reload(self):  # reload all - sandbox and modules btn
        temp_path = 'm/temp/temporaryModules'  # sandbox cash

        self.sandbox.dump_sandbox(temp_path)
        self.clear_modules_btns()
        self.load_modules_btns()
        self.sandbox.clear_sandbox(force=True)
        self.sandbox.load_file_modules(temp_path)

    def start_process(self):
        if self.result_box_group:  # Qgroup to include the results window when not poped
            self.result_box_group.deleteLater()  # improve memory
            self.result_box_group = None
        self.old_box = self.result_box
        starter = self.sandbox.starter
        if starter:
            try:
                extras = starter.module.run()
                self.result_box = ResultView(self, extras)
                if self.modes['outer_window']:
                    w = QMainWindow(self)
                    w.setCentralWidget(self.result_box)
                    w.show()
                else:
                    g = QGroupBox()
                    gl = QHBoxLayout()
                    g.setLayout(gl)
                    gl.addWidget(self.result_box)
                    self.result_box_group = g
                    self.layout().addWidget(g, 5)
            except:
                self.pop_errors([format_exc()])


        else:
            self.statusBar().showMessage('please define starter', 2000)
            self.sandbox.force_stater()
            self.start_process()

    def keyPressEvent(self, event):
        self.toolbar.shortcut(event.key())