def create_widgets(self): self.cycles_frame = ScrollableFrame(self, background=BG) self.cycles_list = tk.Frame( self.cycles_frame.scrollable_frame, background=BG) self.cycles_list.grid(row=0, column=0, sticky=tk.E+tk.W) self.cycles_list.columnconfigure(0, weight=1) cycle = Cycle(self.cycles_list, borderwidth=1, relief='raised') self.cycles.append(cycle) cycle.grid(row=0, column=0, pady=(0, 16), sticky=tk.E+tk.W) cycles_buttons = tk.Frame( self.cycles_frame.scrollable_frame, background=BG) cycles_buttons.grid(row=1, column=0, pady=(16, 24)) tk.Button( cycles_buttons, text='+ Step', highlightbackground=BG, command=self.add_step, ).grid(row=0, column=0) self.run_button = tk.Button( cycles_buttons, text='Run Program', highlightbackground=BG, font=tkFont.Font(weight='bold'), command=self.run_program) self.run_button.grid(row=0, column=1, ipady=6) self.cycles_frame.grid(row=0, column=0, sticky=tk.N+tk.E+tk.S+tk.W) self.cycles_frame.scrollable_frame.columnconfigure(0, weight=1) self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1)
def settings(): win = Toplevel() win.title('Nastavení') win.minsize(900, 700) win.maxsize(900, 700) # bottom frame bottom_frame = Frame(win) apply_button = Button(bottom_frame, text="Uložit", width=6, command=win.destroy).pack(side=RIGHT) cancel_button = Button(bottom_frame, text="Zrušit", width=6, command=win.destroy).pack(side=RIGHT) ok_button = Button(bottom_frame, text="OK", width=6, command=win.destroy).pack(side=RIGHT) bottom_frame.pack(side=BOTTOM, fill=BOTH) # right frame right_frame_main = ScrollableFrame(win) right_frame = right_frame_main.scrollable_frame # draw general settings window general_draw(right_frame) right_frame_main.pack(side=RIGHT, expand=1, fill=BOTH) # left frame left_frame = Frame(win, highlightthickness=1, highlightbackground="grey") general_button = Button(left_frame, text="Obecné", width=10, command=lambda: general_draw(right_frame)).pack() stream_button = Button(left_frame, text="Stream", width=10, command=lambda: stream_draw(right_frame)).pack() output_button = Button(left_frame, text="Výstup", width=10, command=lambda: output_draw(right_frame)).pack() audio_button = Button(left_frame, text="Audio", width=10, command=lambda: audio_draw(right_frame)).pack() video_button = Button(left_frame, text="Video", width=10, command=lambda: video_draw(right_frame)).pack() advanced_button = Button( left_frame, text="Pokročilé", width=10, command=lambda: advanced_draw(right_frame)).pack() left_frame.pack(side=LEFT, fill=Y, padx=10, pady=10)
def __init__(self, parent, name, palette, sidebar_width, *args, **kwargs): """Do things in build_selection_list_frame""" logg = logging.getLogger(f"c.{__class__.__name__}.init") logg.info("Start init") self.name = name self.palette = palette self.sidebar_width = sidebar_width # frame background color self.back_col = self.palette.get_colors(f"background.{self.name}") # header background color self.back_col_header = ( self.palette.get_colors("background.header.selection_list"), ) # ScrollableFrame colors self.back_col_scrollable = self.palette.get_colors( "background.scrollable.selection_list") self.hover_col_scrollable = self.palette.get_colors( "hover.scrollable.selection_list") self.slider_col_scrollable = self.palette.get_colors( "slider.scrollable.selection_list") # ThumbButton colors self.back_col_thumbbtn = self.palette.get_colors( "background.thumbbtn.selection_list") self.hover_back_col_thumbbtn = self.palette.get_colors( "hover.thumbbtn.selection_list") self.back_col_bis_thumbbtn = self.palette.get_colors( "backgroundbis.thumbbtn.selection_list") super().__init__(parent, background=self.back_col, *args, **kwargs) self.selection_list_frame_header = tk.Label( self, text="Selection list:", background=self.back_col_header) # ScrollableFrame that holds the ThumbButtons self.selection_list_scrollable = ScrollableFrame( self, scroll_width=self.sidebar_width, back_col=self.back_col_scrollable, hover_back_col=self.hover_col_scrollable, slider_col=self.slider_col_scrollable, ) # setup grid in selection_list_frame self.grid_rowconfigure(1, weight=1) self.grid_columnconfigure(0, weight=1) # grid static elements self.selection_list_frame_header.grid(row=0, column=0, sticky="ew") self.selection_list_scrollable.grid(row=1, column=0, sticky="nsew") # dicts for runtime elements self.selection_list_thumbbtn = {}
def test_scrollable_frame(): root = tk.Tk() # the row expands root.grid_rowconfigure(0, weight=1) # the first column expands root.grid_columnconfigure(0, weight=1) # the second column is fixed (set only for clarity) root.grid_columnconfigure(1, weight=0) # create the ScrollableFrame, with a set width scroll_width = 200 scroll = ScrollableFrame(root, scroll_width=scroll_width) scroll.grid(row=0, column=1, sticky="ns") # the main windows is here, this does expand 'ew' filler = tk.Frame(root, bg="blue", width=100) filler.grid(row=0, column=0, sticky="nsew") labels = [] for i in range(30): new_label = tk.Label( scroll.scroll_frame, text=f"Label created at row {i}", background="orange", ) new_label.grid(row=i, column=0, sticky="ew") # add bindings for mouse scrolling new_label.bind("<4>", scroll.on_list_scroll) new_label.bind("<5>", scroll.on_list_scroll) new_label.bind("<MouseWheel>", scroll.on_list_scroll) labels.append(new_label) # if the labels do not cover the entire canvas, some of these might work # scroll.bind("<4>", scroll.on_list_scroll) # scroll.bind("<5>", scroll.on_list_scroll) # scroll.bind("<MouseWheel>", scroll.on_list_scroll) # scroll.scroll_canvas.bind("<4>", scroll.on_list_scroll) # scroll.scroll_canvas.bind("<5>", scroll.on_list_scroll) # scroll.scroll_canvas.bind("<MouseWheel>", scroll.on_list_scroll) # scroll.scroll_frame.bind("<4>", scroll.on_list_scroll) # scroll.scroll_frame.bind("<5>", scroll.on_list_scroll) # scroll.scroll_frame.bind("<MouseWheel>", scroll.on_list_scroll) root.mainloop()
def get_windows(width: int, history: List[Dict[str, int]], deficiencies: List[Tuple[str, int]], names: List[str]) -> tk.Tk: """ Create tkinter window :param width: length of processes :param history: list of histories :param deficiencies: list of rewounds :param names: names of algorithms :return: """ # creating root root = tk.Tk() wd = str(width * 50) root.geometry(f'{wd}x500') # main frame of app main_frame = ScrollableFrame(root) main_frame.pack(expand=True, fill='both') # drawing all history in canvas draw_all(history, deficiencies, names, main_frame.frame) return root
def __init__(self, optimizer, parent, controller): tk.Frame.__init__(self, parent) #prepares player dataframe used throughout frame self.player_master = optimizer.player_master.filter( ['position', 'name', 'team', 'salary', 'ppg_projection', 'value']) #declares scrollable frame for excl and lock buttons #borrows from class found online player_frame = ScrollableFrame(self, 420, 400) player_frame.grid(column=0, row=1, padx=10, pady=(0, 10), rowspan=3) #adds excl and lock labels tk.Label(self, text='Excl | Lock').grid(column=0, row=0, sticky='sw', padx=4, pady=(10, 0)) #creates and places lock and exclusion buttons self.excl_buttons = {} self.lock_buttons = {} self.excl_vars = {} self.lock_vars = {} for i, player in enumerate(self.player_master.index): #excl buttons self.excl_vars[player] = tk.IntVar() self.excl_vars[player].set(0) self.excl_buttons[player] = ttk.Checkbutton( player_frame.scrollable_frame, variable=self.excl_vars[player], command=lambda x=player: self.toggle_excl(x)) self.excl_buttons[player].grid(row=i, column=0) #lock buttons self.lock_vars[player] = tk.IntVar() self.lock_vars[player].set(0) self.lock_buttons[player] = ttk.Checkbutton( player_frame.scrollable_frame, variable=self.lock_vars[player], command=lambda x=player: self.toggle_lock(x)) self.lock_buttons[player].grid(row=i, column=1) #adds labels to scrollframe with player info player_labels = {} self.player_text = self.player_master.to_string( header=False, index=False, justify='right').splitlines() for i in range(len(self.player_master.index)): player_labels[i] = tk.Label(player_frame.scrollable_frame, text=self.player_text[i], anchor='w', font=('Consolas', 11), bg='white') player_labels[i].grid(column=3, row=i, sticky='w') #adds text box for exluded players tk.Label(self, text="Excluded:", font=('Calibri', 11)).grid(row=0, column=1, sticky='sw') self.excl_text = tk.Text(self, height=10, width=50, state=tk.DISABLED) self.excl_text.grid(row=1, column=1, sticky='ns', padx=(0, 10)) e_scroll = ttk.Scrollbar(self, command=self.excl_text.yview) e_scroll.grid(row=1, column=1, sticky='nse', padx=(0, 10)) self.excl_text['yscrollcommand'] = e_scroll.set #adds text box for locked players tk.Label(self, text="Locked:", font=('Calibri', 11)).grid(row=2, column=1, sticky='sw') self.lock_text = tk.Text(self, height=10, width=50, state=tk.DISABLED) self.lock_text.grid(row=3, column=1, sticky='ns', pady=(0, 10), padx=(0, 10)) l_scroll = ttk.Scrollbar(self, command=self.lock_text.yview) l_scroll.grid(row=3, column=1, sticky='nse', pady=(0, 10), padx=(0, 10)) self.lock_text['yscrollcommand'] = l_scroll.set #dataframes to be converted to string in toggle functions self.excl_df = pd.DataFrame() self.lock_df = pd.DataFrame()
def draw_personal_route(personalized_route): # Окно персонализированного маршрута main_window = Toplevel(root) main_window.minsize(width=550, height=700) route_header_frame = Frame(main_window, highlightbackground="#c7c7c7", highlightthickness=1) route_header_frame.pack(side=TOP, pady=4) destinations_text_label = Label(route_header_frame, text='{} - {}'.format( personalized_route.point_a, personalized_route.point_b), font='Roboto 14 bold') destinations_text_label.pack(side=TOP) distance_text_label = Label(route_header_frame, text='Дистанция - {}'.format( personalized_route.distance), font='Roboto 12 underline') distance_text_label.pack() time_text_label = Label(route_header_frame, text='Время - {}'.format(personalized_route.time), font='Roboto 12') time_text_label.pack() route_type_text_label = Label(route_header_frame, text='Тип маршрута - {}'.format( personalized_route.kind), font='Roboto 12') route_type_text_label.pack() route_frame = Frame(main_window, highlightbackground="#c7c7c7", highlightthickness=2) route_frame.pack(expand=1, fill=BOTH, pady=4, padx=4) frame = ScrollableFrame(route_frame) for place_to_draw in personalized_route.route: place_frame = Frame(frame.scrollable_frame, highlightbackground="#0093c4", highlightthickness=2) place_frame.pack() name_text_label = Label(frame.scrollable_frame, text=place_to_draw.name, font='Roboto 13 bold', justify=LEFT) name_text_label.pack() description_text_label = Message(frame.scrollable_frame, text=place_to_draw.description, font='Roboto 11') description_text_label.pack() kind_text_label = Label(frame.scrollable_frame, text=place_to_draw.kind, font='Roboto 11 underline', justify=LEFT) kind_text_label.pack() address_text_label = Message(frame.scrollable_frame, text=place_to_draw.address, font='Roboto 12', justify=LEFT) address_text_label.pack() working_hours_text_label = Label(frame.scrollable_frame, text='Работает: {}'.format( place_to_draw.working_hours), font='Roboto 11', justify=LEFT) working_hours_text_label.pack() frame.pack(expand=1, fill=BOTH)
def __init__(self, parent, name, palette, sidebar_width, *args, **kwargs): """Do things in build_photo_list_frame""" logg = logging.getLogger(f"c.{__class__.__name__}.init") logg.info("Start init") self.name = name self.palette = palette self.back_col = self.palette.get_colors(f"background.{self.name}") self.back_col_header = ( self.palette.get_colors("background.header.photo_list"), ) self.back_col_scrollable = self.palette.get_colors( "background.scrollable.photo_list") self.hover_col_scrollable = self.palette.get_colors( "hover.scrollable.photo_list") self.slider_col_scrollable = self.palette.get_colors( "slider.scrollable.photo_list") self.back_col_thumbbtn = self.palette.get_colors( "background.thumbbtn.photo_list") self.hover_back_col_thumbbtn = self.palette.get_colors( "hover.thumbbtn.photo_list") self.back_col_bis_thumbbtn = self.palette.get_colors( "backgroundbis.thumbbtn.photo_list") super().__init__(parent, background=self.back_col, *args, **kwargs) # save width of sidebar, needed to explicitly set ScrollableFrame self.sidebar_width = sidebar_width self.photo_list_frame_header = tk.Label( self, text="Photo list:", background=self.back_col_header) # TODO reimplement the whole thing: manually change the TB you show # ask for new PhotoInfo when needed, so that they do not have to be all # loaded; bind configure of photo_list_frame to compute how many TB # have to be available; bind scroll (from the Scrollbar as well?) to a # call in the model to update the list of TB, and show just them # this is mainly needed because this frame can only hold a puny 1000ish # photo list; that's like one week of vacation. # ScrollableFrame that holds the ThumbButtons self.photo_list_scrollable = ScrollableFrame( self, scroll_width=self.sidebar_width, back_col=self.back_col_scrollable, hover_back_col=self.hover_col_scrollable, slider_col=self.slider_col_scrollable, ) # setup grid in photo_list_frame (this widget) self.grid_rowconfigure(1, weight=1) self.grid_columnconfigure(0, weight=1) # grid static elements self.photo_list_frame_header.grid(row=0, column=0, sticky="ew") self.photo_list_scrollable.grid(row=1, column=0, sticky="nsew") # dicts for runtime elements self.photo_list_thumbbtn = {} self.current_photo_prim = ""
class PhotoListFrame(ThumbButtonList): def __init__(self, parent, name, palette, sidebar_width, *args, **kwargs): """Do things in build_photo_list_frame""" logg = logging.getLogger(f"c.{__class__.__name__}.init") logg.info("Start init") self.name = name self.palette = palette self.back_col = self.palette.get_colors(f"background.{self.name}") self.back_col_header = ( self.palette.get_colors("background.header.photo_list"), ) self.back_col_scrollable = self.palette.get_colors( "background.scrollable.photo_list") self.hover_col_scrollable = self.palette.get_colors( "hover.scrollable.photo_list") self.slider_col_scrollable = self.palette.get_colors( "slider.scrollable.photo_list") self.back_col_thumbbtn = self.palette.get_colors( "background.thumbbtn.photo_list") self.hover_back_col_thumbbtn = self.palette.get_colors( "hover.thumbbtn.photo_list") self.back_col_bis_thumbbtn = self.palette.get_colors( "backgroundbis.thumbbtn.photo_list") super().__init__(parent, background=self.back_col, *args, **kwargs) # save width of sidebar, needed to explicitly set ScrollableFrame self.sidebar_width = sidebar_width self.photo_list_frame_header = tk.Label( self, text="Photo list:", background=self.back_col_header) # TODO reimplement the whole thing: manually change the TB you show # ask for new PhotoInfo when needed, so that they do not have to be all # loaded; bind configure of photo_list_frame to compute how many TB # have to be available; bind scroll (from the Scrollbar as well?) to a # call in the model to update the list of TB, and show just them # this is mainly needed because this frame can only hold a puny 1000ish # photo list; that's like one week of vacation. # ScrollableFrame that holds the ThumbButtons self.photo_list_scrollable = ScrollableFrame( self, scroll_width=self.sidebar_width, back_col=self.back_col_scrollable, hover_back_col=self.hover_col_scrollable, slider_col=self.slider_col_scrollable, ) # setup grid in photo_list_frame (this widget) self.grid_rowconfigure(1, weight=1) self.grid_columnconfigure(0, weight=1) # grid static elements self.photo_list_frame_header.grid(row=0, column=0, sticky="ew") self.photo_list_scrollable.grid(row=1, column=0, sticky="nsew") # dicts for runtime elements self.photo_list_thumbbtn = {} self.current_photo_prim = "" def update_photo_list(self, photo_list_info): """Receives a dict of PhotoInfo object and creates ThumbButton photo_list_info = { pic : PhotoInfo } """ logg = logging.getLogger(f"c.{__class__.__name__}.update_photo_list") # logg.setLevel("TRACE") logg.info("Updating photo_list ThumbButton") for pic in self.photo_list_thumbbtn: self.photo_list_thumbbtn[pic].grid_forget() for ri, pic in enumerate(photo_list_info): # create the new ThumbButton if pic not in self.photo_list_thumbbtn: self.photo_list_thumbbtn[pic] = ThumbButton( self.photo_list_scrollable.scroll_frame, photo_list_info[pic], back_col=self.back_col_thumbbtn, hover_back_col=self.hover_back_col_thumbbtn, back_col_bis=self.back_col_bis_thumbbtn, ) # bind enter/leave event to highlight self.photo_list_thumbbtn[pic].bind("<Enter>", self.on_thumbbtn_enter) self.photo_list_thumbbtn[pic].bind("<Leave>", self.on_thumbbtn_leave) # bind scroll function to ThumbButton elements self.photo_list_thumbbtn[pic].register_scroll_func( self.photo_list_scrollable.on_list_scroll) # add event for doubleclick self.photo_list_thumbbtn[pic].bind_doubleclick( self.on_photo_list_doubleclick) # highlight current photo primary if pic == self.current_photo_prim: logg.trace(f"Setting color mode BIS for '{pic}' ThumbButton") self.photo_list_thumbbtn[pic].set_back_col_mode("BIS") else: self.photo_list_thumbbtn[pic].set_back_col_mode("FIRST") # grid the ThumbButton self.photo_list_thumbbtn[pic].grid(row=ri, column=0, sticky="ew") logg.trace(f"Loaded thbtn {self.photo_list_thumbbtn.keys()}") def on_photo_list_doubleclick(self, event): """Handle double clicks on photo list, go to that pic MAYBE better binding of this event in ThumbButton, bind the double click to some virtual events raised, then bind the virtual event on the ThumbButton top widget, so that the callback can access event.widget directly on the ThumbButton, instead of event.widget.master """ logg = logging.getLogger( f"c.{__class__.__name__}.on_photo_list_doubleclick") # logg.setLevel("TRACE") logg.debug("Doublecliked something") logg.trace( f"Event {event} fired by {event.widget} master {event.widget.master}" ) self.photo_doubleclicked = event.widget.master.photo_info.photo_name_full logg.trace(f"photo_doubleclicked {self.photo_doubleclicked}") self.event_generate("<<thumbbtn_photo_doubleclick>>") def update_current_photo_prim(self, pic): logg = logging.getLogger( f"c.{__class__.__name__}.update_current_photo_prim") # logg.setLevel("TRACE") logg.trace("Update current_photo_prim") if self.current_photo_prim != "": self.photo_list_thumbbtn[ self.current_photo_prim].set_back_col_mode("FIRST") self.photo_list_thumbbtn[pic].set_back_col_mode("BIS") self.current_photo_prim = pic
class SelectionListFrame(ThumbButtonList): def __init__(self, parent, name, palette, sidebar_width, *args, **kwargs): """Do things in build_selection_list_frame""" logg = logging.getLogger(f"c.{__class__.__name__}.init") logg.info("Start init") self.name = name self.palette = palette self.sidebar_width = sidebar_width # frame background color self.back_col = self.palette.get_colors(f"background.{self.name}") # header background color self.back_col_header = ( self.palette.get_colors("background.header.selection_list"), ) # ScrollableFrame colors self.back_col_scrollable = self.palette.get_colors( "background.scrollable.selection_list") self.hover_col_scrollable = self.palette.get_colors( "hover.scrollable.selection_list") self.slider_col_scrollable = self.palette.get_colors( "slider.scrollable.selection_list") # ThumbButton colors self.back_col_thumbbtn = self.palette.get_colors( "background.thumbbtn.selection_list") self.hover_back_col_thumbbtn = self.palette.get_colors( "hover.thumbbtn.selection_list") self.back_col_bis_thumbbtn = self.palette.get_colors( "backgroundbis.thumbbtn.selection_list") super().__init__(parent, background=self.back_col, *args, **kwargs) self.selection_list_frame_header = tk.Label( self, text="Selection list:", background=self.back_col_header) # ScrollableFrame that holds the ThumbButtons self.selection_list_scrollable = ScrollableFrame( self, scroll_width=self.sidebar_width, back_col=self.back_col_scrollable, hover_back_col=self.hover_col_scrollable, slider_col=self.slider_col_scrollable, ) # setup grid in selection_list_frame self.grid_rowconfigure(1, weight=1) self.grid_columnconfigure(0, weight=1) # grid static elements self.selection_list_frame_header.grid(row=0, column=0, sticky="ew") self.selection_list_scrollable.grid(row=1, column=0, sticky="nsew") # dicts for runtime elements self.selection_list_thumbbtn = {} def update_selection_list(self, selection_list_info): """Receives a dict of PhotoInfo object and creates ThumbButton There is also info on whether the pic is still selected selection_list_info = { pic : (PhotoInfo, is_selected) } """ logg = logging.getLogger( f"c.{__class__.__name__}.update_selection_list") # logg.setLevel("TRACE") logg.info("Updating selection_list ThumbButtons") for pic in self.selection_list_thumbbtn: self.selection_list_thumbbtn[pic].grid_forget() for ri, pic in enumerate(selection_list_info): # extract values photo_info = selection_list_info[pic][0] is_selected = selection_list_info[pic][1] # create the new ThumbButton if pic not in self.selection_list_thumbbtn: self.selection_list_thumbbtn[pic] = ThumbButton( self.selection_list_scrollable.scroll_frame, photo_info, back_col=self.back_col_thumbbtn, hover_back_col=self.hover_back_col_thumbbtn, back_col_bis=self.back_col_bis_thumbbtn, ) # bind enter/leave event to highlight self.selection_list_thumbbtn[pic].bind("<Enter>", self.on_thumbbtn_enter) self.selection_list_thumbbtn[pic].bind("<Leave>", self.on_thumbbtn_leave) # bind scroll function to ThumbButton elements self.selection_list_thumbbtn[pic].register_scroll_func( self.selection_list_scrollable.on_list_scroll) # add event for doubleclick self.selection_list_thumbbtn[pic].bind_doubleclick( self.on_selection_list_doubleclick) # set selected photo to FIRST, de-selected to BIS color_mode if is_selected: self.selection_list_thumbbtn[pic].set_back_col_mode("FIRST") else: self.selection_list_thumbbtn[pic].set_back_col_mode("BIS") self.selection_list_thumbbtn[pic].grid(row=ri, column=0, sticky="ew") def on_selection_list_doubleclick(self, event): logg = logging.getLogger( f"c.{__class__.__name__}.on_selection_list_doubleclick") # logg.setLevel("TRACE") logg.debug("Doublecliked something in selection list") logg.trace( f"Event {event} fired by {event.widget} master {event.widget.master}" ) self.selection_doubleclicked = event.widget.master.photo_info.photo_name_full logg.trace(f"selection_doubleclicked {self.selection_doubleclicked}") self.event_generate("<<thumbbtn_selection_doubleclick>>")
class Program(tk.Frame): def __init__(self, master, on_run, camera_direction, **kwargs): tk.Frame.__init__(self, master, **kwargs) self.on_run = on_run self.camera_direction = camera_direction self.cycles = [] self.create_widgets() def create_widgets(self): self.cycles_frame = ScrollableFrame(self, background=BG) self.cycles_list = tk.Frame( self.cycles_frame.scrollable_frame, background=BG) self.cycles_list.grid(row=0, column=0, sticky=tk.E+tk.W) self.cycles_list.columnconfigure(0, weight=1) cycle = Cycle(self.cycles_list, borderwidth=1, relief='raised') self.cycles.append(cycle) cycle.grid(row=0, column=0, pady=(0, 16), sticky=tk.E+tk.W) cycles_buttons = tk.Frame( self.cycles_frame.scrollable_frame, background=BG) cycles_buttons.grid(row=1, column=0, pady=(16, 24)) tk.Button( cycles_buttons, text='+ Step', highlightbackground=BG, command=self.add_step, ).grid(row=0, column=0) self.run_button = tk.Button( cycles_buttons, text='Run Program', highlightbackground=BG, font=tkFont.Font(weight='bold'), command=self.run_program) self.run_button.grid(row=0, column=1, ipady=6) self.cycles_frame.grid(row=0, column=0, sticky=tk.N+tk.E+tk.S+tk.W) self.cycles_frame.scrollable_frame.columnconfigure(0, weight=1) self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) def add_step(self): cycle_index = len(self.cycles) cycle = Cycle( self.cycles_list, cycle_index, borderwidth=1, relief='raised') cycle.grid(row=cycle_index, column=0, pady=(0, 16), sticky=tk.E+tk.W) rm = tk.Label( cycle, text='✕', foreground='#833', width=2, justify=tk.CENTER) rm.place(relx=1, anchor=tk.NE) rm.bind('<Button-1>', lambda _: self.remove_step(cycle)) self.cycles.append(cycle) def remove_step(self, cycle): self.cycles = [a for a in self.cycles if a is not cycle] cycle.destroy() for i, cycle in enumerate(self.cycles): cycle.grid(row=i, column=0, sticky=tk.E+tk.W) def run_program(self): program = [] for cycle in self.cycles: for _ in range(int(cycle.cycles_count.get())): for a in cycle.actions: n = int(a.action.frames.get()) if a.action.name == 'Camera': if self.camera_direction.get() == 'rw': n *= -1 program.append((n, 0)) else: if a.action.direction.get() == 'rw': n *= -1 program.append((0, n)) self.on_run(program) def disable(self): self.run_button.config(state=tk.DISABLED, text='Program running...') def enable(self): self.run_button.config(state=tk.NORMAL, text='Run program')
def main(self, host, port): ip = host while True: try: print(ip) print(type(ip)) self.c_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.c_socket.settimeout(3) self.c_socket.connect((ip, port)) break except OSError as e: print("例外args:", e.args) with open("master_ip.txt", encoding='utf-8-sig') as f: ip = f.read() print("retrying :" + ip) time.sleep(1) continue # ワーカースレッドを起動する self.c_socket.settimeout(None) NUMBER_OF_THREADS = 10 for _ in range(NUMBER_OF_THREADS): thread = threading.Thread(target=self.worker_thread) thread.daemon = True thread.start() self.gui_thread = threading.Thread(target=self.label_manager) self.gui_thread.setDaemon(True) self.gui_thread.start() # ここ以降にGUIの記述をする self.root.grid_rowconfigure(0, weight=1) self.root.grid_columnconfigure(0, weight=1) self.flush_window = tk.Frame(self.root, bg="white") self.flush_window.grid(row=0, column=0) self.bc_button_base = tk.Frame(self.root, bg="orange") self.bc_button_base.grid(row=0, column=0, sticky=tk.W + tk.E + tk.N + tk.S) self.taiki_base = tk.Frame(self.root, bg="gray") self.taiki_base.grid(row=0, column=0, sticky=tk.W + tk.E + tk.N + tk.S) self.timeline = ScrollableFrame(self.taiki_base, width=900) null = " " null += " " null += " " ttk.Label(self.timeline.scrollable_frame, text=null).pack() # self.timeline.pack() self.timeline.place(relx=0.15, rely=0) self.tl_contents = [] quitbut2 = tk.Button(self.taiki_base, text="Quit") # quitbut.pack() quitbut2.place(relx=0.95, rely=0.95) quitbut2.bind("<Button-1>", self.quit) """for i in range(50): ttk.Button(self.timeline.scrollable_frame, text="Sample scrolling label").pack() self.timeline.pack()""" """self.taiki_base = tk.Frame(self.root, bg="gray") self.taiki_base.grid(row=0, column=0, sticky=tk.W + tk.E + tk.N + tk.S) self.timeline = tk.Canvas(self.taiki_base, bg="green", width=900, height=10000) self.timeline.place(relx=0.15, rely=0) self.tl_scrollbar = tk.Scrollbar(self.timeline, command=self.timeline.yview, width=80) self.tl_scrollbar.pack(side=tk.RIGHT, fill=tk.Y) self.tl_contents = []""" self.button_base = tk.Frame(self.root, bg="gray") self.button_base.grid(row=0, column=0, sticky=tk.W + tk.E + tk.N + tk.S) block_button = tk.Button(self.flush_window, text = "☝話し中", bg="gray", width=800, height=100,font=("", 120), fg="white") block_button.pack(fill="both") block_button.bind("<Button-1>", self.dummy) # 閉じるボタン quitbut = tk.Button(self.button_base, text="Quit") # quitbut.pack(side="right") quitbut.grid(column=5, row=5) quitbut.bind("<Button-1>", self.quit) """koushin_but = tk.Button(self.button_base, text="他の選択肢", width=15, height=3, bg="SkyBlue1", activebackground="green", activeforeground="white", fg="blue", font=("", 17)) koushin_but.grid(column=4, row=1) koushin_but.bind("<Button-1>", self.koushin_youkyuu)""" self.conjunctions_buttons = [] for i in range(len(self.conjunction_labels)): self.conjunctions_buttons.append(tk.Button(self.button_base, text=self.conjunction_labels[i][1], width=22, height=3, bg="blue", activebackground="green", activeforeground="white", fg="white", justify='left', font=("", 20))) self.conjunctions_buttons[-1].grid(column=i, columnspan=1, padx=5, pady=30, row=1, sticky='nw') self.conjunctions_buttons[-1].bind("<Button-1>", self.conjunctions_button_process) self.buttons = [] for i in range(len(self.choice_labels)): self.buttons.append(tk.Button(self.button_base, text=self.choice_labels[i][1], width=70, height=5, bg="blue", activebackground="green", activeforeground="white", fg="white", justify='left', font=("",25))) self.buttons[-1].grid(column=0, columnspan=5, padx=10, pady=20, row=i+2, sticky='n') self.buttons[-1].bind("<Button-1>", self.button_process) self.choice_timer_bar = tk.Label(self.button_base, text="", bg="SkyBlue1", width=150, height=2) self.choice_timer_bar.grid(column=0, columnspan=5, padx=40, pady=10, row=5) self.choice_timer_bar.after(200, self.choice_timer_bar_counter) self.bc_buttons = [] self.latest_argument = tk.Label(self.bc_button_base, text=self.latest_opinion, width=79, height=5, bg="white", activebackground="white", activeforeground="white", fg="blue", justify='left', borderwidth=2, relief="raised", font=("", 25)) self.latest_argument.grid(column=1, row=0, columnspan=3) for i in range(len(self.bc_choice_labels)): self.bc_buttons.append(tk.Button(self.bc_button_base, text=self.bc_choice_labels[i][1], width=33, height=4, bg="dark orange", activebackground="gold", activeforeground="white", fg="white", justify='left', borderwidth=2, relief="raised", font=("",24))) self.bc_buttons[-1].grid(column=int(i/2)+1, columnspan=1, padx=15, pady=80, row=i%2+2) self.bc_buttons[-1].bind("<Button-1>", self.bc_button_process) self.timer_bar = tk.Label(self.bc_button_base, text="", bg="SkyBlue1", width=150, height=6) self.timer_bar.grid(column=0, columnspan=3, padx=40, pady=80, row=4) self.timer_bar.after(200, self.timer_bar_counter) self.root.mainloop()
class TouchDisp(): def __init__(self, host, port): self.colors = ["deep sky blue", "SpringGreen2", "pink3", "orange"] # 参加者ごとの色 self.root = tk.Tk() self.root.title(u"Test") self.root.geometry("2800x2000") self.root.overrideredirect(True) self.root.geometry("{0}x{1}+0+0".format(self.root.winfo_screenwidth(), self.root.winfo_screenheight())) self.last_pressed = [0, -1, "はじめる"] # 最後に押したのがどのボタンか、いつ押したか、そのラベル self.bc_last_pressed = [0, -1, "はじめる"] self.BC_DUR = 4 self.DUR = 20 # self.root.attributes("-zoomed", "1") # self.root.mainloop() self.quitcount = 0 self.timeline_log = [] self.latest_opinion = "" self.p_status = "floor" # taiki か floor self.choice_labels = [["00000", "はじめる"],["00000", ""],["00000", ""]] self.bc_choice_labels = [["", ""],["", ""],["", ""],["", ""]] # self.conjunctions_labels = [["85001","逆に"],["8400","それなら"],["8200","けど"],["8600","関係ないかもしれないけど"]] self.conjunction_labels = [["", ""], ["", ""], ["", ""]] self.conjunctions_buttons = [] self.bc_show = False self.bc_start = [0, False] # bcを表示するか、bc画面が表示されているか self.choice_start = [0, True] self.my_timer = time.perf_counter() self.owari = False self.is_operation_waited = True self.buttons = [] self.conj_set = [-1,[]] # 暫定で入力されている接続詞 self.nopress = False # ボタンが反応するかどうか self.bc_nopress = False self.kakasi = kakasi() # ひらがな化インスタンス self.kakasi.setMode('J', 'H') # J(Kanji) to H(Hiragana) self.main(host, port) def button_process(self, data): if self.nopress: return if (time.perf_counter() - self.choice_start[0]) / self.DUR < 0.07: return self.bc_show = True self.choice_start[1] = False pressed = 0 for i in range(len(self.choice_labels)): if self.choice_labels[i][1] == data.widget["text"]: pressed = i break self.last_pressed[0] = pressed self.last_pressed[1] = time.time() self.last_pressed[2] = self.choice_labels[pressed][1] senddata = "hatsuwa:" if self.conj_set[1] == []: senddata += ";" + self.choice_labels[pressed][0] else: senddata += self.conj_set[1][0] + ";" + self.choice_labels[pressed][0] print("send|" + senddata) self.c_socket.send(senddata.encode('utf-8')) def conjunctions_button_process(self, data): if self.nopress: return pressed = 0 for i in range(len(self.conjunction_labels)): if self.conjunction_labels[i][1] == data.widget["text"]: pressed = i break if self.conj_set[0] != pressed: self.conj_set[0] = pressed self.conj_set[1] = self.conjunction_labels[pressed] print("registered" + self.conjunction_labels[pressed][0]) else: self.conj_set[0] = -1 self.conj_set[1] = [] print("unregistered" + self.conjunction_labels[pressed][0]) self.conjunctions_label_manager() def bc_button_process(self, data): if self.bc_nopress: return pressed = 0 for i in range(len(self.bc_choice_labels)): if self.bc_choice_labels[i][1] == data.widget["text"]: pressed = i break self.bc_last_pressed[0] = pressed self.bc_last_pressed[1] = time.time() self.bc_last_pressed[2] = self.bc_choice_labels[pressed][1] j = 0 for but in self.bc_buttons: if self.bc_last_pressed[0] == j: but["text"] = self.bc_last_pressed[2] but["bg"] = "gold" but["activebackground"] = "gold" else: but["text"] = "" j += 1 senddata = "hatsuwa:;" senddata += self.bc_choice_labels[pressed][0] print("send|" + senddata) self.bc_nopress = True self.c_socket.send(senddata.encode('utf-8')) def dummy(self, data): return def conjunctions_label_manager(self): j = 0 for cbut in self.conjunctions_buttons: if self.conj_set[0] == j: cbut["text"] = self.conj_set[1][1] cbut["bg"] = "green" cbut["activebackground"] = "green" if self.conj_set[0] != j: if cbut["bg"] == "green": cbut["text"] = self.conjunction_labels[j][1] cbut["bg"] = "blue" cbut["activebackground"] = "blue" j += 1 def label_manager(self): conv = self.kakasi.getConverter() while True: if self.owari: break # あいづち画面を終わらせる if self.bc_start[1]: # print(time.perf_counter(), self.bc_start[0]) if time.perf_counter() - self.bc_start[0] > self.BC_DUR: if self.p_status == "floor": self.button_base.tkraise() self.nopress = False self.choice_start[1] = True self.choice_start[0] = time.perf_counter() elif self.p_status == "taiki": self.taiki_base.tkraise() self.choice_start[1] = False self.bc_start[1] = False passed = int(time.time() - self.last_pressed[1]) # 発話の後どのくらい操作不可能時間があるか utter_len = 3 # utter_len = int(len(conv.do(self.last_pressed[2]))/5) + 1 if passed < utter_len: # print("sentaku") self.nopress = True j = 0 for but in self.buttons: if self.last_pressed[0] == j: but["text"] = self.last_pressed[2] but["bg"] = "green" but["activebackground"] = "green" else: but["text"] = "" j += 1 j = 0 for cbut in self.conjunctions_buttons: if self.conj_set[0] == j: cbut["text"] = self.conj_set[1][1] else: cbut["text"] = "" j += 1 elif self.nopress and ((passed >= utter_len and self.is_operation_waited) or passed > 15): self.nopress = False # 登録されていた接続詞の消去 self.conjunctions_buttons[self.conj_set[0]]["text"] = self.conjunction_labels[self.conj_set[0]][1] self.conjunctions_buttons[self.conj_set[0]]["bg"] = "blue" self.conjunctions_buttons[self.conj_set[0]]["activebackground"] = "blue" self.conj_set[0] = -1 self.conj_set[1] = [] j = 0 for but in self.buttons: but["text"] = self.choice_labels[j][1] but["bg"] = "blue" but["activebackground"] = "blue" j += 1 j = 0 for cbut in self.conjunctions_buttons: cbut["text"] = self.conjunction_labels[j][1] j += 1 else: j = 0 for but in self.buttons: but["text"] = self.choice_labels[j][1] j += 1 j = 0 for cbut in self.conjunctions_buttons: cbut["text"] = self.conjunction_labels[j][1] j += 1 continue def quit(self, data): self.quitcount += 1 if self.quitcount > 6: self.owari = True # self.gui_thread.kill() self.root.quit() def pass_to_others(self): print("send|jidou") self.c_socket.send("jidou".encode('utf-8')) self.choice_start[1] = False def choice_timer_bar_counter(self): if self.choice_start[1]: rate = (time.perf_counter() - self.choice_start[0]) / self.DUR if rate > 1 and len(self.timeline_log) > 1: rate = 0 self.pass_to_others() else: rate = 0 self.choice_timer_bar.configure(bg="gold") self.choice_timer_bar.configure(width=int(150*(1 - rate))) self.choice_timer_bar.configure(bg="SkyBlue1") # print("timer working", rate) self.choice_timer_bar.after(200, self.choice_timer_bar_counter) def timer_bar_counter(self): rate = (time.perf_counter() - self.bc_start[0]) / self.BC_DUR if rate > 1: rate = 0 self.timer_bar.configure(width=int(150*(1 - rate))) # print("timer working", rate) self.timer_bar.after(200, self.timer_bar_counter) def main(self, host, port): ip = host while True: try: print(ip) print(type(ip)) self.c_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.c_socket.settimeout(3) self.c_socket.connect((ip, port)) break except OSError as e: print("例外args:", e.args) with open("master_ip.txt", encoding='utf-8-sig') as f: ip = f.read() print("retrying :" + ip) time.sleep(1) continue # ワーカースレッドを起動する self.c_socket.settimeout(None) NUMBER_OF_THREADS = 10 for _ in range(NUMBER_OF_THREADS): thread = threading.Thread(target=self.worker_thread) thread.daemon = True thread.start() self.gui_thread = threading.Thread(target=self.label_manager) self.gui_thread.setDaemon(True) self.gui_thread.start() # ここ以降にGUIの記述をする self.root.grid_rowconfigure(0, weight=1) self.root.grid_columnconfigure(0, weight=1) self.flush_window = tk.Frame(self.root, bg="white") self.flush_window.grid(row=0, column=0) self.bc_button_base = tk.Frame(self.root, bg="orange") self.bc_button_base.grid(row=0, column=0, sticky=tk.W + tk.E + tk.N + tk.S) self.taiki_base = tk.Frame(self.root, bg="gray") self.taiki_base.grid(row=0, column=0, sticky=tk.W + tk.E + tk.N + tk.S) self.timeline = ScrollableFrame(self.taiki_base, width=900) null = " " null += " " null += " " ttk.Label(self.timeline.scrollable_frame, text=null).pack() # self.timeline.pack() self.timeline.place(relx=0.15, rely=0) self.tl_contents = [] quitbut2 = tk.Button(self.taiki_base, text="Quit") # quitbut.pack() quitbut2.place(relx=0.95, rely=0.95) quitbut2.bind("<Button-1>", self.quit) """for i in range(50): ttk.Button(self.timeline.scrollable_frame, text="Sample scrolling label").pack() self.timeline.pack()""" """self.taiki_base = tk.Frame(self.root, bg="gray") self.taiki_base.grid(row=0, column=0, sticky=tk.W + tk.E + tk.N + tk.S) self.timeline = tk.Canvas(self.taiki_base, bg="green", width=900, height=10000) self.timeline.place(relx=0.15, rely=0) self.tl_scrollbar = tk.Scrollbar(self.timeline, command=self.timeline.yview, width=80) self.tl_scrollbar.pack(side=tk.RIGHT, fill=tk.Y) self.tl_contents = []""" self.button_base = tk.Frame(self.root, bg="gray") self.button_base.grid(row=0, column=0, sticky=tk.W + tk.E + tk.N + tk.S) block_button = tk.Button(self.flush_window, text = "☝話し中", bg="gray", width=800, height=100,font=("", 120), fg="white") block_button.pack(fill="both") block_button.bind("<Button-1>", self.dummy) # 閉じるボタン quitbut = tk.Button(self.button_base, text="Quit") # quitbut.pack(side="right") quitbut.grid(column=5, row=5) quitbut.bind("<Button-1>", self.quit) """koushin_but = tk.Button(self.button_base, text="他の選択肢", width=15, height=3, bg="SkyBlue1", activebackground="green", activeforeground="white", fg="blue", font=("", 17)) koushin_but.grid(column=4, row=1) koushin_but.bind("<Button-1>", self.koushin_youkyuu)""" self.conjunctions_buttons = [] for i in range(len(self.conjunction_labels)): self.conjunctions_buttons.append(tk.Button(self.button_base, text=self.conjunction_labels[i][1], width=22, height=3, bg="blue", activebackground="green", activeforeground="white", fg="white", justify='left', font=("", 20))) self.conjunctions_buttons[-1].grid(column=i, columnspan=1, padx=5, pady=30, row=1, sticky='nw') self.conjunctions_buttons[-1].bind("<Button-1>", self.conjunctions_button_process) self.buttons = [] for i in range(len(self.choice_labels)): self.buttons.append(tk.Button(self.button_base, text=self.choice_labels[i][1], width=70, height=5, bg="blue", activebackground="green", activeforeground="white", fg="white", justify='left', font=("",25))) self.buttons[-1].grid(column=0, columnspan=5, padx=10, pady=20, row=i+2, sticky='n') self.buttons[-1].bind("<Button-1>", self.button_process) self.choice_timer_bar = tk.Label(self.button_base, text="", bg="SkyBlue1", width=150, height=2) self.choice_timer_bar.grid(column=0, columnspan=5, padx=40, pady=10, row=5) self.choice_timer_bar.after(200, self.choice_timer_bar_counter) self.bc_buttons = [] self.latest_argument = tk.Label(self.bc_button_base, text=self.latest_opinion, width=79, height=5, bg="white", activebackground="white", activeforeground="white", fg="blue", justify='left', borderwidth=2, relief="raised", font=("", 25)) self.latest_argument.grid(column=1, row=0, columnspan=3) for i in range(len(self.bc_choice_labels)): self.bc_buttons.append(tk.Button(self.bc_button_base, text=self.bc_choice_labels[i][1], width=33, height=4, bg="dark orange", activebackground="gold", activeforeground="white", fg="white", justify='left', borderwidth=2, relief="raised", font=("",24))) self.bc_buttons[-1].grid(column=int(i/2)+1, columnspan=1, padx=15, pady=80, row=i%2+2) self.bc_buttons[-1].bind("<Button-1>", self.bc_button_process) self.timer_bar = tk.Label(self.bc_button_base, text="", bg="SkyBlue1", width=150, height=6) self.timer_bar.grid(column=0, columnspan=3, padx=40, pady=80, row=4) self.timer_bar.after(200, self.timer_bar_counter) self.root.mainloop() def fav_marking(self, message, fav_er): for i, log in enumerate(self.tl_contents): if message in log[1]["text"]: if self.tl_contents[i][3][fav_er] == False: print("found one to mark", message) log[2].create_text(10 + fav_er * 15, 10, fill=self.colors[fav_er], text="★", font=("", 17)) self.tl_contents[i][3][fav_er] = True break else: print("found one to mark", message) log[2].create_text(10 + fav_er * 15, 10, fill="white", text="★", font=("", 17)) self.tl_contents[i][3][fav_er] = False break # log[2].create_rectangle(15+fav_er*8, 20, 15+fav_er*8+5, 20, fill=self.colors[fav_er]) def reputation_button(self, event): self.c_socket.send(("/rireki:" + event.widget["text"][:30] + ";" + str(self.mynumber)).encode('utf-8')) # self.fav_marking(event.widget["text"], self.mynumber) """if not "★" in event.widget["text"]: if not "★" in event.widget["text"]: event.widget["text"] = "★\n" + event.widget["text"] else: event.widget["text"] = "★" + event.widget["text"] return""" def tl_adding(self): print("new record", self.timeline_log[-1]) cc = self.colors[int(self.timeline_log[-1][0])] if int(self.timeline_log[-1][0]) == self.mynumber: temp_tl = tk.Frame(self.timeline.scrollable_frame, bg=cc, padx=40, pady=20) temp_tl.pack(anchor=tk.E) canvas = tk.Canvas(temp_tl, bg='white', width=80, height=60) canvas.create_oval(25, 25, 50, 50, fill=cc) canvas.create_text(60, 50, text="あなた") canvas.pack(side= tk.RIGHT, padx=10) if self.timeline_log[-1][2] == "opinion": temp_tl_content = tk.Button(temp_tl, text=self.timeline_log[-1][1], font=("", 15), padx=5, pady=5, bg=cc, justify='left') temp_tl_content.bind("<Button-1>", self.reputation_button) temp_tl_content.pack(side= tk.RIGHT, padx=20) else: temp_tl_content = tk.Label(temp_tl, text=self.timeline_log[-1][1], font=("", 12), padx=5, pady=5, bg=cc, justify='left') # temp_tl_content.bind("<Button-1>", self.reputation_button) temp_tl_content.pack(side= tk.RIGHT, padx=20) else: temp_tl = tk.Frame(self.timeline.scrollable_frame, bg=cc, padx=40, pady=20) temp_tl.pack(anchor=tk.W) canvas = tk.Canvas(temp_tl, bg='white', width=80, height=60) canvas.create_oval(25, 25, 50, 50, fill=cc) canvas.pack(side= tk.LEFT, padx=10) # temp_tl_content = tk.Button(temp_tl, text=self.timeline_log[-1][1], font=("", 15), padx=5, pady=5, bg=cc, justify='left') # temp_tl_content.bind("<Button-1>", self.reputation_button) # temp_tl_content.pack(side= tk.LEFT, padx=20) if self.timeline_log[-1][2] == "opinion": temp_tl_content = tk.Button(temp_tl, text=self.timeline_log[-1][1], font=("", 15), padx=5, pady=5, bg=cc, justify='left') temp_tl_content.bind("<Button-1>", self.reputation_button) temp_tl_content.pack(side= tk.LEFT, padx=20) else: temp_tl_content = tk.Label(temp_tl, text=self.timeline_log[-1][1], font=("", 12), padx=5, pady=5, bg=cc, justify='left') # temp_tl_content.bind("<Button-1>", self.reputation_button) temp_tl_content.pack(side= tk.LEFT, padx=20) """temp_tl_content = tk.Button(temp_tl, text=self.timeline_log[-1][1], font=("", 15), padx=5, pady=5) temp_tl_content.pack()""" self.tl_contents.append([temp_tl, temp_tl_content, canvas, [False, False, False, False]]) # ttk.Button(self.timeline.scrollable_frame, text="Sample scrolling label").pack() def worker_thread(self): auto_quit_counter = 0 while True: self.recvdata = self.c_socket.recv(1024).decode('utf-8') print("RecvData|" + self.recvdata) if self.recvdata == "": # 接続が切れた場合 auto_quit_counter += 1 else: auto_quit_counter = 0 if auto_quit_counter > 5: self.root.quit() self.quitcount = 0 if "you are number" in self.recvdata: self.mynumber = int(self.recvdata.split(":")[-1]) print("I am number " + str(self.mynumber)) if "/operation_waiting" in self.recvdata: print("wait", self.bc_show, self.p_status) if self.bc_show: self.bc_start[0] = time.perf_counter() self.bc_start[1] = True if int(self.timeline_log[-1][0]) == self.mynumber: self.taiki_base.tkraise() else: self.bc_button_base.tkraise() # あいづちボタンを表示させるモードになる self.choice_start[1] = False j = 0 for but in self.bc_buttons: but["text"] = self.bc_choice_labels[j][1] but["bg"] = "dark orange" but["activebackground"] = "dark orange" j += 1 self.latest_argument["text"] = self.latest_opinion self.bc_nopress = False self.bc_show = False else: if self.p_status == "floor": self.button_base.tkraise() self.nopress = False self.choice_start[1] = True self.choice_start[0] = time.perf_counter() elif self.p_status == "taiki": self.taiki_base.tkraise() self.choice_start[1] = False elif "/operation_blocking" in self.recvdata: if not self.bc_start[1]: print("block") self.flush_window.tkraise() self.choice_start[1] = False if "rireki" in self.recvdata: try: rirekiyou = re.search('/rireki.*#', self.recvdata).group()[:-1].split(":")[-1].split(";") self.fav_marking(rirekiyou[0], int(rirekiyou[1])) self.recvdata = re.sub('/rireki.*#', "", self.recvdata) except TypeError: pass if "taiki" in self.recvdata: self.p_status = "taiki" if "choice" in self.recvdata: self.p_status = "floor" buf = re.sub("/operation_blocking", "", self.recvdata) buf = re.sub("/operation_waiting", "", buf) # buffering = buf.split("/")[1] buffering = buf.split("/") for b in buffering: sent = b.split(":") try: print(sent) if sent[0] == "choice": choices_l = sent[3].split(";") conjunctions_l = sent[2].split(";") # print(choices_l, conjunctions_l) self.choice_labels = [] for choice in choices_l: temp = choice.split(",") if len(temp[1]) > 38: temp_str = temp[1][:37] temp_str2 = temp[1][37:] temp[1] = temp_str + "\n" + temp_str2 # print(temp) self.choice_labels.append(temp) self.conjunction_labels = [] for conjunction in conjunctions_l: temp = conjunction.split(",") self.conjunction_labels.append(temp) except IndexError: print("unable to fix choice to show") continue if "bc_ch" in self.recvdata: self.bc_show = True print("backchanneling stocked") buf = re.sub("/operation_blocking", "", self.recvdata) buf = re.sub("/operation_waiting", "", buf) # buffering = buf.split("/")[1] buffering = buf.split("/") for b in buffering: sent = b.split(":") try: print(sent) if sent[0] == "bc_ch": choices_bc = sent[2].split(";") self.bc_choice_labels = [] for choice in choices_bc: temp = choice.split(",") if len(temp[1]) > 38: temp_str = temp[1][:37] temp_str2 = temp[1][37:] temp[1] = temp_str + "\n" + temp_str2 # print(temp) self.bc_choice_labels.append(temp) except IndexError: print("unable to fix choice to show") continue if "loggin" in self.recvdata: buf = re.sub("/operation_blocking", "", self.recvdata) buf = re.sub("/operation_waiting", "", buf) # buffering = buf.split("/")[1] buffering = buf.split("/") for b in buffering: sent = b.split(":") try: print(sent) if sent[0] == "logging": logger = sent[1].split(";") sender = logger[0] # content = logger[2] texts = logger[2].split("^") content = "" for con in texts: content += con if len(content) > 32: temp_str = content[:31] temp_str2 = content[31:] content = temp_str + "\n" + temp_str2 property = logger[1] print([sender, content, property]) self.timeline_log.append([sender, content, property]) self.tl_adding() self.timeline.canvas.create_window((0, 0), window=self.timeline.scrollable_frame, anchor="sw") if logger[1] == "opinion": print("opinion stocked" + texts[-1]) self.latest_opinion = texts[-1] if len(self.latest_opinion) > 37: temp_str = self.latest_opinion[:37] temp_str2 = self.latest_opinion[37:] self.latest_opinion = temp_str + "\n" + temp_str2 except IndexError: print("unable to log a log") continue if "quit" in self.recvdata: self.root.quit() sys.exit()