Beispiel #1
0
 def __init__(self,host,port,listen_number):
     super(ChatServer,self).__init__()
     self.create_socket()
     self.set_reuse_addr()
     self.bind((host,port))
     self.listen(listen_number)
     self.chat_session = ChatSession()
     self.hall = Hall()
Beispiel #2
0
def sit_families(families: [Family], hall: Hall) -> bool:
    """
    Attempts to seat all families in the given `hall`.
    Returns true is successful, raises HallFullException otherwise.
    """
    for fam in families:
        print(f'Seating {fam}')
        hall.sit(fam)
    return True
class LoginWindow (QWidget):
    def __init__(self,director):
        QWidget.__init__(self)
        self.director = director
        self.ui = Ui_LoginWindow()
        self.ui.setupUi(self)
        self.connect(self.ui.loginButton,SIGNAL('clicked()'),self.onLoginButtonClickedEvent)

    def onLoginButtonClickedEvent(self):
        if self.director.clientThread == None:
            self.director.clientThread = ClientThread(self.director)
            client = Client(8,str(self.ui.ServerIPText.text()),self.ui.PortNumberText.text().toInt()[0],0.1,self.director.clientThread)
            self.director.clientThread.begin(client)
            self.director.connectSlotAndSignalWithServices()
        else:
            self.director.clientThread.client.close()
            self.director.clientThread.client.isAlive = False
            self.director.clientThread = ClientThread(self.director)
            client = Client(8,str(self.ui.ServerIPText.text()),self.ui.PortNumberText.text().toInt()[0],0.1,self.director.clientThread)
            self.director.clientThread.begin(client)
            print "get another client"
            self.director.connectSlotAndSignalWithServices()
        data = {}

        data['nickname'] = unicode(self.ui.NicknameText.text())
        data['password'] = unicode(self.ui.PasswordText.text())
        self.director.clientThread.client.sendToServer(1001,1001,data)
        self.director.playerNickname = data['nickname']

    def connectWithService(self):
        self.disconnect(self.director.clientThread.client.dispatcher.services[1001],\
                     SIGNAL('goToHallFromLoginWindow(bool,int,int)'),self.goToHallFromLoginWindow)
        self.disconnect(self.director.clientThread.client.dispatcher.services[1001],\
                     SIGNAL('loginFailed(QString)'),self.loginFailed)
        self.connect(self.director.clientThread.client.dispatcher.services[1001],\
                     SIGNAL('goToHallFromLoginWindow(bool,int,int)'),self.goToHallFromLoginWindow)
        self.connect(self.director.clientThread.client.dispatcher.services[1001],\
                     SIGNAL('loginFailed(QString)'),self.loginFailed)

    def goToHallFromLoginWindow(self,isFirstLogin,tableColNum,tableRowNum):
        print "Go To Hall From Login Window"
        if isFirstLogin:
            QMessageBox.about(None,u"欢迎光临",u"欢迎第一次登陆")
        else:
            QMessageBox.about(None,u'欢迎光临',u"欢迎再次登陆")
        self.close()
        print "Type self director:",self.director
        self.hall = Hall(tableRowNum,tableColNum,self.director )
        self.hall.show()

    def loginFailed(self,errorString):
        QMessageBox.about(None,u"登陆失败!",errorString)
 def goToHallFromLoginWindow(self,isFirstLogin,tableColNum,tableRowNum):
     print "Go To Hall From Login Window"
     if isFirstLogin:
         QMessageBox.about(None,u"欢迎光临",u"欢迎第一次登陆")
     else:
         QMessageBox.about(None,u'欢迎光临',u"欢迎再次登陆")
     self.close()
     print "Type self director:",self.director
     self.hall = Hall(tableRowNum,tableColNum,self.director )
     self.hall.show()
Beispiel #5
0
def main(args):
    families_csv_path, rows_csv_path = get_csv_paths(args)

    # Read csv files
    families = read_csv(families_csv_path, Family)
    families.sort(key=lambda f: f.size, reverse=True)
    hall = Hall(rows_csv_path)

    print('Found the following families:')
    print(*families, '\n', sep='\n')
    print(hall)

    # Seating loop
    families_are_sitting = False
    try_num = 0
    while not families_are_sitting:
        try_num += 1
        try:
            if sit_families(families, hall):
                families_are_sitting = True
        except HallFullException as e:
            print(e)
            hall.reset()
            if try_num % NUM_TRIES_BEFORE_WARN == 0 and args.use_gui:
                to_continue = easygui.boolbox(
                    msg=f'I wasn\'t able to find a suitable seating '
                    f'arangement in {try_num} tries. This is either '
                    'because I was unluck and I need to try a couple '
                    'more times, or no possible seating arangements exist.'
                    '\n\n Would you like to continue trying?')
                if not to_continue:
                    quit()

    output_path = get_output_path(args)
    hall.to_csv(output_path)
Beispiel #6
0
class ChatServer(asyncore.dispatcher):
    def __init__(self,host,port,listen_number):
        super(ChatServer,self).__init__()
        self.create_socket()
        self.set_reuse_addr()
        self.bind((host,port))
        self.listen(listen_number)
        self.chat_session = ChatSession()
        self.hall = Hall()

    def handle_accepted(self, sock, addr):
        print("{addr}连接进来".format(addr = addr))
        handler = ChatHandler(sock)
        self.hall.Login(sock)
Beispiel #7
0
import tornado.ioloop
import tornado.web
import os
import argparse

from Hall import Hall
from Hall import GameRoom
from Hall import User

hall = Hall()


class BaseHandler(tornado.web.RequestHandler):
    def get_current_user(self):
        return self.get_secure_cookie("username")


class ChessHandler(BaseHandler):
    def get_post(self):
        info_ = ""
        user = hall.get_user_with_uid(self.current_user)
        room = user.game_room
        chess_board = room.board if room else None
        self.render(
            "page/chessboard.html",
            username=self.current_user,
            room=room,
            chess_board=chess_board,
            user=user,
        )
Beispiel #8
0
from Hall import Hall
li=[]
n = int(input("Enter the number of Entries\n"))
for i in range(0, n):
    print("Enter details of Hall %d" % (i + 1))
    name = input("Enter Hall name\n")
    phno = int(input("Enter Phone\n"))
    addr = input("Enter Address\n")
    date = input("Enter Date of booking\n")
    cost = float(input("Enter cost\n"))
    oname = input("Enter owner name\n")
    p = Hall(name, phno, addr, date, cost, oname)
    li.append(p)
Beispiel #9
0
    def getDataFromPageThree(self):
        lines = self.file.readlines()
        reached_side_three = False
        general_bool = True
        hall_bool = False
        kitchen_bool = False
        toilet_bool = False
        living_room_bool = False
        room_1_bool = False
        room_2_bool = False
        general_data = General()
        hall_data = Hall()
        kitchen_data = Kitchen()
        toilet_data = Toilet()
        living_room_data = Room()
        room_1_data = Room()
        room_2_data = Room()
        for index, line in enumerate(lines):
            if "Side 3 - Tilstand, vedligeholdelse" in line:
                reached_side_three = True

            if reached_side_three:
                if general_bool:
                    if "Eltavle" in line:
                        general_data.eltavle = self.create_content(line)

                    if "HFI" in line:
                        general_data.hfi = self.create_content(line)

                    if "Stik, afbrydere og udtag" in line:
                        general_data.stik = self.create_content(line)

                    if "vinduer og ruder" in line.lower():
                        general_data.vinduer = self.create_content(line)

                    if "Vedligeholdelse:" in line:
                        general_data.vedligeholdse = self.create_content(line)

                    if "Rydning" in line:
                        general_data.rydning = self.create_content(line)

                    if "Rengøring" in line:
                        general_data.rengøring = self.create_content(line)
                        general_bool = False
                        hall_bool = True

                if hall_bool:
                    if "Loft" in line:
                        hall_data.loft = self.create_content(line)
                    if "Vægge" in line:
                        hall_data.vægge = self.create_content(line)
                    if "Gulv" in line:
                        hall_data.gulv = self.create_content(line)
                    if "Træværk" in line:
                        hall_data.træværk = self.create_content(line)
                        hall_bool = False
                        kitchen_bool = True

                if kitchen_bool:
                    if "Loft" in line:
                        kitchen_data.Loft = self.create_content(line)
                    if "Vægge" in line:
                        kitchen_data.Vægge = self.create_content(line)
                    if "Gulv" in line:
                        kitchen_data.Gulv = self.create_content(line)
                    if "Træværk" in line:
                        kitchen_data.Træværk = self.create_content(line)
                    if "Skabe" in line:
                        kitchen_data.Skabe = self.create_content(line)
                    if 'Bordplader' in line:
                        kitchen_data.Bordplader = self.create_content(line)
                    if 'Vægfliser' in line:
                        kitchen_data.Vægfliser = self.create_content(line)
                    if 'Afløbsinstallation' in line:
                        kitchen_data.Afløbsinstallation = self.create_content(
                            line)
                    if 'Vandinstallation' in line:
                        kitchen_data.Vandinstallation = self.create_content(
                            line)
                    if 'Gasinstallation' in line:
                        kitchen_data.Gasinstallation = self.create_content(
                            line)
                    if 'Hårde hvidevarer' in line:
                        kitchen_data.Hvidevarer = self.create_content(line)
                        kitchen_bool = False
                        toilet_bool = True

                if toilet_bool:
                    if "Loft" in line:
                        toilet_data.Loft = self.create_content(line)
                    if "Vægge" in line:
                        toilet_data.Vægge = self.create_content(line)
                    if "Gulv" in line:
                        toilet_data.Gulv = self.create_content(line)
                    if "Træværk" in line:
                        toilet_data.Træværk = self.create_content(line)
                    if "WC" in line:
                        toilet_data.WC = self.create_content(line)
                    if "Håndvask" in line:
                        toilet_data.Håndvask = self.create_content(line)
                    if "Bruseinstallation" in line:
                        toilet_data.Bruseinstallation = self.create_content(
                            line)
                    if "Vandinstallation" in line:
                        toilet_data.Vandinstallation = self.create_content(
                            line)
                    if "Afløbsinstallation" in line:
                        toilet_data.Afløbsinstallation = self.create_content(
                            line)
                    if "Ventilation" in line:
                        toilet_data.Ventilation = self.create_content(line)
                        toilet_bool = False
                        room_1_bool = True

                if room_1_bool:
                    if "Værelse" in line:
                        room_1_data.title = line.replace('\n', '')
                    if "Loft" in line:
                        room_1_data.loft = self.create_content(line)
                    if "Vægge" in line:
                        room_1_data.vægge = self.create_content(line)
                    if "Gulv" in line:
                        room_1_data.gulv = self.create_content(line)
                    if "Træværk" in line:
                        room_1_data.træværk = self.create_content(line)
                    if "Radiator" in line:
                        room_1_data.radiator = self.create_content(line)
                        room_1_bool = False
                        room_2_bool = True

                if room_2_bool:
                    if "Værelse" in line:
                        room_2_data.title = line.replace('\n', '')
                    if "Loft" in line:
                        room_2_data.loft = self.create_content(line)
                    if "Vægge" in line:
                        room_2_data.vægge = self.create_content(line)
                    if "Gulv" in line:
                        room_2_data.gulv = self.create_content(line)
                    if "Træværk" in line:
                        room_2_data.træværk = self.create_content(line)
                    if "Radiator" in line:
                        room_2_data.radiator = self.create_content(line)

                if 'Stue' in line or living_room_bool:
                    living_room_bool = True
                    if "Stue" in line:
                        living_room_data.title = line.replace('\n', '')
                    if "Loft" in line:
                        living_room_data.loft = self.create_content(line)
                    if "Vægge" in line:
                        living_room_data.vægge = self.create_content(line)
                    if "Gulv" in line:
                        living_room_data.gulv = self.create_content(line)
                    if "Træværk" in line:
                        living_room_data.træværk = self.create_content(line)
                    if "Radiator" in line:
                        living_room_data.radiator = self.create_content(line)
                        living_room_bool = False
                        room_1_bool = True

        list_of_content = [
            general_data, hall_data, kitchen_data, toilet_data,
            living_room_data, room_1_data, room_2_data
        ]
        return list_of_content
        self.sock = sock
        self.client_name = client_name


SERVER_HOST = '0.0.0.0'
SERVER_PORT = 8000

# Create socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_socket.bind((SERVER_HOST, SERVER_PORT))
server_socket.listen(1)
print('Listening on port %s ...' % SERVER_PORT)

clients = []
hall = Hall('#general')


def handle_client(client):
    while True:
        # Recebe mensagem do cliente
        msg = client.sock.recv(1024).decode()

        if msg == 'exit':
            goodbyeMsg = 'exit'
            client.sock.sendall(goodbyeMsg.encode())

            name = client.client_name
            clients.remove(client)
            hall.remove_client(client)
            leaveMsg = name + ' has left the chat'
Beispiel #11
0
from Hall import Hall
import datetime
d1 = input("Enter Start time \n")
d2 = input("Enter the End time\n")
cost = int(input("Enter the cost per day\n"))
startdate = datetime.datetime.strptime(d1, '%b %d %Y').date()
enddate = datetime.datetime.strptime(d2, '%b %d %Y').date()
p = Hall(startdate, enddate, cost)
p.noDays()
p.cost(cost)