def button1_click(): if grp_name != entry1.get(): if (entry1.get() in self.user) or (entry1.get() in self.group) or ( entry1.get() == '*Add a group...'): label3_string.set('This name has already been taken.') return if entry1.get() == '': label3_string.set('Please enter the group name.') return chosen = [] for i in range(len(values)): if values[i].get() == 1: chosen.append(choices[i]) if chosen == []: label3_string.set('Please at least make a choice.') return chosen.append(self.name) msg = json.dumps({ "action": "edit_group", "from": self.name, 'member': chosen, 'new_name': entry1.get(), 'old_name': grp_name }) chat_utils.mysend(self.socket, msg) window.destroy()
def button3_click(): msg = json.dumps({ "action": "delete_group", "from": self.name, 'to': self.to }) chat_utils.mysend(self.socket, msg) window.destroy()
def add_point(self, point, home=True): if home: self.home_score.setText(str(int(self.home_score.text()) + point)) else: self.guest_score.setText(str(int(self.guest_score.text()) + point)) d = { "action": "broadcasting", "update": "scored", "point": point, "home": home } mysend(self.s, json.dumps(d)) self.repaint()
def post_message(self): if self.input_new_line.text() != "": detail = self.input_new_line.text() self.textBrowser.append("{}: {}".format(self.name, detail)) self.input_new_line.setText("") self.textBrowser.moveCursor(self.textBrowser.textCursor().End) d = { "action": "broadcasting", "update": "chat", "detail": detail, "from": self.name } mysend(self.s, json.dumps(d)) self.repaint()
def add_text(self): if self.input_time.text() != "" and self.input_new_line.text() != "": time = self.input_time.text() detail = self.input_new_line.text() self.textBrowser.append("{} : {}, {} : {}".format( time, detail, self.home_score.text(), self.guest_score.text())) self.time.setText(time) self.input_new_line.setText("") self.input_time.setText("") self.textBrowser.moveCursor(self.textBrowser.textCursor().End) self.repaint() d = { "action": "broadcasting", "update": "post", "time": time, "detail": detail } mysend(self.s, json.dumps(d))
def post_message(self): if self.input_new_line.text() != "": detail = self.input_new_line.text() if self.chance == 0: self.textBrowser.append('you are mute from hotline') else: if self.process(detail)[1]: self.chance -= 1 detail = self.process(detail)[0] self.textBrowser.append("{}: {}".format(self.name, detail)) self.input_new_line.setText("") self.textBrowser.moveCursor(self.textBrowser.textCursor().End) d = { "action": "broadcasting", "update": "chat", "detail": detail, "from": self.name } mysend(self.s, json.dumps(d)) self.repaint()
def start(self): home_team = self.home_name.text() guest_team = self.guest_name.text() if home_team != "" and guest_team != "": self.home_icon.setStyleSheet( "border-image: url(:/figure_lucy/{}.png);".format(home_team)) self.guest_icon.setStyleSheet( "border-image: url(:/figure_lucy/{}.png);".format(guest_team)) self.show_main() self.hide_create() d = { "action": "broadcasting", "update": "start", "home": home_team, "guest": guest_team } mysend(self.s, json.dumps(d)) else: QMessageBox.warning(self, "Warning", "Please select home/guest team before start.", QMessageBox.Ok) self.repaint()
def main(self): window = Toplevel() window.iconbitmap('logo.ico') window.title('Create a Group') frame1 = Frame(window) frame1.pack(anchor=W, padx=20, pady=20) label1 = Label(frame1, text='Group name:') label1.pack(side=LEFT, padx=5, pady=5) entry1 = Entry(frame1) entry1.pack(side=RIGHT, pady=5, padx=5) label2 = Label(window, text='Select members:') label2.pack(anchor=W, padx=25, pady=5) labelframe1 = LabelFrame(window) labelframe1.pack(padx=30, pady=5, fill=X) choices = [] for each in self.user: if each != self.name: choices.append(each) values = [] for each in choices: values.append(IntVar()) button = Checkbutton(labelframe1, text=each, variable=values[-1]) button.pack(anchor=W) def button1_click(): if (entry1.get() in self.user) or (entry1.get() in self.group) or ( entry1.get() == '*Add a group...'): label3_string.set('This name has already been taken.') return if entry1.get() == '': label3_string.set('Please enter the group name.') return chosen = [] for i in range(len(values)): if values[i].get() == 1: chosen.append(choices[i]) if chosen == []: label3_string.set('Please at least make a choice.') return chosen.append(self.name) msg = json.dumps({ "action": "create_group", "from": self.name, 'member': chosen, 'name': entry1.get() }) chat_utils.mysend(self.socket, msg) window.destroy() button1 = Button(window, text='Create_group', width=10, command=button1_click) button1.pack(pady=10) label3_string = StringVar() label3 = Label(window, textvariable=label3_string) label3.pack() label4 = Label(window) # only to take up position label4.pack() window.mainloop() msg = json.dumps({"action": "refresh_list", "from": self.name}) chat_utils.mysend(self.socket, msg)