示例#1
0
文件: CLI.py 项目: subfusc/Verdande
class CLI:

    def __init__(self, db_file):
        self.db = DB(db_file)
        self.cli_re = re.compile(r'^\s*(?P<cmd>\S+)\s*(?P<nick>\S+)?\s*(?P<name>.+)?$')

    def help(self):
        print """
        new [nick [name]] Register new member with optional nick and name (will be prompted if not supplied)
        list              Show all members that are currently in the database
        quit              Exit the program
        help              Show this
        """
        
    def start(self):

        while True:
            try:
                inp = raw_input('[ Verdande ]$ ')

                match = self.cli_re.match(inp)
                if match:
                    cmd = match.group('cmd')
                    if cmd == 'new':
                        nick = match.group('nick') if match.group('nick') else raw_input('> Nick: ')
                        name = match.group('name') if match.group('name') else raw_input('> Full Name: ')
                        if not self.db.add_member(nick, name):
                            print "Member %s allready exist." % (nick)
                        else:
                            print "Successfully registered %s." % (nick)

                    elif cmd == 'list' or cmd == 'show':
                        print self.db

                    elif cmd == 'del':
                        if raw_input('are you root? ') == 'I always run as root!':
                            print "ok"
                            nick = match.group('nick') if match.group('nick') else raw_input('> Nick: ')
                            self.db.del_member(nick)
                        else:
                            print "No you're not!"
                            
                    elif cmd == 'quit':
                        answ = raw_input('Are you sure you want to quit [y/N]? ')
                        if answ == 'y' or answ == 'Y':
                            break

                    else:
                        self.help()
                        
            except EOFError:
                answ = raw_input('\nAre you sure you want to quit [y/N]? ')
                if answ == 'y' or answ == 'Y':
                    break

        self.db.close()
示例#2
0
文件: GUI.py 项目: subfusc/Verdande
class MainWindow(QtGui.QMainWindow):

    def __init__(self, file_path):
        super(MainWindow, self).__init__()

        self.db = DB(file_path)
        self.makeUI()
        
    def makeUI(self):
        add_box = QtGui.QVBoxLayout()
        button_box = QtGui.QHBoxLayout()
        
        nlabel = QtGui.QLabel('UiO Username: '******'Full Name: ')
        self.nedit = QtGui.QLineEdit()
        self.fnedit = QtGui.QLineEdit()
        abtn = QtGui.QPushButton('Add', self)
        cbtn = QtGui.QPushButton('Clear', self)

        abtn.clicked.connect(self.addClicked)
        cbtn.clicked.connect(self.clearClicked)
        
        button_box.addWidget(abtn)
        button_box.addWidget(cbtn)
        
        add_box.addWidget(nlabel)
        add_box.addWidget(self.nedit)
        add_box.addWidget(fnlabel)
        add_box.addWidget(self.fnedit)
        add_box.addLayout(button_box)

        cwidget = QtGui.QWidget()
        cwidget.setLayout(add_box)
        
        self.setCentralWidget(cwidget)
        self.statusBar()
        
        self.setGeometry(300, 300, 300, 150)
        self.setWindowTitle('Verdande :: Registration System')
        self.statusBar().showMessage('Ready')
        self.show()

        # perhaps grid.setSpacing(10)

    def addClicked(self):
        nick = self.nedit.text()
        name = self.fnedit.text()

        print len(name), name.indexOf(' ')
        
        if len(nick) <= 1:
            self.statusBar().showMessage('No username supplied.')
            return
        
        if len(name) < 4 or name.indexOf(' ') < 2:
            self.statusBar().showMessage('Not a real name or none supplied.')
            return
        
        if self.db.add_member(nick, name):
            self.nedit.clear()
            self.fnedit.clear()
            self.statusBar().showMessage('You where successfully added.')
        else:
            self.nedit.clear()
            self.fnedit.clear()
            self.statusBar().showMessage('You are already registered.')
            
    def clearClicked(self):
        self.nedit.clear()
        self.fnedit.clear()
        self.statusBar().showMessage('Clear!')