예제 #1
0
def update(i):
    new, old = ([None, 0, 1, 1, -1, -1, 0][i]
                for i in [pairs[i][0].get(), pairs[i][1]])
    if new == old:
        return
    clock(
        'Update Start'
    )  #This needs to come the filter so that false alarms don't mess with the timer
    old_sign = copysign(1, pairs[i][1])
    pairs[i][1] = pairs[i][0].get()

    v = pairs[i][2]
    if old != 0:  #Update constraints to reflect removed constraint
        if v in failed_constraints:  #If it was a failed constraint,
            del failed_constraints[v]  #Note its removal, and move on.
        else:
            remove_constraint(v, old)
            if failed_constraints:  #If some constraints have failed,
                for constraint in failed_constraints:
                    add_constraint(constraint, failed_constraints[constraint])
                solution = solve()  #Try to run with all constraints
                if isinstance(solution, list):  #If succeessfull, rejoice.
                    update_gui_vars(solution)
                    failed_constraints.clear()
                else:  #Otherwise, maintain the old solution.
                    #print('('+str(solution)+')', file=stderr)
                    for constraint in failed_constraints:
                        remove_constraint(constraint,
                                          failed_constraints[constraint])
    if new != 0:  #Update constraints to reflect introduced constraint
        #(a reversed constraint is modeled as a removal and then an introduction)
        add_constraint(v, new)
        if old_sign != new:  #If this breaks current solution
            solution = solve()  #Try to run
            if isinstance(solution, list):  #If succeessfull, rejoice.
                update_gui_vars(solution)
            else:  #If fail, then flag as failed constraint, and move on.
                #print(solution, file=stderr)
                failed_constraints[v] = copysign(1, new)
                pairs[i][1] = copysign(2, old_sign)
                pairs[i][0].set(pairs[i][1])
                remove_constraint(v, new)
    clock('Update -> GUI')
    GUI.update()
    clock('GUI End')
    total_time = clock.difference('Update Start', 'GUI End')
    GUI_time = clock.difference('Update -> GUI', 'GUI End')
    engine_time = clock.difference('Engine Start', 'Engine End')
    other_time = total_time - engine_time - GUI_time

    d = clock.times
    timer_variable.set([
        total_time, GUI_time, engine_time, other_time,
        clock.average_print_time()
    ])

    clock.clear()
예제 #2
0
파일: chessgame.py 프로젝트: jonprairie/cts
    def __init__(self, player_w, player_b, time_control=default_options["time_control"]):
        self.player_w = player_w
        self.player_b = player_b
        self.time_control = time_control
        self.clock = clock(time_control)
        self.move_list = []
        self.result = 0
        self.is_finished = 0
        self.bye = 0
        self.player_on_bye = 0

        if not self.player_b:
            self.bye = 1
            self.player_on_bye = self.player_w
        if not self.player_w:
            self.bye = 1
            self.player_on_bye = self.player_b

        cts.application.row.row.__init__(self, dict(white=self.player_w, black=self.player_b))
import sys

sys.path = [ './lib' ] + sys.path
sys.path = [ './modules' ] + sys.path
 

from module import *
from notify_led  import *
from display     import *
from email_check import *
from clock       import *


config = read_config('/home/pi/.notification_conf.ini');


# Register modules
modules = {
#   'Notify_LED':  notify_led(),
    'Email_check': email_check(),
    'Display':     display.display(),
    'Clock':       clock()
}

set_modules(modules)
pass_configuration(config)
start_workers()


예제 #4
0
def solve():
    clock('Engine Start')
    out = engine.solve(engine.constraints)
    clock('Engine End')
    return out
programa = program()
proceso = InterruptionManager()
cola_ready = queue()
cola_waiting = queue()
cola_ready = queue()
cola_waiting = queue()
pcbtable = pcb_table()
pagetable = page_table()  #Ver como deshabilitar con asignacion continua
memoria_fisica = Memory()
swap = Swap()
#memory = Memory()
disco = disk()
procesador = CPU()
puntero = Dispacher()
reloj = clock()

#Variables booleanas para seleccion de opciones
option_schedule = True
option_type_memory = True
option_ajuste = True
option_victima = True

print "Seleccione el tipo de Schedule a utilizar\n"
print "0 - FCFS"
print "1 - Priority No Expropiativo"
print "2 - Round Robin"
print "3 - Priority Expropiativo"
while option_schedule:
    schedule = input("Introduce tipo de Schedule: ")
예제 #6
0
파일: design.py 프로젝트: wnew/hdl_devel
from clock import *


clk1 = clock("sys_clk", 100)
clk2 = clock("epb_clk", 67)

clocks = [clk1, clk2]

예제 #7
0
    def setupUi(self, MainWindow):
        self.clk = clock()
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(480, 320)
        font = QtGui.QFont()
        font.setPointSize(16)
        MainWindow.setFont(font)

        # setting background image to status bar 
        #MainWindow.statusBar().setStyleSheet("background-image : url(beans.jpg);")

        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")

        #background Photo
        self.BackgroundPhoto = QtWidgets.QGraphicsView(self.centralwidget)
        self.BackgroundPhoto.setGeometry(QtCore.QRect(0, 0, 480, 320))
        self.BackgroundPhoto.setAutoFillBackground(False)
        self.BackgroundPhoto.setObjectName("BackgroundPhoto")
        self.BackgroundPhoto.setStyleSheet("background-image : url(beans.jpg);")

        #Clock
        self.ClockLabel = QtWidgets.QLabel(self.centralwidget)
        self.ClockLabel.setGeometry(QtCore.QRect(80, 150, 310, 101))
        font = QtGui.QFont()
        font.setFamily("Segoe Print")
        font.setPointSize(40)
        self.ClockLabel.setFont(font)
        self.ClockLabel.setStyleSheet("color: white")
        self.ClockLabel.setAlignment(QtCore.Qt.AlignCenter)
        self.ClockLabel.setObjectName("ClockLabel")

        #On/Off Button
        self.on_offButton = QtWidgets.QPushButton(self.centralwidget)
        self.on_offButton.setGeometry(QtCore.QRect(20, 20, 180, 125))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.on_offButton.setFont(font)
        self.on_offButton.setObjectName("on_offButton")

        #Brew Button
        self.brewButton = QtWidgets.QPushButton(self.centralwidget)
        self.brewButton.setGeometry(QtCore.QRect(280, 20, 180, 125))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.brewButton.setFont(font)
        self.brewButton.setObjectName("brewButton")

        #Clock Test Button
        self.clockTest = QtWidgets.QPushButton(self.centralwidget)
        self.clockTest.setGeometry(QtCore.QRect(20, 260, 150, 50))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.clockTest.setFont(font)
        self.clockTest.setObjectName("clockTest")

        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        #Connected the buttons to their callbacks
        self.on_offButton.clicked.connect(self.on_off_callback)
        self.brewButton.clicked.connect(self.brew_callback)
        self.clockTest.clicked.connect(self.clockTest_callback)
예제 #8
0
파일: bot1.py 프로젝트: z0921787301z/botnew
def lineBot(op):
    try:
        if op.type == 0:
            return
        if op.type == 13:
            print("[ 13 ] NOTIFIED INVITE INTO GRUUP")
            b = open("b.txt", "r")
            blackListedMid = b.readline()
            b.close()
            if op.param3 in MySelf.mid:
                client.acceptGroupInvitation(op.param1)
            if op.param3 in blackListedMid:
                client.cancelGroupInvitation(op.param1, [op.param3])
            else:
                pass
        if op.type == 19:
            print("[ 19 ] NOTIFIED KICKOUT FROM GROUP")
            if op.param3 == MySelf.mid:
                hb = open("hb.txt", "r")
                b = open("b.txt", "r")
                halfBlackListedMid = hb.readline()
                blackListedMid = b.readline()
                hb.close()
                b.close()
                if op.param2 not in halfBlackListedMid and op.param3 not in blackListedMid:
                    hb = open("hb.txt", "w")
                    hb.write(op.param2)
                    hb.close()
                elif op.param2 in halfBlackListedMid:
                    b = open("b.txt", "w")
                    b.write(op.param2)
                    b.close()
            else:
                if op.param3 in whiteListedMid:
                    if op.param2 not in whiteListedMid:
                        try:
                            client.kickoutFromGroup(op.param1, [op.param2])
                        except Exception as e:
                            print(e)
                    group = client.getGroup(op.param1)
                    if group.preventedJoinByTicket == True:
                        try:
                            group.preventedJoinByTicket = False
                            str1 = client.reissueGroupTicket(op.param1)
                            client.updateGroup(group)
                            client.sendMessage(
                                op.param3,
                                "/jgurlx gid: " + op.param1 + " gid " +
                                "url: http://line.me/R/ti/g/" + str1 + " url")
                        except Exception as e:
                            print(e)
                    else:
                        try:
                            str1 = client.reissueGroupTicket(op.param1)
                            client.updateGroup(group)
                            client.sendMessage(
                                op.param3,
                                "/jgurlx gid: " + op.param1 + " gid " +
                                "url: http://line.me/R/ti/g/" + str1 + " url")
                        except Exception as e:
                            print(e)
        if op.type == 26:
            print("[ 26 ] RECRIVE MESSAGE")
            msg = op.message
            try:
                if msg.contentType == 0:
                    try:
                        if msg.toType == 0:
                            print("\n")
                            print("Private Chat Message Received")
                            print("Sender's Name : " +
                                  client.getContact(msg._from).displayName)
                            print("Sender's MID : " + msg._from)
                            print("Received Message : " + msg.text)
                            print("\n")
                            if msg._from in whiteListedMid:
                                if msg.text.startswith("/jgurlx"):
                                    str1 = find_between_r(
                                        msg.text, "gid: ", " gid")
                                    str2 = find_between_r(
                                        msg.text,
                                        "url: http://line.me/R/ti/g/", " url")
                                    client.acceptGroupInvitationByTicket(
                                        str1, str2)
                                    JoinedGroups.append(str1)
                                    group = client.getGroup(str1)
                                    try:
                                        client.reissueGroupTicket(str1)
                                        group.preventedJoinByTicket = True
                                        client.updateGroup(group)
                                    except Exception as e:
                                        print(e)
                        else:
                            pass
                    except:
                        pass
                else:
                    pass
            except:
                pass
        if op.type == 25:
            print("[ 25 ] SEND MESSAGE")
            msg = op.message
            if msg.toType == 0:
                if msg.contentType == 0:
                    if msg.text == "speed":
                        start = time.time()
                        elapsed_time = time.time() - start
                        client.sendMessage(msg.to,
                                           format(str(elapsed_time)) + "秒")
                    elif msg.text == "mid":
                        client.sendMessage(msg.to, msg.to)
                    elif msg.text == "me":
                        client.sendMessage(msg.to,
                                           text=None,
                                           contentMetadata={'mid': msg._from},
                                           contentType=13)
                    elif msg.text == "you":
                        client.sendMessage(msg.to,
                                           text=None,
                                           contentMetadata={'mid': msg.to},
                                           contentType=13)
                else:
                    pass
            if msg.toType == 2:
                if msg.contentType == 0:
                    if msg.text == "invite bot":
                        group = client.getGroup(msg.to)
                        try:
                            group.preventedJoinByTicket = False
                            str1 = client.reissueGroupTicket(msg.to)
                            client.updateGroup(group)
                        except Exception as e:
                            print(e)
                        client.sendMessage(
                            "u58bc30a989f932d0fd73ccb847107779",
                            "/jgurl gid: " + msg.to + " gid " +
                            "url: http://line.me/R/ti/g/" + str1 + " url")
                        client.sendMessage(
                            "u2a3fb897b9e40c92a5962c43ec178006",
                            "/jgurl gid: " + msg.to + " gid " +
                            "url: http://line.me/R/ti/g/" + str1 + " url")
                        client.sendMessage(
                            "u0fcc0258ddc63ea6feea223e1a571445",
                            "/jgurl gid: " + msg.to + " gid " +
                            "url: http://line.me/R/ti/g/" + str1 + " url")
                        client.sendMessage(
                            "ud417ada62140fb51e46c19ec43b5681b",
                            "/jgurl gid: " + msg.to + " gid " +
                            "url: http://line.me/R/ti/g/" + str1 + " url")
                        client.sendMessage(
                            "ueaff862c8ef0202b937bb2203794ef4a",
                            "/jgurlx gid: " + msg.to + " gid " +
                            "url: http://line.me/R/ti/g/" + str1 + " url")
                    elif msg.text == "speed":
                        start = clock()
                        elapsed_time = clock() - start
                        client.sendMessage(msg.to,
                                           format(str(elapsed_time)) + "秒")
                    elif msg.text == "gcreator":
                        group = client.getGroup(msg.to)
                        gc = group.creator.mid
                        client.sendContact(msg.to, gc)
                    elif msg.text == "mid":
                        client.sendMessage(msg.to, msg._from)
                    elif msg.text == "gid":
                        client.sendMessage(msg.to, msg.to)
                    elif msg.text == "ginfo":
                        group = client.getGroup(msg.to)
                        md = "[群組名稱]\n" + group.name + "\n\n[gid]\n" + group.id + "\n\n[群組圖片]\nhttp://dl.profile.line-cdn.net/" + group.pictureStatus
                        if group.preventedJoinByTicket is False:
                            md += "\n\n行動網址: 開啟\n"
                        else:
                            md += "\n\n行動網址: 關閉\n"
                        if group.invitee is None:
                            md += "\n成員數: " + str(len(
                                group.members)) + "人\n\n邀請中: 0人"
                        else:
                            md += "\n成員數: " + str(len(
                                group.members)) + "人\n邀請中: " + str(
                                    len(group.invitee)) + "人"
                        client.sendMessage(msg.to, md)
                    elif msg.text == "me":
                        client.sendContact(msg.to, MySelf.mid)
                    elif msg.text == "/destroy":
                        print("start destroying")
                        botlist = [
                            "u2a3fb897b9e40c92a5962c43ec178006",
                            "u0fcc0258ddc63ea6feea223e1a571445",
                            "ud417ada62140fb51e46c19ec43b5681b",
                            "ueaff862c8ef0202b937bb2203794ef4a"
                        ]
                        _name = msg.text.replace("/destroy", "")
                        group = client.getGroup(msg.to)
                        targets = []
                        for g in group.members:
                            if _name in g.displayName:
                                targets.append(g.mid)
                        if targets == []:
                            client.leaveGroup(msg.to)
                        else:
                            for target in targets:
                                try:
                                    client.sendMessage(
                                        random.choice(botlist),
                                        "/kick gid: " + msg.to + " gid mid: " +
                                        target + " mid")
                                except:
                                    client.sendMessage(msg.to, "錯誤")
                    elif msg.text == "logout":
                        client.sendMessage(
                            "u58bc30a989f932d0fd73ccb847107779",
                            "/sm mid: " + msg.to + " mid text: 開始進行登出程序 text")
                        client.sendMessage(
                            "u2a3fb897b9e40c92a5962c43ec178006",
                            "/sm mid: " + msg.to + " mid text: 開始進行登出程序 text")
                        client.sendMessage(
                            "u0fcc0258ddc63ea6feea223e1a571445",
                            "/sm mid: " + msg.to + " mid text: 開始進行登出程序 text")
                        client.sendMessage(
                            "ud417ada62140fb51e46c19ec43b5681b",
                            "/sm mid: " + msg.to + " mid text: 開始進行登出程序 text")
                        client.sendMessage(
                            "ueaff862c8ef0202b937bb2203794ef4a",
                            "/sm mid: " + msg.to + " mid text: 開始進行登出程序 text")
                    elif msg.text == "報數":
                        client.sendMessage(
                            "u58bc30a989f932d0fd73ccb847107779",
                            "/sm mid: " + msg.to + " mid text: 1 text")
                        time.sleep(0.5)
                        client.sendMessage(
                            "u2a3fb897b9e40c92a5962c43ec178006",
                            "/sm mid: " + msg.to + " mid text: 2 text")
                        client.sendMessage(
                            "u0fcc0258ddc63ea6feea223e1a571445",
                            "/sm mid: " + msg.to + " mid text: 3 text")
                        client.sendMessage(
                            "ud417ada62140fb51e46c19ec43b5681b",
                            "/sm mid: " + msg.to + " mid text: 4 text")
                        client.sendMessage(
                            "ueaff862c8ef0202b937bb2203794ef4a",
                            "/sm mid: " + msg.to + " mid text: 5 text")
            else:
                pass
    except Exception as e:
        print(e)
예제 #9
0
 def show(self):
     self.clock = clock(1, self.get_data)
     self.app.display()