def initUI(self): self.parent.title("Validador Lexico y Sintacto de Ruby") self.pack(fill=BOTH, expand=True) global value value = 0 global expr expr = StringVar() global res res = StringVar() frame1 = Frame(self) frame1.pack(fill=X) frame1.config(width=480, height=320) lbl1 = Label(frame1, text="Expresion :", width=18) lbl1.pack(side=LEFT, padx=5, pady=5) # entry1 = Entry(frame1,textvariable=expr) # entry1.pack(fill=X, padx=5, expand=True) self.expr = Text(frame1) self.expr.pack(fill=X, padx=5, pady=5) frame3 = Frame(self) frame3.pack(fill=X) btnlex = Button(frame3, text="Analisis Lexico ", width=12, command=self.validate_lex) btnlex.pack(side=LEFT, anchor=N, padx=5, pady=5) btnsyntax = Button(frame3, text="Analisis Sintactico", width=12, command=self.validate_syntax) btnsyntax.pack(side=LEFT, anchor=N, padx=12, pady=5) btnclear = Button(frame3, text="Limpiar", width=8, command=self.clear) btnclear.pack(side=LEFT, anchor=N, padx=20, pady=5) frame4 = Frame(self) frame4.pack(fill=X) lbl3 = Label(frame4, text="Analisis Lexico :", width=70) lbl3.pack(side=LEFT, padx=5, pady=5) lbl4 = Label(frame4, text="Analisis Sintactico :", width=20) lbl4.pack(side=LEFT, padx=25, pady=5) frame5 = Frame(self) frame5.pack(fill=X) self.tbox = Text(frame5) self.tbox.pack(padx=5, pady=5, side=LEFT) self.tbox2 = Text(frame5) self.tbox2.pack(after=self.tbox, padx=5, pady=10, side=LEFT)
def create_frame(self): """ Factory method for creating a new frame when needed :return tkinter.ttk.Frame: Frame object """ new_frame = Frame(self) new_frame.pack(fill=X) new_frame.config() return new_frame
def __create_frame_grid( self, frame_position: FrameGridPositionEnum, width: int = None, height: int = None, column_weight: int = 0, row_weight: int = 0, padx: int = None, pady: int = None, row: int = None, column: int = None, sticky: GridPositionEnum = GridPositionEnum.NONE) -> Frame: if frame_position == FrameGridPositionEnum.CUSTOM_POSITION \ and (row is None or column is None): raise ApplicationException( 'Bug: row and column parameters must have values' ' when frame_position is CUSTOM_POSITION') frame = Frame(self.__frame_and_name.frame) self.update_row_and_column(frame_position) if frame_position != FrameGridPositionEnum.CUSTOM_POSITION: row = self.__row column = self.__column logger().debug( f'Create new frame_and_name. Parent [{self.__frame_and_name.name}]' f' Row [{row}] Column [{column}]' f' Sticky [{sticky.value}]') frame.rowconfigure(row, weight=row_weight) frame.columnconfigure(column, weight=column_weight) frame.grid(row=row, column=column, padx=padx, pady=pady, sticky=sticky.value) if width: frame.config(width=width) if height: frame.config(height=height) return frame
def __init__(self): self.__root = root = tkinter.Tk() root.title('HLS录制程序') Menu(root) print('app目录', resource_path.path('')) # 设置windows窗口图标 if platform == 'win32': icon = resource_path.path('icon.ico') print('icon', icon) root.iconbitmap(icon) root.minsize(450, 450) frame = Frame(root) frame.config(padding=5) frame.pack(fill=tkinter.BOTH, expand=True) self.__ui_m3u8 = m3u8 = ui_m3u8.Frame(root=frame, cache=my_cache) self.__ui_aria2 = aria2 = ui_aria2.Frame( root=frame, cache=my_cache, on_click_start_aria2c=self.start_aria2c, on_click_stop_aria2c=self.stop_aria2c, on_click_open_aria2c=self.open_aria2c_webui) self.__ui_log = log = ui_log.Frame(root=frame) self.__ui_buttons = ui_buttons.Frame( root=frame, on_click_start=self.start, on_click_stop=self.stop, on_click_merge_video=self.merge_video, on_click_watermark=self.watermark) log.pack() self.__core_m3u8: CoreM3u8 = None self.__core_aria2c: CoreAria2c = CoreAria2c(logger=log) root.protocol("WM_DELETE_WINDOW", self.on_closing) # threading.Thread(target=self.loop_check).start() self.loop_check() root.mainloop()
def plot_init_dist(self): ''' This function will plot the distribution of variable calls prior to running the simulation. This will enable users to see whether the distributions are as they expected. ''' self.get_distributions() fig_list =[] for var, values in self.simulation_dist.items(): fig = Figure(figsize = (3,3), facecolor=[240/255,240/255,237/255], tight_layout=True) a = fig.add_subplot(111) num_bins = 15 a.hist(values, num_bins, facecolor='blue', edgecolor='black', alpha=1.0) a.set_title(var) fig_list.append(fig) if self.univar_row_num != 0: row_num = 17 else: row_num = 10 frame_canvas = Frame(self.current_tab) frame_canvas.grid(row=row_num, column=1, columnspan = 3,pady=(5, 0)) frame_canvas.grid_rowconfigure(0, weight=1) frame_canvas.grid_columnconfigure(0, weight=1) frame_canvas.config(height = '10c', width='16c') main_canvas = Canvas(frame_canvas) main_canvas.grid(row=0, column=0, sticky="news") main_canvas.config(height = '10c', width='16c') vsb = Scrollbar(frame_canvas, orient="vertical", command=main_canvas.yview) vsb.grid(row=0, column=2,sticky = 'ns') main_canvas.configure(yscrollcommand=vsb.set) figure_frame = Frame(main_canvas) main_canvas.create_window((0, 0), window=figure_frame, anchor='nw') figure_frame.config(height = '10c', width='16c') row_num = 0 column = False for figs in fig_list: figure_canvas = FigureCanvasTkAgg(figs, master=figure_frame) if column: col = 4 else: col = 1 figure_canvas.get_tk_widget().grid( row=row_num, column=col,columnspan=2, rowspan = 5, pady = 5,padx = 8, sticky=E) if column: row_num += 5 column = not column figure_frame.update_idletasks() frame_canvas.config(width='16c', height='10c') main_canvas.config(scrollregion=figure_frame.bbox("all"))
def __init__(self, mainWin, modulesWithNewerFileDates): super(DialogPluginManager, self).__init__(mainWin.parent) self.ENABLE = _("Enable") self.DISABLE = _("Disable") self.parent = mainWin.parent self.cntlr = mainWin # copy plugins for temporary display self.pluginConfig = PluginManager.pluginConfig self.pluginConfigChanged = False self.uiClassMethodsChanged = False self.modelClassesChanged = False self.disclosureSystemTypesChanged = False self.hostSystemFeaturesChanged = False self.modulesWithNewerFileDates = modulesWithNewerFileDates parentGeometry = re.match("(\d+)x(\d+)[+]?([-]?\d+)[+]?([-]?\d+)", self.parent.geometry()) dialogX = int(parentGeometry.group(3)) dialogY = int(parentGeometry.group(4)) self.title(_("Plug-in Manager")) frame = Frame(self) # left button frame buttonFrame = Frame(frame, width=40) buttonFrame.columnconfigure(0, weight=1) addLabel = Label(buttonFrame, text=_("Find plug-in modules:"), wraplength=60, justify="center") addLocalButton = Button(buttonFrame, text=_("Locally"), command=self.findLocally) ToolTip(addLocalButton, text=_("File chooser allows selecting python module files to add (or reload) plug-ins, from the local file system."), wraplength=240) addWebButton = Button(buttonFrame, text=_("On Web"), command=self.findOnWeb) ToolTip(addWebButton, text=_("Dialog to enter URL full path to load (or reload) plug-ins, from the web or local file system."), wraplength=240) addLabel.grid(row=0, column=0, pady=4) addLocalButton.grid(row=1, column=0, pady=4) addWebButton.grid(row=2, column=0, pady=4) buttonFrame.grid(row=0, column=0, rowspan=2, sticky=(N, S, W), padx=3, pady=3) # right tree frame (plugins already known to arelle) modulesFrame = Frame(frame, width=700) vScrollbar = Scrollbar(modulesFrame, orient=VERTICAL) hScrollbar = Scrollbar(modulesFrame, orient=HORIZONTAL) self.modulesView = Treeview(modulesFrame, xscrollcommand=hScrollbar.set, yscrollcommand=vScrollbar.set, height=7) self.modulesView.grid(row=0, column=0, sticky=(N, S, E, W)) self.modulesView.bind('<<TreeviewSelect>>', self.moduleSelect) hScrollbar["command"] = self.modulesView.xview hScrollbar.grid(row=1, column=0, sticky=(E,W)) vScrollbar["command"] = self.modulesView.yview vScrollbar.grid(row=0, column=1, sticky=(N,S)) modulesFrame.columnconfigure(0, weight=1) modulesFrame.rowconfigure(0, weight=1) modulesFrame.grid(row=0, column=1, columnspan=4, sticky=(N, S, E, W), padx=3, pady=3) self.modulesView.focus_set() self.modulesView.column("#0", width=120, anchor="w") self.modulesView.heading("#0", text=_("Name")) self.modulesView["columns"] = ("author", "ver", "status", "date", "update", "descr", "license") self.modulesView.column("author", width=100, anchor="w", stretch=False) self.modulesView.heading("author", text=_("Author")) self.modulesView.column("ver", width=50, anchor="w", stretch=False) self.modulesView.heading("ver", text=_("Version")) self.modulesView.column("status", width=50, anchor="w", stretch=False) self.modulesView.heading("status", text=_("Status")) self.modulesView.column("date", width=70, anchor="w", stretch=False) self.modulesView.heading("date", text=_("File Date")) self.modulesView.column("update", width=50, anchor="w", stretch=False) self.modulesView.heading("update", text=_("Update")) self.modulesView.column("descr", width=200, anchor="w", stretch=False) self.modulesView.heading("descr", text=_("Description")) self.modulesView.column("license", width=70, anchor="w", stretch=False) self.modulesView.heading("license", text=_("License")) classesFrame = Frame(frame) vScrollbar = Scrollbar(classesFrame, orient=VERTICAL) hScrollbar = Scrollbar(classesFrame, orient=HORIZONTAL) self.classesView = Treeview(classesFrame, xscrollcommand=hScrollbar.set, yscrollcommand=vScrollbar.set, height=5) self.classesView.grid(row=0, column=0, sticky=(N, S, E, W)) hScrollbar["command"] = self.classesView.xview hScrollbar.grid(row=1, column=0, sticky=(E,W)) vScrollbar["command"] = self.classesView.yview vScrollbar.grid(row=0, column=1, sticky=(N,S)) classesFrame.columnconfigure(0, weight=1) classesFrame.rowconfigure(0, weight=1) classesFrame.grid(row=1, column=1, columnspan=4, sticky=(N, S, E, W), padx=3, pady=3) self.classesView.focus_set() self.classesView.column("#0", width=200, anchor="w") self.classesView.heading("#0", text=_("Class")) self.classesView["columns"] = ("modules",) self.classesView.column("modules", width=500, anchor="w", stretch=False) self.classesView.heading("modules", text=_("Modules")) # bottom frame module info details moduleInfoFrame = Frame(frame, width=700) moduleInfoFrame.columnconfigure(1, weight=1) self.moduleNameLabel = Label(moduleInfoFrame, wraplength=600, justify="left", font=font.Font(family='Helvetica', size=12, weight='bold')) self.moduleNameLabel.grid(row=0, column=0, columnspan=4, sticky=W) self.moduleAuthorHdr = Label(moduleInfoFrame, text=_("author:"), state=DISABLED) self.moduleAuthorHdr.grid(row=1, column=0, sticky=W) self.moduleAuthorLabel = Label(moduleInfoFrame, wraplength=600, justify="left") self.moduleAuthorLabel.grid(row=1, column=1, columnspan=3, sticky=W) self.moduleDescrHdr = Label(moduleInfoFrame, text=_("description:"), state=DISABLED) self.moduleDescrHdr.grid(row=2, column=0, sticky=W) self.moduleDescrLabel = Label(moduleInfoFrame, wraplength=600, justify="left") self.moduleDescrLabel.grid(row=2, column=1, columnspan=3, sticky=W) self.moduleClassesHdr = Label(moduleInfoFrame, text=_("classes:"), state=DISABLED) self.moduleClassesHdr.grid(row=3, column=0, sticky=W) self.moduleClassesLabel = Label(moduleInfoFrame, wraplength=600, justify="left") self.moduleClassesLabel.grid(row=3, column=1, columnspan=3, sticky=W) ToolTip(self.moduleClassesLabel, text=_("List of classes that this plug-in handles."), wraplength=240) self.moduleUrlHdr = Label(moduleInfoFrame, text=_("URL:"), state=DISABLED) self.moduleUrlHdr.grid(row=4, column=0, sticky=W) self.moduleUrlLabel = Label(moduleInfoFrame, wraplength=600, justify="left") self.moduleUrlLabel.grid(row=4, column=1, columnspan=3, sticky=W) ToolTip(self.moduleUrlLabel, text=_("URL of plug-in module (local file path or web loaded file)."), wraplength=240) self.moduleDateHdr = Label(moduleInfoFrame, text=_("date:"), state=DISABLED) self.moduleDateHdr.grid(row=5, column=0, sticky=W) self.moduleDateLabel = Label(moduleInfoFrame, wraplength=600, justify="left") self.moduleDateLabel.grid(row=5, column=1, columnspan=3, sticky=W) ToolTip(self.moduleDateLabel, text=_("Date of currently loaded module file (with parenthetical node when an update is available)."), wraplength=240) self.moduleLicenseHdr = Label(moduleInfoFrame, text=_("license:"), state=DISABLED) self.moduleLicenseHdr.grid(row=6, column=0, sticky=W) self.moduleLicenseLabel = Label(moduleInfoFrame, wraplength=600, justify="left") self.moduleLicenseLabel.grid(row=6, column=1, columnspan=3, sticky=W) self.moduleImportsHdr = Label(moduleInfoFrame, text=_("imports:"), state=DISABLED) self.moduleImportsHdr.grid(row=7, column=0, sticky=W) self.moduleImportsLabel = Label(moduleInfoFrame, wraplength=600, justify="left") self.moduleImportsLabel.grid(row=7, column=1, columnspan=3, sticky=W) self.moduleEnableButton = Button(moduleInfoFrame, text=self.ENABLE, state=DISABLED, command=self.moduleEnable) ToolTip(self.moduleEnableButton, text=_("Enable/disable plug in."), wraplength=240) self.moduleEnableButton.grid(row=8, column=1, sticky=E) self.moduleReloadButton = Button(moduleInfoFrame, text=_("Reload"), state=DISABLED, command=self.moduleReload) ToolTip(self.moduleReloadButton, text=_("Reload/update plug in."), wraplength=240) self.moduleReloadButton.grid(row=8, column=2, sticky=E) self.moduleRemoveButton = Button(moduleInfoFrame, text=_("Remove"), state=DISABLED, command=self.moduleRemove) ToolTip(self.moduleRemoveButton, text=_("Remove plug in from plug in table (does not erase the plug in's file)."), wraplength=240) self.moduleRemoveButton.grid(row=8, column=3, sticky=E) moduleInfoFrame.grid(row=2, column=0, columnspan=5, sticky=(N, S, E, W), padx=3, pady=3) moduleInfoFrame.config(borderwidth=4, relief="groove") okButton = Button(frame, text=_("Close"), command=self.ok) ToolTip(okButton, text=_("Accept and changes (if any) and close dialog."), wraplength=240) cancelButton = Button(frame, text=_("Cancel"), command=self.close) ToolTip(cancelButton, text=_("Cancel changes (if any) and close dialog."), wraplength=240) okButton.grid(row=3, column=3, sticky=(S,E), pady=3) cancelButton.grid(row=3, column=4, sticky=(S,E), pady=3, padx=3) enableDisableFrame = Frame(frame) enableDisableFrame.grid(row=3, column=1, sticky=(S,W), pady=3) enableAllButton = Button(enableDisableFrame, text=_("Enable All"), command=self.enableAll) ToolTip(enableAllButton, text=_("Enable all plug ins."), wraplength=240) disableAllButton = Button(enableDisableFrame, text=_("Disable All"), command=self.disableAll) ToolTip(disableAllButton, text=_("Disable all plug ins."), wraplength=240) enableAllButton.grid(row=1, column=1) disableAllButton.grid(row=1, column=2) self.loadTreeViews() self.geometry("+{0}+{1}".format(dialogX+50,dialogY+100)) frame.grid(row=0, column=0, sticky=(N,S,E,W)) frame.columnconfigure(0, weight=0) frame.columnconfigure(1, weight=1) frame.rowconfigure(0, weight=1) window = self.winfo_toplevel() window.columnconfigure(0, weight=1) window.rowconfigure(0, weight=1) self.bind("<Return>", self.ok) self.bind("<Escape>", self.close) self.protocol("WM_DELETE_WINDOW", self.close) self.grab_set() self.wait_window(self)
def __init__(self, mainWin, modulesWithNewerFileDates): super(DialogPluginManager, self).__init__(mainWin.parent) self.ENABLE = _("Enable") self.DISABLE = _("Disable") self.parent = mainWin.parent self.cntlr = mainWin # copy plugins for temporary display self.pluginConfig = PluginManager.pluginConfig self.pluginConfigChanged = False self.uiClassMethodsChanged = False self.modelClassesChanged = False self.disclosureSystemTypesChanged = False self.modulesWithNewerFileDates = modulesWithNewerFileDates parentGeometry = re.match("(\d+)x(\d+)[+]?([-]?\d+)[+]?([-]?\d+)", self.parent.geometry()) dialogX = int(parentGeometry.group(3)) dialogY = int(parentGeometry.group(4)) self.title(_("Plug-in Manager")) frame = Frame(self) # left button frame buttonFrame = Frame(frame, width=40) buttonFrame.columnconfigure(0, weight=1) addLabel = Label(buttonFrame, text=_("Find plug-in modules:"), wraplength=60, justify="center") addLocalButton = Button(buttonFrame, text=_("Locally"), command=self.findLocally) ToolTip(addLocalButton, text=_("File chooser allows selecting python module files to add (or reload) plug-ins, from the local file system."), wraplength=240) addWebButton = Button(buttonFrame, text=_("On Web"), command=self.findOnWeb) ToolTip(addWebButton, text=_("Dialog to enter URL full path to load (or reload) plug-ins, from the web or local file system."), wraplength=240) addLabel.grid(row=0, column=0, pady=4) addLocalButton.grid(row=1, column=0, pady=4) addWebButton.grid(row=2, column=0, pady=4) buttonFrame.grid(row=0, column=0, rowspan=2, sticky=(N, S, W), padx=3, pady=3) # right tree frame (plugins already known to arelle) modulesFrame = Frame(frame, width=700) vScrollbar = Scrollbar(modulesFrame, orient=VERTICAL) hScrollbar = Scrollbar(modulesFrame, orient=HORIZONTAL) self.modulesView = Treeview(modulesFrame, xscrollcommand=hScrollbar.set, yscrollcommand=vScrollbar.set, height=7) self.modulesView.grid(row=0, column=0, sticky=(N, S, E, W)) self.modulesView.bind('<<TreeviewSelect>>', self.moduleSelect) hScrollbar["command"] = self.modulesView.xview hScrollbar.grid(row=1, column=0, sticky=(E,W)) vScrollbar["command"] = self.modulesView.yview vScrollbar.grid(row=0, column=1, sticky=(N,S)) modulesFrame.columnconfigure(0, weight=1) modulesFrame.rowconfigure(0, weight=1) modulesFrame.grid(row=0, column=1, columnspan=4, sticky=(N, S, E, W), padx=3, pady=3) self.modulesView.focus_set() self.modulesView.column("#0", width=120, anchor="w") self.modulesView.heading("#0", text=_("Name")) self.modulesView["columns"] = ("author", "ver", "status", "date", "update", "descr", "license") self.modulesView.column("author", width=100, anchor="w", stretch=False) self.modulesView.heading("author", text=_("Author")) self.modulesView.column("ver", width=50, anchor="w", stretch=False) self.modulesView.heading("ver", text=_("Version")) self.modulesView.column("status", width=50, anchor="w", stretch=False) self.modulesView.heading("status", text=_("Status")) self.modulesView.column("date", width=70, anchor="w", stretch=False) self.modulesView.heading("date", text=_("File Date")) self.modulesView.column("update", width=50, anchor="w", stretch=False) self.modulesView.heading("update", text=_("Update")) self.modulesView.column("descr", width=200, anchor="w", stretch=False) self.modulesView.heading("descr", text=_("Description")) self.modulesView.column("license", width=70, anchor="w", stretch=False) self.modulesView.heading("license", text=_("License")) classesFrame = Frame(frame) vScrollbar = Scrollbar(classesFrame, orient=VERTICAL) hScrollbar = Scrollbar(classesFrame, orient=HORIZONTAL) self.classesView = Treeview(classesFrame, xscrollcommand=hScrollbar.set, yscrollcommand=vScrollbar.set, height=5) self.classesView.grid(row=0, column=0, sticky=(N, S, E, W)) hScrollbar["command"] = self.classesView.xview hScrollbar.grid(row=1, column=0, sticky=(E,W)) vScrollbar["command"] = self.classesView.yview vScrollbar.grid(row=0, column=1, sticky=(N,S)) classesFrame.columnconfigure(0, weight=1) classesFrame.rowconfigure(0, weight=1) classesFrame.grid(row=1, column=1, columnspan=4, sticky=(N, S, E, W), padx=3, pady=3) self.classesView.focus_set() self.classesView.column("#0", width=200, anchor="w") self.classesView.heading("#0", text=_("Class")) self.classesView["columns"] = ("modules",) self.classesView.column("modules", width=500, anchor="w", stretch=False) self.classesView.heading("modules", text=_("Modules")) # bottom frame module info details moduleInfoFrame = Frame(frame, width=700) moduleInfoFrame.columnconfigure(1, weight=1) self.moduleNameLabel = Label(moduleInfoFrame, wraplength=600, justify="left", font=font.Font(family='Helvetica', size=12, weight='bold')) self.moduleNameLabel.grid(row=0, column=0, columnspan=4, sticky=W) self.moduleAuthorHdr = Label(moduleInfoFrame, text=_("author:"), state=DISABLED) self.moduleAuthorHdr.grid(row=1, column=0, sticky=W) self.moduleAuthorLabel = Label(moduleInfoFrame, wraplength=600, justify="left") self.moduleAuthorLabel.grid(row=1, column=1, columnspan=3, sticky=W) self.moduleDescrHdr = Label(moduleInfoFrame, text=_("description:"), state=DISABLED) self.moduleDescrHdr.grid(row=2, column=0, sticky=W) self.moduleDescrLabel = Label(moduleInfoFrame, wraplength=600, justify="left") self.moduleDescrLabel.grid(row=2, column=1, columnspan=3, sticky=W) self.moduleClassesHdr = Label(moduleInfoFrame, text=_("classes:"), state=DISABLED) self.moduleClassesHdr.grid(row=3, column=0, sticky=W) self.moduleClassesLabel = Label(moduleInfoFrame, wraplength=600, justify="left") self.moduleClassesLabel.grid(row=3, column=1, columnspan=3, sticky=W) ToolTip(self.moduleClassesLabel, text=_("List of classes that this plug-in handles."), wraplength=240) self.moduleUrlHdr = Label(moduleInfoFrame, text=_("URL:"), state=DISABLED) self.moduleUrlHdr.grid(row=4, column=0, sticky=W) self.moduleUrlLabel = Label(moduleInfoFrame, wraplength=600, justify="left") self.moduleUrlLabel.grid(row=4, column=1, columnspan=3, sticky=W) ToolTip(self.moduleUrlLabel, text=_("URL of plug-in module (local file path or web loaded file)."), wraplength=240) self.moduleDateHdr = Label(moduleInfoFrame, text=_("date:"), state=DISABLED) self.moduleDateHdr.grid(row=5, column=0, sticky=W) self.moduleDateLabel = Label(moduleInfoFrame, wraplength=600, justify="left") self.moduleDateLabel.grid(row=5, column=1, columnspan=3, sticky=W) ToolTip(self.moduleDateLabel, text=_("Date of currently loaded module file (with parenthetical node when an update is available)."), wraplength=240) self.moduleLicenseHdr = Label(moduleInfoFrame, text=_("license:"), state=DISABLED) self.moduleLicenseHdr.grid(row=6, column=0, sticky=W) self.moduleLicenseLabel = Label(moduleInfoFrame, wraplength=600, justify="left") self.moduleLicenseLabel.grid(row=6, column=1, columnspan=3, sticky=W) self.moduleEnableButton = Button(moduleInfoFrame, text=self.ENABLE, state=DISABLED, command=self.moduleEnable) ToolTip(self.moduleEnableButton, text=_("Enable/disable plug in."), wraplength=240) self.moduleEnableButton.grid(row=7, column=1, sticky=E) self.moduleReloadButton = Button(moduleInfoFrame, text=_("Reload"), state=DISABLED, command=self.moduleReload) ToolTip(self.moduleReloadButton, text=_("Reload/update plug in."), wraplength=240) self.moduleReloadButton.grid(row=7, column=2, sticky=E) self.moduleRemoveButton = Button(moduleInfoFrame, text=_("Remove"), state=DISABLED, command=self.moduleRemove) ToolTip(self.moduleRemoveButton, text=_("Remove plug in from plug in table (does not erase the plug in's file)."), wraplength=240) self.moduleRemoveButton.grid(row=7, column=3, sticky=E) moduleInfoFrame.grid(row=2, column=0, columnspan=5, sticky=(N, S, E, W), padx=3, pady=3) moduleInfoFrame.config(borderwidth=4, relief="groove") okButton = Button(frame, text=_("Close"), command=self.ok) ToolTip(okButton, text=_("Accept and changes (if any) and close dialog."), wraplength=240) cancelButton = Button(frame, text=_("Cancel"), command=self.close) ToolTip(cancelButton, text=_("Cancel changes (if any) and close dialog."), wraplength=240) okButton.grid(row=3, column=3, sticky=(S,E), pady=3) cancelButton.grid(row=3, column=4, sticky=(S,E), pady=3, padx=3) enableDisableFrame = Frame(frame) enableDisableFrame.grid(row=3, column=1, sticky=(S,W), pady=3) enableAllButton = Button(enableDisableFrame, text=_("Enable All"), command=self.enableAll) ToolTip(enableAllButton, text=_("Enable all plug ins."), wraplength=240) disableAllButton = Button(enableDisableFrame, text=_("Disable All"), command=self.disableAll) ToolTip(disableAllButton, text=_("Disable all plug ins."), wraplength=240) enableAllButton.grid(row=1, column=1) disableAllButton.grid(row=1, column=2) self.loadTreeViews() self.geometry("+{0}+{1}".format(dialogX+50,dialogY+100)) frame.grid(row=0, column=0, sticky=(N,S,E,W)) frame.columnconfigure(0, weight=0) frame.columnconfigure(1, weight=1) frame.rowconfigure(0, weight=1) window = self.winfo_toplevel() window.columnconfigure(0, weight=1) window.rowconfigure(0, weight=1) self.bind("<Return>", self.ok) self.bind("<Escape>", self.close) self.protocol("WM_DELETE_WINDOW", self.close) self.grab_set() self.wait_window(self)
def __init__(self, mainWin, packageNamesWithNewerFileDates): super(DialogPackageManager, self).__init__(mainWin.parent) self.ENABLE = _("Enable") self.DISABLE = _("Disable") self.parent = mainWin.parent self.cntlr = mainWin # copy plugins for temporary display self.packagesConfig = PackageManager.packagesConfig self.packagesConfigChanged = False self.packageNamesWithNewerFileDates = packageNamesWithNewerFileDates parentGeometry = re.match("(\d+)x(\d+)[+]?([-]?\d+)[+]?([-]?\d+)", self.parent.geometry()) dialogX = int(parentGeometry.group(3)) dialogY = int(parentGeometry.group(4)) self.title(_("Taxonomy Packages Manager")) frame = Frame(self) # left button frame buttonFrame = Frame(frame, width=40) buttonFrame.columnconfigure(0, weight=1) addLabel = Label(buttonFrame, text=_("Find taxonomy packages:"), wraplength=64, justify="center") addLocalButton = Button(buttonFrame, text=_("Locally"), command=self.findLocally) ToolTip(addLocalButton, text=_("File chooser allows selecting taxonomy packages to add (or reload), from the local file system. " "Select either a taxonomy package zip file, or a taxonomy manifest (.taxonomyPackage.xml) within an unzipped taxonomy package. "), wraplength=240) addWebButton = Button(buttonFrame, text=_("On Web"), command=self.findOnWeb) ToolTip(addWebButton, text=_("Dialog to enter URL full path to load (or reload) package, from the web or local file system. " "URL may be either a taxonomy package zip file, or a taxonomy manifest (.taxonomyPackage.xml) within an unzipped taxonomy package. "), wraplength=240) manifestNameButton = Button(buttonFrame, text=_("Manifest"), command=self.manifestName) ToolTip(manifestNameButton, text=_("Provide non-standard archive manifest file name pattern (e.g., *taxonomyPackage.xml). " "Uses unix file name pattern matching. " "Multiple manifest files are supported in archive (such as oasis catalogs). " "(Replaces search for either .taxonomyPackage.xml or catalog.xml). "), wraplength=240) self.manifestNamePattern = "" addLabel.grid(row=0, column=0, pady=4) addLocalButton.grid(row=1, column=0, pady=4) addWebButton.grid(row=2, column=0, pady=4) manifestNameButton.grid(row=3, column=0, pady=4) buttonFrame.grid(row=0, column=0, rowspan=3, sticky=(N, S, W), padx=3, pady=3) # right tree frame (packages already known to arelle) packagesFrame = Frame(frame, width=700) vScrollbar = Scrollbar(packagesFrame, orient=VERTICAL) hScrollbar = Scrollbar(packagesFrame, orient=HORIZONTAL) self.packagesView = Treeview(packagesFrame, xscrollcommand=hScrollbar.set, yscrollcommand=vScrollbar.set, height=7) self.packagesView.grid(row=0, column=0, sticky=(N, S, E, W)) self.packagesView.bind('<<TreeviewSelect>>', self.packageSelect) hScrollbar["command"] = self.packagesView.xview hScrollbar.grid(row=1, column=0, sticky=(E,W)) vScrollbar["command"] = self.packagesView.yview vScrollbar.grid(row=0, column=1, sticky=(N,S)) packagesFrame.columnconfigure(0, weight=1) packagesFrame.rowconfigure(0, weight=1) packagesFrame.grid(row=0, column=1, columnspan=4, sticky=(N, S, E, W), padx=3, pady=3) self.packagesView.focus_set() self.packagesView.column("#0", width=120, anchor="w") self.packagesView.heading("#0", text=_("Name")) self.packagesView["columns"] = ("ver", "status", "date", "update", "descr") self.packagesView.column("ver", width=150, anchor="w", stretch=False) self.packagesView.heading("ver", text=_("Version")) self.packagesView.column("status", width=50, anchor="w", stretch=False) self.packagesView.heading("status", text=_("Status")) self.packagesView.column("date", width=170, anchor="w", stretch=False) self.packagesView.heading("date", text=_("File Date")) self.packagesView.column("update", width=50, anchor="w", stretch=False) self.packagesView.heading("update", text=_("Update")) self.packagesView.column("descr", width=200, anchor="w", stretch=False) self.packagesView.heading("descr", text=_("Description")) remappingsFrame = Frame(frame) vScrollbar = Scrollbar(remappingsFrame, orient=VERTICAL) hScrollbar = Scrollbar(remappingsFrame, orient=HORIZONTAL) self.remappingsView = Treeview(remappingsFrame, xscrollcommand=hScrollbar.set, yscrollcommand=vScrollbar.set, height=5) self.remappingsView.grid(row=0, column=0, sticky=(N, S, E, W)) hScrollbar["command"] = self.remappingsView.xview hScrollbar.grid(row=1, column=0, sticky=(E,W)) vScrollbar["command"] = self.remappingsView.yview vScrollbar.grid(row=0, column=1, sticky=(N,S)) remappingsFrame.columnconfigure(0, weight=1) remappingsFrame.rowconfigure(0, weight=1) remappingsFrame.grid(row=1, column=1, columnspan=4, sticky=(N, S, E, W), padx=3, pady=3) self.remappingsView.focus_set() self.remappingsView.column("#0", width=200, anchor="w") self.remappingsView.heading("#0", text=_("Prefix")) self.remappingsView["columns"] = ("remapping") self.remappingsView.column("remapping", width=500, anchor="w", stretch=False) self.remappingsView.heading("remapping", text=_("Remapping")) # bottom frame package info details packageInfoFrame = Frame(frame, width=700) packageInfoFrame.columnconfigure(1, weight=1) self.packageNameLabel = Label(packageInfoFrame, wraplength=600, justify="left", font=font.Font(family='Helvetica', size=12, weight='bold')) self.packageNameLabel.grid(row=0, column=0, columnspan=6, sticky=W) self.packageVersionHdr = Label(packageInfoFrame, text=_("version:"), state=DISABLED) self.packageVersionHdr.grid(row=1, column=0, sticky=W) self.packageVersionLabel = Label(packageInfoFrame, wraplength=600, justify="left") self.packageVersionLabel.grid(row=1, column=1, columnspan=5, sticky=W) self.packageDescrHdr = Label(packageInfoFrame, text=_("description:"), state=DISABLED) self.packageDescrHdr.grid(row=2, column=0, sticky=W) self.packageDescrLabel = Label(packageInfoFrame, wraplength=600, justify="left") self.packageDescrLabel.grid(row=2, column=1, columnspan=5, sticky=W) self.packagePrefixesHdr = Label(packageInfoFrame, text=_("prefixes:"), state=DISABLED) self.packagePrefixesHdr.grid(row=3, column=0, sticky=W) self.packagePrefixesLabel = Label(packageInfoFrame, wraplength=600, justify="left") self.packagePrefixesLabel.grid(row=3, column=1, columnspan=5, sticky=W) ToolTip(self.packagePrefixesLabel, text=_("List of prefixes that this package remaps."), wraplength=240) self.packageUrlHdr = Label(packageInfoFrame, text=_("URL:"), state=DISABLED) self.packageUrlHdr.grid(row=4, column=0, sticky=W) self.packageUrlLabel = Label(packageInfoFrame, wraplength=600, justify="left") self.packageUrlLabel.grid(row=4, column=1, columnspan=5, sticky=W) ToolTip(self.packageUrlLabel, text=_("URL of taxonomy package (local file path or web loaded file)."), wraplength=240) self.packageDateHdr = Label(packageInfoFrame, text=_("date:"), state=DISABLED) self.packageDateHdr.grid(row=5, column=0, sticky=W) self.packageDateLabel = Label(packageInfoFrame, wraplength=600, justify="left") self.packageDateLabel.grid(row=5, column=1, columnspan=5, sticky=W) ToolTip(self.packageDateLabel, text=_("Date of currently loaded package file (with parenthetical node when an update is available)."), wraplength=240) self.packageEnableButton = Button(packageInfoFrame, text=self.ENABLE, state=DISABLED, command=self.packageEnable) ToolTip(self.packageEnableButton, text=_("Enable/disable package."), wraplength=240) self.packageEnableButton.grid(row=6, column=1, sticky=E) self.packageMoveUpButton = Button(packageInfoFrame, text=_("Move Up"), state=DISABLED, command=self.packageMoveUp) ToolTip(self.packageMoveUpButton, text=_("Move package up (above other remappings)."), wraplength=240) self.packageMoveUpButton.grid(row=6, column=2, sticky=E) self.packageMoveDownButton = Button(packageInfoFrame, text=_("Move Down"), state=DISABLED, command=self.packageMoveDown) ToolTip(self.packageMoveDownButton, text=_("Move package down (below other remappings)."), wraplength=240) self.packageMoveDownButton.grid(row=6, column=3, sticky=E) self.packageReloadButton = Button(packageInfoFrame, text=_("Reload"), state=DISABLED, command=self.packageReload) ToolTip(self.packageReloadButton, text=_("Reload/update package."), wraplength=240) self.packageReloadButton.grid(row=6, column=4, sticky=E) self.packageRemoveButton = Button(packageInfoFrame, text=_("Remove"), state=DISABLED, command=self.packageRemove) ToolTip(self.packageRemoveButton, text=_("Remove package from packages table (does not erase the package file)."), wraplength=240) self.packageRemoveButton.grid(row=6, column=5, sticky=E) packageInfoFrame.grid(row=2, column=0, columnspan=5, sticky=(N, S, E, W), padx=3, pady=3) packageInfoFrame.config(borderwidth=4, relief="groove") okButton = Button(frame, text=_("Close"), command=self.ok) ToolTip(okButton, text=_("Accept and changes (if any) and close dialog."), wraplength=240) cancelButton = Button(frame, text=_("Cancel"), command=self.close) ToolTip(cancelButton, text=_("Cancel changes (if any) and close dialog."), wraplength=240) okButton.grid(row=3, column=3, sticky=(S,E), pady=3) cancelButton.grid(row=3, column=4, sticky=(S,E), pady=3, padx=3) self.loadTreeViews() self.geometry("+{0}+{1}".format(dialogX+50,dialogY+100)) frame.grid(row=0, column=0, sticky=(N,S,E,W)) frame.columnconfigure(0, weight=0) frame.columnconfigure(1, weight=1) frame.rowconfigure(0, weight=1) window = self.winfo_toplevel() window.columnconfigure(0, weight=1) window.rowconfigure(0, weight=1) self.bind("<Return>", self.ok) self.bind("<Escape>", self.close) self.protocol("WM_DELETE_WINDOW", self.close) self.grab_set() self.wait_window(self)
class LDAPConsole(Frame): def __init__(self): super().__init__() self.initConsole() def initConsole(self): self.master.title("LDAP Management Console") self.style = Style() self.style.theme_use("alt") ## Frame principal. self.pack(fill=BOTH, expand=1) ## Creacion de barra de menus. menubar = Menu(self.master) self.master.config(menu=menubar) ## Seccion File del menu. fileMenu = Menu(menubar, tearoff=0) fileMenu.add_command(label="Connect", command=self.OpenConnection) fileMenu.add_command(label="Disconnect", command=self.CloseConnection) fileMenu.add_separator() fileMenu.add_command(label="Exit", command=self.ExitOption) menubar.add_cascade(label="File", menu=fileMenu) ## Seccion Advanced del menu. AdvancedMenu = Menu(menubar, tearoff=0) AdvancedMenu.add_command(label="Display Options") AdvancedMenu.add_command(label="Verify") AdvancedMenu.add_command(label="Configure") menubar.add_cascade(label="Advanced", menu=AdvancedMenu) ## Seccion Help del menu. HelpMenu = Menu(menubar, tearoff=0) HelpMenu.add_command(label="Show Help") HelpMenu.add_command(label="About LDAP GUI") menubar.add_cascade(label="Help", menu=HelpMenu) ## Definicion de frames secundarios anidados en el principal. ## Nuevo frame para contener la representacion del arbol de directorio. self.treeNavFrame = Frame(self) self.treeNavFrame.config(relief=RAISED, borderwidth=2) self.treeNavCanvas = Canvas(self.treeNavFrame, bg="white", width=200, height=120) self.treeNavCanvas.pack(fill=Y, side=LEFT) self.treeNavFrame.pack(fill=Y, side=LEFT) ## Nuevo frame para contener la información de objetos seleccionados. self.infoFrame = Frame(self) self.infoFrame.config(relief=RAISED, borderwidth=2) self.infoFrameCanvas = Canvas(self.infoFrame, bg="white", width=500, height=400) self.infoFrameCanvas.pack(fill=X, anchor=NE) self.infoFrame.pack(fill=X, anchor=NE) def ExitOption(self): self.quit() def OpenConnection(self): self.quit() def CloseConnection(self): self.quit()
def __init__(self, mainWin, packageNamesWithNewerFileDates): super(DialogPackageManager, self).__init__(mainWin.parent) self.ENABLE = _("Enable") self.DISABLE = _("Disable") self.parent = mainWin.parent self.cntlr = mainWin # copy plugins for temporary display self.packagesConfig = PackageManager.packagesConfig self.packagesConfigChanged = False self.packageNamesWithNewerFileDates = packageNamesWithNewerFileDates parentGeometry = re.match("(\d+)x(\d+)[+]?([-]?\d+)[+]?([-]?\d+)", self.parent.geometry()) dialogX = int(parentGeometry.group(3)) dialogY = int(parentGeometry.group(4)) self.title(_("Taxonomy Packages Manager")) frame = Frame(self) # left button frame buttonFrame = Frame(frame, width=40) buttonFrame.columnconfigure(0, weight=1) addLabel = Label(buttonFrame, text=_("Find taxonomy packages:"), wraplength=64, justify="center") addLocalButton = Button(buttonFrame, text=_("Locally"), command=self.findLocally) ToolTip(addLocalButton, text=_("File chooser allows selecting taxonomy packages to add (or reload), from the local file system. " "Select either a PWD or prior taxonomy package zip file, or a taxonomy manifest (.taxonomyPackage.xml) within an unzipped taxonomy package. "), wraplength=360) addWebButton = Button(buttonFrame, text=_("On Web"), command=self.findOnWeb) ToolTip(addWebButton, text=_("Dialog to enter URL full path to load (or reload) package, from the web or local file system. " "URL may be either a PWD or prior taxonomy package zip file, or a taxonomy manifest (.taxonomyPackage.xml) within an unzipped taxonomy package. "), wraplength=360) manifestNameButton = Button(buttonFrame, text=_("Manifest"), command=self.manifestName) ToolTip(manifestNameButton, text=_("Provide pre-PWD non-standard archive manifest file name pattern (e.g., *taxonomyPackage.xml). " "Uses unix file name pattern matching. " "Multiple manifest files are supported in pre-PWD archives (such as oasis catalogs). " "(Replaces pre-PWD search for either .taxonomyPackage.xml or catalog.xml). "), wraplength=480) self.manifestNamePattern = "" addLabel.grid(row=0, column=0, pady=4) addLocalButton.grid(row=1, column=0, pady=4) addWebButton.grid(row=2, column=0, pady=4) manifestNameButton.grid(row=3, column=0, pady=4) buttonFrame.grid(row=0, column=0, rowspan=3, sticky=(N, S, W), padx=3, pady=3) # right tree frame (packages already known to arelle) packagesFrame = Frame(frame, width=700) vScrollbar = Scrollbar(packagesFrame, orient=VERTICAL) hScrollbar = Scrollbar(packagesFrame, orient=HORIZONTAL) self.packagesView = Treeview(packagesFrame, xscrollcommand=hScrollbar.set, yscrollcommand=vScrollbar.set, height=7) self.packagesView.grid(row=0, column=0, sticky=(N, S, E, W)) self.packagesView.bind('<<TreeviewSelect>>', self.packageSelect) hScrollbar["command"] = self.packagesView.xview hScrollbar.grid(row=1, column=0, sticky=(E,W)) vScrollbar["command"] = self.packagesView.yview vScrollbar.grid(row=0, column=1, sticky=(N,S)) packagesFrame.columnconfigure(0, weight=1) packagesFrame.rowconfigure(0, weight=1) packagesFrame.grid(row=0, column=1, columnspan=4, sticky=(N, S, E, W), padx=3, pady=3) self.packagesView.focus_set() self.packagesView.column("#0", width=120, anchor="w") self.packagesView.heading("#0", text=_("Name")) self.packagesView["columns"] = ("ver", "status", "date", "update", "descr") self.packagesView.column("ver", width=150, anchor="w", stretch=False) self.packagesView.heading("ver", text=_("Version")) self.packagesView.column("status", width=50, anchor="w", stretch=False) self.packagesView.heading("status", text=_("Status")) self.packagesView.column("date", width=170, anchor="w", stretch=False) self.packagesView.heading("date", text=_("File Date")) self.packagesView.column("update", width=50, anchor="w", stretch=False) self.packagesView.heading("update", text=_("Update")) self.packagesView.column("descr", width=200, anchor="w", stretch=False) self.packagesView.heading("descr", text=_("Description")) remappingsFrame = Frame(frame) vScrollbar = Scrollbar(remappingsFrame, orient=VERTICAL) hScrollbar = Scrollbar(remappingsFrame, orient=HORIZONTAL) self.remappingsView = Treeview(remappingsFrame, xscrollcommand=hScrollbar.set, yscrollcommand=vScrollbar.set, height=5) self.remappingsView.grid(row=0, column=0, sticky=(N, S, E, W)) hScrollbar["command"] = self.remappingsView.xview hScrollbar.grid(row=1, column=0, sticky=(E,W)) vScrollbar["command"] = self.remappingsView.yview vScrollbar.grid(row=0, column=1, sticky=(N,S)) remappingsFrame.columnconfigure(0, weight=1) remappingsFrame.rowconfigure(0, weight=1) remappingsFrame.grid(row=1, column=1, columnspan=4, sticky=(N, S, E, W), padx=3, pady=3) self.remappingsView.focus_set() self.remappingsView.column("#0", width=200, anchor="w") self.remappingsView.heading("#0", text=_("Prefix")) self.remappingsView["columns"] = ("remapping") self.remappingsView.column("remapping", width=500, anchor="w", stretch=False) self.remappingsView.heading("remapping", text=_("Remapping")) # bottom frame package info details packageInfoFrame = Frame(frame, width=700) packageInfoFrame.columnconfigure(1, weight=1) self.packageNameLabel = Label(packageInfoFrame, wraplength=600, justify="left", font=font.Font(family='Helvetica', size=12, weight='bold')) self.packageNameLabel.grid(row=0, column=0, columnspan=6, sticky=W) self.packageVersionHdr = Label(packageInfoFrame, text=_("version:"), state=DISABLED) self.packageVersionHdr.grid(row=1, column=0, sticky=W) self.packageVersionLabel = Label(packageInfoFrame, wraplength=600, justify="left") self.packageVersionLabel.grid(row=1, column=1, columnspan=5, sticky=W) self.packageDescrHdr = Label(packageInfoFrame, text=_("description:"), state=DISABLED) self.packageDescrHdr.grid(row=2, column=0, sticky=W) self.packageDescrLabel = Label(packageInfoFrame, wraplength=600, justify="left") self.packageDescrLabel.grid(row=2, column=1, columnspan=5, sticky=W) self.packagePrefixesHdr = Label(packageInfoFrame, text=_("prefixes:"), state=DISABLED) self.packagePrefixesHdr.grid(row=3, column=0, sticky=W) self.packagePrefixesLabel = Label(packageInfoFrame, wraplength=600, justify="left") self.packagePrefixesLabel.grid(row=3, column=1, columnspan=5, sticky=W) ToolTip(self.packagePrefixesLabel, text=_("List of prefixes that this package remaps."), wraplength=240) self.packageUrlHdr = Label(packageInfoFrame, text=_("URL:"), state=DISABLED) self.packageUrlHdr.grid(row=4, column=0, sticky=W) self.packageUrlLabel = Label(packageInfoFrame, wraplength=600, justify="left") self.packageUrlLabel.grid(row=4, column=1, columnspan=5, sticky=W) ToolTip(self.packageUrlLabel, text=_("URL of taxonomy package (local file path or web loaded file)."), wraplength=240) self.packageDateHdr = Label(packageInfoFrame, text=_("date:"), state=DISABLED) self.packageDateHdr.grid(row=5, column=0, sticky=W) self.packageDateLabel = Label(packageInfoFrame, wraplength=600, justify="left") self.packageDateLabel.grid(row=5, column=1, columnspan=5, sticky=W) ToolTip(self.packageDateLabel, text=_("Date of currently loaded package file (with parenthetical node when an update is available)."), wraplength=240) self.packageEnableButton = Button(packageInfoFrame, text=self.ENABLE, state=DISABLED, command=self.packageEnable) ToolTip(self.packageEnableButton, text=_("Enable/disable package."), wraplength=240) self.packageEnableButton.grid(row=6, column=1, sticky=E) self.packageMoveUpButton = Button(packageInfoFrame, text=_("Move Up"), state=DISABLED, command=self.packageMoveUp) ToolTip(self.packageMoveUpButton, text=_("Move package up (above other remappings)."), wraplength=240) self.packageMoveUpButton.grid(row=6, column=2, sticky=E) self.packageMoveDownButton = Button(packageInfoFrame, text=_("Move Down"), state=DISABLED, command=self.packageMoveDown) ToolTip(self.packageMoveDownButton, text=_("Move package down (below other remappings)."), wraplength=240) self.packageMoveDownButton.grid(row=6, column=3, sticky=E) self.packageReloadButton = Button(packageInfoFrame, text=_("Reload"), state=DISABLED, command=self.packageReload) ToolTip(self.packageReloadButton, text=_("Reload/update package."), wraplength=240) self.packageReloadButton.grid(row=6, column=4, sticky=E) self.packageRemoveButton = Button(packageInfoFrame, text=_("Remove"), state=DISABLED, command=self.packageRemove) ToolTip(self.packageRemoveButton, text=_("Remove package from packages table (does not erase the package file)."), wraplength=240) self.packageRemoveButton.grid(row=6, column=5, sticky=E) packageInfoFrame.grid(row=2, column=0, columnspan=5, sticky=(N, S, E, W), padx=3, pady=3) packageInfoFrame.config(borderwidth=4, relief="groove") okButton = Button(frame, text=_("Close"), command=self.ok) ToolTip(okButton, text=_("Accept and changes (if any) and close dialog."), wraplength=240) cancelButton = Button(frame, text=_("Cancel"), command=self.close) ToolTip(cancelButton, text=_("Cancel changes (if any) and close dialog."), wraplength=240) okButton.grid(row=3, column=3, sticky=(S,E), pady=3) cancelButton.grid(row=3, column=4, sticky=(S,E), pady=3, padx=3) enableDisableFrame = Frame(frame) enableDisableFrame.grid(row=3, column=1, sticky=(S,W), pady=3) enableAllButton = Button(enableDisableFrame, text=_("Enable All"), command=self.enableAll) ToolTip(enableAllButton, text=_("Enable all packages."), wraplength=240) disableAllButton = Button(enableDisableFrame, text=_("Disable All"), command=self.disableAll) ToolTip(disableAllButton, text=_("Disable all packages."), wraplength=240) enableAllButton.grid(row=1, column=1) disableAllButton.grid(row=1, column=2) self.loadTreeViews() self.geometry("+{0}+{1}".format(dialogX+50,dialogY+100)) frame.grid(row=0, column=0, sticky=(N,S,E,W)) frame.columnconfigure(0, weight=0) frame.columnconfigure(1, weight=1) frame.rowconfigure(0, weight=1) window = self.winfo_toplevel() window.columnconfigure(0, weight=1) window.rowconfigure(0, weight=1) self.bind("<Return>", self.ok) self.bind("<Escape>", self.close) self.protocol("WM_DELETE_WINDOW", self.close) self.grab_set() self.wait_window(self)
class LDAPConsole(Frame): def __init__(self): super().__init__() self.initConsole() self.addMenuBar() self.createSections() def initConsole(self): self.master.title("LDAP Management Console") self.style = Style() self.style.theme_use("alt") ## Frame principal. self.pack(fill=BOTH, expand=1) def addMenuBar(self): ## Creacion de barra de menus. menubar = Menu(self.master) self.master.config(menu=menubar) ## Seccion File del menu. fileMenu = Menu(menubar, tearoff=0) fileMenu.add_command(label="Connect", command=self.OpenConnection) fileMenu.add_command(label="Disconnect", command=self.CloseConnection) fileMenu.add_separator() fileMenu.add_command(label="Exit", command=self.ExitOption) menubar.add_cascade(label="File", menu=fileMenu) ## Seccion Advanced del menu. AdvancedMenu = Menu(menubar, tearoff=0) AdvancedMenu.add_command(label="Display Options") AdvancedMenu.add_command(label="Verify") AdvancedMenu.add_command(label="Configure") menubar.add_cascade(label="Advanced", menu=AdvancedMenu) ## Seccion Help del menu. HelpMenu = Menu(menubar, tearoff=0) HelpMenu.add_command(label="Show Help") HelpMenu.add_command(label="About LDAP GUI") menubar.add_cascade(label="Help", menu=HelpMenu) def createSections(self): ## Definicion de frames secundarios anidados en el principal. ## Nuevo Frame para contener la representacion del arbol de ## directorio incluyendo las barras de desplazamiento. self.treeNavFrame = Frame(self) self.treeNavFrame.config(relief=RAISED, borderwidth=2) self.treeNavView = Treeview(self.treeNavFrame, show="tree", selectmode="browse") ## Definicion de barras de desplazamiento. ## La barra de desplazamiento tiene como padre el Frame pero controla ## el widget treeview. ### Barra de desplazamiento horizontal. self.HorScrollBar = Scrollbar(self.treeNavFrame, activerelief=RAISED, orient=HORIZONTAL) self.HorScrollBar.config(command=self.treeNavView.xview) self.HorScrollBar.pack(fill=X, side=BOTTOM) ### Barra de desplazamiento vertical. self.VerScrollBar = Scrollbar(self.treeNavFrame, activerelief=RAISED, orient=VERTICAL) self.VerScrollBar.config(command=self.treeNavView.yview) self.VerScrollBar.pack(fill=Y, side=RIGHT) self.treeNavFrame.pack(fill=BOTH, side=LEFT) self.treeNavView.pack(fill=BOTH, side=LEFT) self.treeNavView.config(xscrollcommand=self.HorScrollBar.set, yscrollcommand=self.VerScrollBar.set) ## Nuevo frame para contener la informacion de objetos seleccionados. self.infoFrame = Frame(self) self.infoFrame.config(relief=RAISED, borderwidth=2) self.infoFrameCanvas = Canvas(self.infoFrame, bg="white", width=500, height=400) self.infoFrameCanvas.pack(fill=X, anchor=NE) self.infoFrame.pack(fill=X, anchor=NE) def updateInfoSection(self, dntoSearch, infoToDisplay): try: self.infoFrameCanvas.delete("all") self.infoFrameCanvas.create_text(20, 20, font=("Liberation Serif Bold", 30, "bold"), anchor=W, text="{}".format(dntoSearch[0])) row = 50 self.infoFrameCanvas.create_text(20, row, font=("Liberation Serif Bold", 20), anchor=W, text="objectClass: ") for objclass in infoToDisplay[0]["attributes"]["objectClass"]: self.infoFrameCanvas.create_text(160, row, font=("Liberation Serif Bold", 10), anchor=W, text="{}".format(objclass)) row += 20 print(objclass) except: print("Error en updateInfoSection") def contextOperations(self, cadena, elLDAPObject, operationType): try: if (operationType == "REFRESH"): print("Refresh sobre {}.".format(cadena)) if (operationType == "ADD"): print("Nueva entrada sobre {}.".format(cadena)) if (operationType == "DELETE"): print("Borrar entrada sobre {}.".format(cadena)) if (operationType == "MOVE"): print("Mover entrada sobre {}.".format(cadena)) except: print("Error en contextOperations") def __oneRightClick(self, event, ldapconnectionobject): print("Right clicked mouse on line {}".format( event.widget.selection())) self.operationsMenu = Menu(self, tearoff=0, borderwidth=2, relief=RAISED) self.operationsMenu.add_command( label="Refresh tree", command=lambda: self.contextOperations(event.widget.selection( ), ldapconnectionobject, "REFRESH")) self.operationsMenu.add_separator() self.operationsMenu.add_command( label="Add Entry", command=lambda: self.contextOperations(event.widget.selection( ), ldapconnectionobject, "ADD")) self.operationsMenu.add_command( label="Delete Entry", command=lambda: self.contextOperations(event.widget.selection( ), ldapconnectionobject, "DELETE")) self.operationsMenu.add_command( label="Move Entry", command=lambda: self.contextOperations(event.widget.selection( ), ldapconnectionobject, "MOVE")) self.operationsMenu.tk_popup(self.treeNavView.winfo_pointerx(), self.treeNavView.winfo_pointery()) def __oneLeftClick(self, event, ldapconnectionobject): ## Por defecto, click sobre cualquier entrada provoca una busqueda de la misma. print("Left clicked mouse on line {}".format(event.widget.selection())) dntoSearch = event.widget.selection() print(dntoSearch[0]) ldapoperations.SearchLdap(ldapconnectionobject, rootSearch=dntoSearch[0], scopeSearch="BASE") self.updateInfoSection(dntoSearch, ldapconnectionobject.response) def DisplayAndBind(self, parentID, lineIDX, entryIID, textString, ldapconnectionobject, isOpen): self.treeNavView.insert(parentID, lineIDX, entryIID, open=isOpen, text=textString) def lefclickhandler(event, self=self, parameters=ldapconnectionobject): return self.__oneLeftClick(event, ldapconnectionobject) self.treeNavView.bind('<<TreeviewSelect>>', lefclickhandler) def rightclickhandler(event, self=self, parameters=ldapconnectionobject): return self.__oneRightClick(event, ldapconnectionobject) self.treeNavView.bind('<Button-3>', rightclickhandler) def ExitOption(self): self.quit() def OpenConnection(self): self.quit() def CloseConnection(self): self.quit()
class Application(Frame): def __init__(self): super().__init__() self.is_all_data = IntVar() self.selected_month_1 = StringVar() self.selected_year_1 = StringVar() self.selected_month_2 = StringVar() self.selected_year_2 = StringVar() self.selected_saham = StringVar() self.finished = False self.initUI() def initUI(self): self.master.title("Analisa Harga Saham") self.pack(fill=BOTH, expand=True) self.columnconfigure(1, weight=1) self.columnconfigure(3, pad=7) self.rowconfigure(3, weight=1) self.rowconfigure(5, pad=7) self.lbl = Label(self, text="Filename: ") self.lbl.grid(sticky=W, pady=4, padx=5, columnspan=4) self.right_frame = Frame(self, width=800, height=400, borderwidth = 1) self.right_frame.grid(row=2, column=1, columnspan=5, rowspan=4, padx=5, sticky=E+W+S+N) self.right_frame.config(relief=SOLID) self.area = Text(self.right_frame, height = 30, width = 40) self.area.grid(row=0, column=1, padx=5, sticky=W+S+N+E) self.splash = Toplevel(self.right_frame) self.splash.overrideredirect(True) self.splash.geometry('200x23+100+100') self.splash.overrideredirect(1) self.splash.bind("<B1-Motion>", self.move_window) self.splash.attributes('-topmost', 'true') window_height = 23 window_width = 400 screen_width = self.splash.winfo_screenwidth() screen_height = self.splash.winfo_screenheight() x_cordinate = int((screen_width/2) - (window_width/2)) y_cordinate = int((screen_height/2) - (window_height/2)) self.splash.geometry("{}x{}+{}+{}".format(window_width, window_height, x_cordinate, y_cordinate)) self.splash.withdraw() pb = Progressbar(self.splash, orient=HORIZONTAL, length=400) pb.config(mode='indeterminate') pb.start(10) pb.grid(row=1, column=1, sticky=W+E+S+N) # self.splash.withdraw() self.dp = DataProcessor() # upload # lblUpload = Label(self, text="upload") # lblUpload.grid(row=1, column=0, columnspan=2) abtn = Button(self, text="Upload", command=self.openFile) abtn.grid(row=1, column=0, sticky=W, padx=5) self.left_frame = Frame(self, width=200, height=400, borderwidth = 1) self.left_frame.grid(row=2, column=0) self.left_frame.config(relief=SOLID) # self.chkBox = Checkbutton(self.left_frame, text = "All data", variable=self.is_all_data, command=self.cbCallback) # self.chkBox.grid(row=1, column=0, sticky=W, padx=5) Separator(self.left_frame,orient=HORIZONTAL).grid(row=2, columnspan=1, ipadx=75, padx=5, sticky=W) self.rangeFrame = self.rangeFrame() #Frame(self.left_frame, borderwidth = 1) self.rangeFrame.grid(row=3, column=0, columnspan=2) # Button Filter self.btnFilter = Button(self.left_frame, text="Filter", command=self.callFilter) self.btnFilter.grid(row=4, column=0, sticky=W, padx=5) Separator(self.left_frame,orient=HORIZONTAL).grid(row=5, columnspan=1, ipadx=75, padx=5, sticky=W) self.txSaham = Text(self.left_frame) self.cbSaham = Combobox(self.left_frame, textvariable=self.selected_saham) self.cbSaham['values'] = [] #self.kodeSaham self.cbSaham['state'] = 'readonly' # normal self.cbSaham.set('-- Pilih Saham --') self.cbSaham.grid(row=7, column=0,padx=5, pady=5) # Buton Proses self.btnProses = Button(self.left_frame, text="proses", command=self.callProses) self.btnProses.grid(row=8, column=0, sticky=W, padx=5) Separator(self.left_frame,orient=HORIZONTAL).grid(row=9, columnspan=1, ipadx=75, padx=5, sticky=W) def rangeFrame(self): frame = Frame(self.left_frame, borderwidth = 1) months = ('01-Jan', '02-Feb', '03-Mar', '04-Apr', '05-May', '06-Jun', '07-Jul', '08-Aug', '09-Sep', '10-Oct', '11-Nov', '12-Dec') years = (2018, 2019, 2020, 2021) lblFrom = Label(frame, text='Dari') lblFrom.grid(row=1, column=0, sticky=W, padx=5) # start bulan month_cb_1 = Combobox(frame, textvariable=self.selected_month_1) month_cb_1['values'] = months month_cb_1['state'] = 'readonly' # normal month_cb_1.set('-- Pilih bulan --') month_cb_1.grid(row=2, column=0,padx=5, pady=5) # start tahun year_cb_1 = Combobox(frame, textvariable=self.selected_year_1) year_cb_1['values'] = years year_cb_1['state'] = 'readonly' # normal year_cb_1.set('-- Pilih tahun --') year_cb_1.grid(row=3, column=0,padx=5, pady=5) lblTo = Label(frame, text='Ke') lblTo.grid(row=4, column=0, sticky=W, padx=5) # end bulan month_cb_2 = Combobox(frame, textvariable=self.selected_month_2) month_cb_2['values'] = months month_cb_2['state'] = 'readonly' # normal month_cb_2.set('-- Pilih bulan --') month_cb_2.grid( row=5, column=0,padx=5, pady=5) # end tahun year_cb_2 = Combobox(frame, textvariable=self.selected_year_2) year_cb_2['values'] = years year_cb_2['state'] = 'readonly' # normal year_cb_2.set('-- Pilih tahun --') year_cb_2.grid(row=6, column=0,padx=5, pady=5) return frame # open data file def openFile(self): name = fd.askopenfilename() self.lbl['text'] = self.lbl['text']+' '+name self.splash.deiconify() msg = self.dp.load(name) self.splash.withdraw() messagebox.showinfo("Info", msg) # show and hide frame def cbCallback(self): if(self.is_all_data.get() == 1): self.rangeFrame.grid_forget() else: self.rangeFrame.grid() def disableButton(self, disable=True): if disable: self.btnFilter['state'] = DISABLED self.btnProses['state'] = DISABLED else: self.btnFilter['state'] = NORMAL self.btnProses['state'] = NORMAL ''' filter data berdasarkan bulan dipilih ''' def filter(self): if self.dp.df is None: messagebox.showerror("Error", "Data kosong, silahkan upload data") return if 'messages' not in self.dp.df.columns: messagebox.showerror("Error", "Data tidak sesuai atau bukan dari log Telegram") return if 'pilih' in self.selected_year_1.get().lower() or 'pilih' in self.selected_month_1.get().lower(): messagebox.showerror("Error", "Bulan dan Tahun awal harus dipilih!") return self.disableButton() self.splash.deiconify() if(self.is_all_data.get()==1): self.dp.filter(awal = '0000', akhir='0000') else: if('Pilih' not in ''.join([self.selected_year_1.get(),self.selected_month_1.get()]) and 'Pilih' in ''.join([self.selected_year_2.get(),self.selected_month_2.get()])): self.dp.filter(awal = str(self.selected_year_1.get())+'-'+self.selected_month_1.get()[:2], akhir = '0000') else: awal = str(self.selected_year_1.get())+'-'+self.selected_month_1.get()[:2] akhir = str(self.selected_year_2.get())+'-'+self.selected_month_2.get()[:2] if datetime.datetime.strptime(awal, '%Y-%m') > datetime.datetime.strptime(akhir, '%Y-%m'): self.disableButton(False) self.splash.withdraw() messagebox.showerror("Error", "Waktu awal > Waktu akhir") return self.dp.filter(awal = awal, akhir = akhir) print(self.dp.dffilter) lst = self.dp.getKodeSaham() self.cbSaham['values'] = lst self.splash.withdraw() messagebox.showinfo("Info", "filter selesai") self.disableButton(False) def callFilter(self): threading.Thread(target=self.filter).start() ''' sanding data dari 2 paket data: mentions counter dan price dari yfinance plot line graph ''' def proses(self): if self.dp.dffilter is None: messagebox.showerror("Error", "Data kosong silahkan filter data terlebih dahulu") return stockcode = self.cbSaham.get() if 'pilih' in stockcode.lower(): messagebox.showerror("Error", "Kode saham belum dipilih!") return stockcode = stockcode.split()[0] self.disableButton() self.splash.deiconify() '''if(len(self.txSaham.get())>0): stockcode = self.txSaham.get()''' # menghitung frekuensi mentions saham di chat dfa = self.dp.getCount(stockcode) print('dfa ',dfa.shape) # mendapatkan stock price's series from yahoo finance self.company_name, stockprice, dfstock = self.dp.getPergerakanHargaSaham(stockcode) print('dfstock ', dfstock.shape) # sanding data self.dfnorm, dfbefnorm = self.dp.sandingData(dfa, stockprice) print('sandingData--- ') self.area.delete('1.0', END) self.area.insert(END, 'correlation {0}\n\n {1}'.format(self.dp.corr(self.dfnorm), dfbefnorm)) # # plot # self.plot(self.right_frame, self.dfnorm, self.company_name) self.finished = True self.disableButton(False) self.splash.withdraw() def callProses(self): # kami memanfaatkan link ini untuk mengetahui bahwa thread sudah selesai # https://stackoverflow.com/a/56010976 POLLING_DELAY = 250 # ms lock = threading.Lock() # Lock for shared resources. def check_status(): with lock: if not self.finished: self.after(POLLING_DELAY, check_status) # Keep polling. else: self.plot(self.right_frame, self.dfnorm, self.company_name) with lock: self.finished = False t = threading.Thread(target=self.proses) t.daemon = True self.after(POLLING_DELAY, check_status) # Start polling. t.start() def move_window(self, e): self.splash.geometry(f'+{e.x_root}+{e.y_root}') def plot(self, root, dfa1, company_name): print('plot') figure1 = plt.Figure(figsize=(9,5), dpi=100) ax1 = figure1.add_subplot(111) bar1 = FigureCanvasTkAgg(figure1, root) bar1.get_tk_widget().grid(row=0, column=2) df1 = dfa1[['date','mentions']].groupby('date').sum() df1.plot( kind='line', legend=True, ax=ax1, color='skyblue',marker='o', fontsize=10) df2 = dfa1[['date', 'price']].groupby('date').sum() df2.plot( kind='line', legend=True, ax=ax1, marker='', color='olive', linewidth=2) # plt.legend() ax1.set_title("Pergerakan Harga Saham "+company_name)
cache.set('m3u8_stop', False) root = tkinter.Tk() root.title('综艺玩很大 转播程序 v' + str(version)) # 设置windows窗口图标 if platform == 'win32': icon = resource_path.path('icon.ico') print('icon', icon) root.iconbitmap(icon) # 禁止改变窗口大小 # root.resizable(False, False) root.minsize(450, 650) frame = Frame(root) frame.config(padding=5) frame.pack(fill=tkinter.BOTH, expand=True) # 流程开始 logger = Logger(root) logger.loop() menu = menu.Menu(root=root, cache=cache, logger=logger) local = layout_local.Frame(root=frame, my_cache=my_cache) video = layout_video.Frame(root=frame, my_cache=my_cache) url = layout_url.Frame(root=frame)
def plot_univ_on_GUI(self): if not self.current_simulation: return if len(self.current_simulation.results) == self.last_results_plotted: return self.last_results_plotted = len(self.current_simulation.results) current_var = self.current_simulation.vars_to_change[0] if self.current_simulation.results: results = concat(self.current_simulation.results).sort_index() results = results[[d is not None for d in results['MFSP']]] # filter to make sure you aren't plotting None results else: results = DataFrame(columns=self.output_columns) fig_list =[] var_fig = Figure(figsize = (3,3), facecolor=[240/255,240/255,237/255], tight_layout=True) a = var_fig.add_subplot(111) num_bins = 15 _, bins, _ = a.hist(self.simulation_dist[current_var], num_bins, facecolor='white',edgecolor='black', alpha=1.0) a.hist(results[current_var], bins=bins, facecolor='blue',edgecolor='black', alpha=1.0) a.set_title(current_var) fig_list.append(var_fig) mfsp_fig = Figure(figsize = (3,3), facecolor=[240/255,240/255,237/255], tight_layout=True) b = mfsp_fig.add_subplot(111) b.hist(results['MFSP'], num_bins, facecolor='blue', edgecolor='black', alpha=1.0) b.set_title('MFSP - ' + current_var) fig_list.append(mfsp_fig) figs_to_plot = self.finished_figures[:] + fig_list if len(self.current_simulation.results) == self.current_simulation.tot_sim: self.finished_figures += fig_list if self.univar_row_num != 0: row_num = 17 else: row_num = 10 frame_canvas = Frame(self.current_tab) frame_canvas.grid(row=row_num, column=1, columnspan = 3,pady=(5, 0)) frame_canvas.grid_rowconfigure(0, weight=1) frame_canvas.grid_columnconfigure(0, weight=1) frame_canvas.config(height = '10c', width='16c') main_canvas = Canvas(frame_canvas) main_canvas.grid(row=0, column=0, sticky="news") main_canvas.config(height = '10c', width='16c') vsb = Scrollbar(frame_canvas, orient="vertical", command=main_canvas.yview) vsb.grid(row=0, column=1,sticky = 'ns') main_canvas.configure(yscrollcommand=vsb.set) figure_frame = Frame(main_canvas) main_canvas.create_window((0, 0), window=figure_frame, anchor='nw') figure_frame.config(height = '10c', width='16c') row_num = 0 column = False for figs in figs_to_plot: figure_canvas = FigureCanvasTkAgg(figs, master=figure_frame) if column: col = 4 else: col = 1 #figure_canvas.draw() figure_canvas.get_tk_widget().grid( row=row_num, column=col,columnspan=2, rowspan = 5, pady = 5,padx = 8, sticky=E) #figure_canvas._tkcanvas.grid(row=row_num, column = 0,columnspan = 10, rowspan = 10, sticky= W+E+N+S, pady = 5,padx = 5) if column: row_num += 5 column = not column figure_frame.update_idletasks() frame_canvas.config(width='16c', height='10c') # Set the canvas scrolling region main_canvas.config(scrollregion=figure_frame.bbox("all"))
class MainApp(Tk): def __init__(self): Tk.__init__(self) self.notebook = Notebook(self) self.wm_title("Sensitivity Analysis Tool") self.notebook.grid() self.construct_home_tab() self.simulations = [] self.current_simulation = None self.current_tab = None self.abort = Value('b', False) self.abort_univar_overall = Value('b', False) self.simulation_vars = {} self.attributes("-topmost", True) self.tot_sim_num = 0 self.sims_completed = Value('i',0) self.start_time = None self.univar_plot_counter = 1 self.finished_figures = [] self.univar_row_num=0 self.last_results_plotted = None self.last_update = None def construct_home_tab(self): self.home_tab = Frame(self.notebook) self.notebook.add(self.home_tab, text = 'Home') Button(self.home_tab, text='Upload Excel Data', command=self.open_excel_file).grid(row=0,column=1, sticky = E, pady = 5,padx = 5) self.input_csv_entry = Entry(self.home_tab) self.input_csv_entry.grid(row=0, column=2) Button(self.home_tab, text="Upload Aspen Model", command=self.open_aspen_file).grid(row=1, column = 1,sticky = E, pady = 5,padx = 5) self.aspen_file_entry = Entry(self.home_tab) self.aspen_file_entry.grid(row=1, column=2,pady = 5,padx = 5) Button(self.home_tab, text="Upload Excel Model", command=self.open_solver_file).grid(row=2,column = 1,sticky = E, pady = 5,padx = 5) self.excel_solver_entry = Entry(self.home_tab) self.excel_solver_entry.grid(row=2, column=2,pady = 5,padx = 5) Button(self.home_tab, text="Load Data", command=self.make_new_tab).grid(row=5,column = 3,sticky = E, pady = 5,padx = 5) self.analysis_type = StringVar(self.home_tab) self.analysis_type.set("Choose Analysis Type") OptionMenu(self.home_tab, self.analysis_type,"Single Point Analysis","Univariate Sensitivity", "Multivariate Sensitivity").grid(row = 5,sticky = E,column = 2,padx =5, pady = 5) Label(self.home_tab, text='CPU Core Count :').grid(row=3, column=1, sticky=E) self.num_processes_entry = Entry(self.home_tab) self.num_processes_entry.grid(row=3, column=2, pady=5, padx=5) def make_new_tab(self): if self.current_tab: self.notebook.forget(self.current_tab) self.current_tab = None if self.analysis_type.get() == 'Choose Analysis Type': print("ERROR: Select an Analysis Type") elif self.analysis_type.get() == 'Univariate Sensitivity': self.current_tab = Frame(self.notebook) self.notebook.add(self.current_tab,text = "Univariate Analysis") ##############Tab 2 LABELS################## Label(self.current_tab, text="Save As :").grid(row=4, column= 1, sticky = E,pady = 5,padx = 5) self.save_as_entry= Entry(self.current_tab) self.save_as_entry.grid(row=4, column=2,pady = 5,padx = 5) Label(self.current_tab,text = ".csv").grid(row = 4, column = 3, sticky = W) Label(self.current_tab, text ='').grid(row= 13, column =1) Button(self.current_tab, text='Run Univariate Sensitivity Analysis', command=self.initialize_univar_analysis).grid(row=14, column=3, columnspan=2, pady=4) Button(self.current_tab, text='Display Variable Distributions', command=self.plot_init_dist).grid(row=14, column=1, columnspan=2, sticky = W, pady=4) Button(self.current_tab, text='Fill # Trials', command=self.fill_num_trials).grid(row=7, columnspan = 2, sticky =E, column=1, pady=4) self.fill_num_sims = Entry(self.current_tab) self.fill_num_sims.grid(row=7,column = 3,sticky =W, pady =2, padx = 2) self.fill_num_sims.config(width = 10) self.options_box = Labelframe(self.current_tab, text='Run Options:') self.options_box.grid(row = 15,column = 3, pady = 10,padx = 10) Button(self.options_box, text = "Next Variable", command=self.abort_sim).grid( row=6,columnspan = 1, column = 2, sticky=W) Button(self.options_box, text = "Abort", command=self.abort_univar_overall_fun).grid( row= 6,columnspan = 1, column = 3, sticky=W) elif self.analysis_type.get() == 'Single Point Analysis': self.current_tab = Frame(self.notebook) self.notebook.add(self.current_tab, text = 'Single Point') Label(self.current_tab, text="Save As :").grid(row=0, column= 0, sticky = E,pady = 5,padx = 5) self.save_as_entry = Entry(self.current_tab) self.save_as_entry.grid(row=0, column=1,pady = 5,padx = 5) Button(self.current_tab, text='Calculate MFSP', command=self.initialize_single_point).grid(row=7, column=1, columnspan=2, pady=4) elif self.analysis_type.get() == 'Multivariate Sensitivity': self.current_tab = Frame(self.notebook) self.notebook.add(self.current_tab,text = "Multivariate Analysis") Label(self.current_tab, text="Number of Simulations :").grid(row=3, column= 1, sticky = E,pady = 5,padx = 5) self.num_sim_entry = Entry(self.current_tab) self.num_sim_entry.grid(row=3, column=2,pady = 5,padx = 5) Label(self.current_tab, text="Save As :").grid(row=4, column= 1, sticky = E,pady = 5,padx = 5) self.save_as_entry = Entry(self.current_tab) self.save_as_entry.grid(row=4, column=2,pady = 5,padx = 5) Label(self.current_tab,text = ".csv").grid(row = 4, column = 3, sticky = W) Button(self.current_tab, text='Run Multivariate Analysis', command=self.initialize_multivar_analysis).grid(row=6, column=3, columnspan=2, sticky=W, pady=4) Button(self.current_tab, text='Display Variable Distributions', command=self.plot_init_dist).grid(row=6, column=1, columnspan=2, sticky=W, pady=4) self.load_variables_into_GUI() self.notebook.select(self.current_tab) def load_variables_into_GUI(self): sens_vars = str(self.input_csv_entry.get()) single_pt_vars = [] univariate_vars = [] multivariate_vars = [] type_of_analysis = self.analysis_type.get() with open(sens_vars) as f: reader = DictReader(f)# Skip the header row for row in reader: if row['Toggle'].lower().strip() == 'true': if type_of_analysis =='Single Point Analysis': single_pt_vars.append((row["Variable Name"], float(row["Range of Values"].split(',')[0].strip()))) elif type_of_analysis == 'Multivariate Analysis': multivariate_vars.append(row["Variable Name"]) else: univariate_vars.append(( row["Variable Name"], row["Format of Range"].strip().lower( ), row['Range of Values'].split(','))) #now populate the gui with the appropriate tab and variables stored above if type_of_analysis == 'Single Point Analysis': self.current_tab.config(width = '5c', height = '5c') self.sp_value_entries = {} # Create a frame for the canvas with non-zero row&column weights frame_canvas = Frame(self.current_tab) frame_canvas.grid(row=2, column=1, pady=(5, 0)) frame_canvas.grid_rowconfigure(0, weight=1) frame_canvas.grid_columnconfigure(0, weight=1) frame_canvas.config(height = '5c') # Add a canvas in the canvas frame canvas = Canvas(frame_canvas) canvas.grid(row=0, column=0, sticky="news") canvas.config(height = '5c') # Link a scrollbar to the canvas vsb = Scrollbar(frame_canvas, orient="vertical", command=canvas.yview) vsb.grid(row=0, column=1,sticky = 'ns') canvas.configure(yscrollcommand=vsb.set) # Create a frame to contain the variables frame_vars = Frame(canvas) canvas.create_window((0, 0), window=frame_vars, anchor='nw') frame_vars.config(height = '5c') self.sp_row_num = 0 for name,value in single_pt_vars: self.sp_row_num += 1 key = str(self.sp_row_num) Label(frame_vars, text= name).grid(row=self.sp_row_num, column= 1, sticky = E,pady = 5,padx = 5) key=Entry(frame_vars) key.grid(row=self.sp_row_num, column=2,pady = 5,padx = 5) key.delete(first=0,last=END) key.insert(0,str(value)) self.sp_value_entries[name]= key # Determine the size of the Canvas frame_vars.update_idletasks() frame_canvas.config(width='5c', height='10c') # Set the canvas scrolling region canvas.config(scrollregion=canvas.bbox("all")) if type_of_analysis == 'Univariate Sensitivity': self.univar_ntrials_entries = {} Label(self.current_tab, text= 'Variable Name').grid(row=8, column= 1,pady = 5,padx = 5, sticky= E) Label(self.current_tab, text= 'Sampling Type').grid(row=8, column= 2,pady = 5,padx = 5, sticky=E) Label(self.current_tab, text= '# of Trials').grid(row=8, column= 3,pady = 5,padx = 5) # Create a frame for the canvas with non-zero row&column weights frame_canvas1 = Frame(self.current_tab) frame_canvas1.grid(row=9, column=1, columnspan =3, pady=(5, 0)) frame_canvas1.grid_rowconfigure(0, weight=1) frame_canvas1.grid_columnconfigure(0, weight=1) frame_canvas1.config(height = '3c') # Add a canvas in the canvas frame canvas1 = Canvas(frame_canvas1) canvas1.grid(row=0, column=0, sticky="news") canvas1.config(height = '3c') # Link a scrollbar to the canvas vsb = Scrollbar(frame_canvas1, orient="vertical", command=canvas1.yview) vsb.grid(row=0, column=1,sticky = 'ns') canvas1.configure(yscrollcommand=vsb.set) # Create a frame to contain the variables frame_vars1 = Frame(canvas1) frame_vars1.config(height = '3c') canvas1.create_window((0, 0), window=frame_vars1, anchor='nw') for name, format_of_data, vals in univariate_vars: Label(frame_vars1, text= name).grid(row=self.univar_row_num, column= 1,pady = 5,padx = 5) Label(frame_vars1, text= format_of_data).grid(row=self.univar_row_num, column= 2,pady = 5,padx = 5) if not(format_of_data == 'linspace' or format_of_data == 'list'): key2=Entry(frame_vars1) key2.grid(row=self.univar_row_num, column=3,pady = 5,padx = 5) #key2.insert(0,univariate_sims) self.univar_ntrials_entries[name]= key2 else: if format_of_data == 'linspace': Label(frame_vars1,text= str(vals[2])).grid(row=self.univar_row_num, column= 3,pady = 5,padx = 5) else: Label(frame_vars1,text= str(len(vals))).grid(row=self.univar_row_num, column= 3,pady = 5,padx = 5) self.univar_row_num += 1 # Update vars frames idle tasks to let tkinter calculate variable sizes frame_vars1.update_idletasks() # Determine the size of the Canvas frame_canvas1.config(width='5c', height='5c') # Set the canvas scrolling region canvas1.config(scrollregion=canvas1.bbox("all")) def get_distributions(self): if self.analysis_type.get() == 'Univariate Sensitivity': if self.univar_ntrials_entries: max_num_sim = 0 for slot in self.univar_ntrials_entries.values(): try: cur_num_sim = int(slot.get()) except: cur_num_sim = 1 max_num_sim = max(max_num_sim, cur_num_sim) else: max_num_sim = 1 self.simulation_vars, self.simulation_dist = self.construct_distributions(ntrials=max_num_sim) for (aspen_variable, aspen_call, fortran_index), dist in self.simulation_vars.items(): if aspen_variable in self.univar_ntrials_entries: try: num_trials_per_var = int(self.univar_ntrials_entries[aspen_variable].get()) except: num_trials_per_var = 1 self.simulation_vars[(aspen_variable, aspen_call, fortran_index)] = dist[:num_trials_per_var] self.simulation_dist[aspen_variable] = dist[:num_trials_per_var] else: try: ntrials = int(self.num_sim_entry.get()) except: ntrials=1 self.simulation_vars, self.simulation_dist = self.construct_distributions(ntrials=ntrials) def construct_distributions(self, ntrials=1): ''' Given the excel input from the user in the GUI, produce a list_of_variables the user wants to change as well as their distributions that should be randomly sampled from. ''' gui_excel_input = str(self.input_csv_entry.get()) with open(gui_excel_input) as f: reader = DictReader(f)# Skip the header row simulation_vars = {} simulation_dist = {} for row in reader: if row['Toggle'].lower().strip() == 'true': dist_type = row['Format of Range'].lower() aspen_variable = row['Variable Name'] aspen_call = row['Variable Aspen Call'] bounds = row['Bounds'].split(',') lb = float(bounds[0].strip()) ub = float(bounds[1].strip()) if 'normal' in dist_type or 'gaussian' in dist_type: dist_variables = row['Range of Values'].split(',') distribution = self.sample_gauss(float(dist_variables[0].strip()), float(dist_variables[1].strip()), lb, ub, ntrials) if 'linspace' in dist_type: linspace_vars = row['Range of Values'].split(',') distribution = linspace(float(linspace_vars[0].strip()), float(linspace_vars[1].strip()), float(linspace_vars[2].strip())) if 'poisson' in dist_type: lambda_p = float(row['Range of Values'].strip()) distribution = self.sample_poisson(lambda_p, lb, ub, ntrials) if 'pareto' in dist_type: pareto_vals = row['Range of Values'].split(',') shape = float(pareto_vals[0].strip()) scale = float(pareto_vals[1].strip()) distribution = self.sample_pareto(shape, scale, lb, ub, ntrials) if 'list' in dist_type: lst = row['Range of Values'].split(',') distribution = [] for l in lst: distribution.append(float(l.strip())) if 'uniform' in dist_type: lb_ub = row['Range of Values'].split(',') lb_uniform, ub_uniform = float(lb_ub[0].strip()), float(lb_ub[1].strip()) distribution = self.sample_uniform(lb_uniform, ub_uniform, lb, ub, ntrials) simulation_dist[aspen_variable] = distribution[:] fortran_index = (0,0) if row['Fortran Call'].strip() != "": fortran_call = row['Fortran Call'] value_to_change = row['Fortran Value to Change'].strip() len_val = len(value_to_change) for i in range(len(fortran_call)): if fortran_call[i:i+len_val] == value_to_change: fortran_index = (i, i+len_val) #NOT INCLUSIVE for i, v in enumerate(distribution): distribution[i] = self.make_fortran(fortran_call, fortran_index, v) simulation_vars[(aspen_variable, aspen_call, fortran_index)] = distribution return simulation_vars, simulation_dist def sample_gauss(self,mean, std, lb, ub, ntrials): d = [] for i in range(ntrials): rand_sample = random.normal(mean,std) while(rand_sample < lb or rand_sample > ub): rand_sample = random.normal(mean,std) d.append(rand_sample) return d def sample_uniform(self,lb_uniform, ub_uniform, lb, ub, ntrials): d = [] for i in range(ntrials): rand_sample = random.uniform(lb_uniform, ub_uniform) while(rand_sample < lb or rand_sample > ub): rand_sample = random.uniform(lb_uniform, ub_uniform) d.append(rand_sample) return d def sample_poisson(self,lambda_p, lb, ub, ntrials): d = [] for i in range(ntrials): rand_sample = random.poisson(10000*lambda_p)/10000 while(rand_sample < lb or rand_sample > ub): rand_sample = random.poisson(10000*lambda_p)/10000 d.append(rand_sample) return d def sample_pareto(self, shape, scale, lb, ub, ntrials): d = [] for i in range(ntrials): rand_sample = (random.pareto(shape) + 1) * scale while(rand_sample < lb or rand_sample > ub): rand_sample = (random.pareto(shape) + 1) * scale d.append(rand_sample) return d def make_fortran(self, fortran_call, fortran_index, val): return fortran_call[:fortran_index[0]] + str(val) + fortran_call[fortran_index[1]:] def disp_sp_mfsp(self): try: if self.current_simulation.results: mfsp = self.current_simulation.results[0].at[0, 'MFSP'] if mfsp: Label(self.current_tab, text= 'MFSP = ${:.2f}'.format(mfsp)).grid( row=self.sp_row_num+1, column = 1) else: Label(self.current_tab, text= 'Aspen Failed to Converge').grid( row=self.sp_row_num+1, column = 1) else: self.after(5000, self.disp_sp_mfsp) except: self.after(5000, self.disp_sp_mfsp) def single_point_analysis(self): self.store_user_inputs() self.get_distributions() # update simulation variable values based on user input in GUI for (aspen_variable, aspen_call, fortran_index), values in self.simulation_vars.items(): self.simulation_vars[(aspen_variable, aspen_call, fortran_index)] = [float( self.sp_value_entries[aspen_variable].get())] self.create_simulation_object(self.simulation_vars, self.vars_to_change, self.output_file, self.num_trial) self.run_simulations() def run_multivar_sens(self): Button(self.current_tab, text = "Abort", command=self.abort_sim).grid( row=7,columnspan = 1, column = 3, sticky=W) self.store_user_inputs() if len(self.simulation_vars) == 0: self.get_distributions() self.create_simulation_object(self.simulation_vars, self.vars_to_change, self.output_file, self.num_trial) self.run_simulations() def run_univ_sens(self): self.store_user_inputs() if len(self.simulation_vars) == 0: self.get_distributions() for (aspen_variable, aspen_call, fortran_index), values in self.simulation_vars.items(): self.create_simulation_object({(aspen_variable, aspen_call, fortran_index): values}, [aspen_variable], self.output_file+'_'+aspen_variable, len(values)) self.run_simulations() def store_user_inputs(self): self.aspen_file = str(self.aspen_file_entry.get()) try: self.num_processes = int(self.num_processes_entry.get()) except: self.num_processes = 1 self.excel_solver_file= str(self.excel_solver_entry.get()) try: self.num_trial = int(self.num_sim_entry.get()) except: self.num_trial = 1 self.output_file = str(self.save_as_entry.get()) self.input_csv = str(self.input_csv_entry.get()) self.vars_to_change = [] with open(self.input_csv) as f: reader = DictReader(f)# Skip the header row for row in reader: if row['Toggle'].lower().strip() == 'true': self.vars_to_change.append(row["Variable Name"]) def run_simulations(self): self.start_time = time() for sim in self.simulations: self.current_simulation = sim self.current_simulation.init_sims() if self.abort_univar_overall.value: self.abort.value = True self.univar_plot_counter += 1 def parse_output_vars(self): excels_to_ignore = {} for p in process_iter(): if 'excel' in p.name().lower(): excels_to_ignore[p.pid] = 1 excel, book = open_excelCOMS(self.excel_solver_file) self.output_vars = [] row_counter = 3 while True: var_name = book.Sheets('Output').Evaluate("B" + str(row_counter)).Value if var_name: units = book.Sheets('Output').Evaluate("D" + str(row_counter)).Value column_name = var_name + ' (' + units + ')' if units else var_name self.output_vars.append(column_name) else: break row_counter += 1 self.output_value_cells = "C3:C" + str(row_counter - 1) self.output_vars += ['Aspen Errors'] for p in process_iter(): if 'excel' in p.name().lower() and p.pid not in excels_to_ignore: p.terminate() def create_simulation_object(self, simulation_vars, vars_to_change, output_file, num_trial): self.parse_output_vars() self.output_columns = vars_to_change + self.output_vars new_sim = Simulation(self.sims_completed, num_trial, simulation_vars, output_file, path.dirname(str(self.input_csv_entry.get())), self.aspen_file, self.excel_solver_file, self.abort, vars_to_change, self.output_value_cells, self.output_columns, save_freq=5, num_processes=self.num_processes) self.simulations.append(new_sim) self.tot_sim_num += num_trial def initialize_single_point(self): self.worker_thread = Thread( target=lambda: self.single_point_analysis()) self.worker_thread.start() self.after(5000, self.disp_sp_mfsp) def initialize_univar_analysis(self): self.worker_thread = Thread( target=lambda: self.run_univ_sens()) self.worker_thread.start() self.status_label = None self.time_rem_label = None self.after(5000, self.univar_gui_update) def initialize_multivar_analysis(self): self.worker_thread = Thread( target=lambda: self.run_multivar_sens()) self.worker_thread.start() self.status_label = None self.time_rem_label = None self.multivar_gui_update() def disp_status_update(self): if self.current_simulation and not self.abort.value: if len(self.current_simulation.results) == self.current_simulation.tot_sim: tmp = Label(self.current_tab, text= 'Status: Simulation Complete ') else: tmp = Label(self.current_tab, text= 'Status: Simulation Running | {} Results Collected'.format( len(self.current_simulation.results))) if self.univar_row_num != 0: row = 15 else: row = 8 tmp.grid(row=row, column = 1, sticky=W, columnspan=2) if self.status_label: self.status_label.destroy() self.status_label = tmp def disp_time_remaining(self): if self.start_time and self.sims_completed.value != self.last_update: self.last_update = self.sims_completed.value elapsed_time = time() - self.start_time if self.sims_completed.value > 0: remaining_time = ((elapsed_time / self.sims_completed.value) * (self.tot_sim_num - self.sims_completed.value))//60 hours, minutes = divmod(remaining_time, 60) tmp = Label(self.current_tab, text='Time Remaining: {} Hours, {} Minutes '.format(int(hours), int(minutes))) else: tmp = Label(self.current_tab, text='Time Remaining: N/A') if self.univar_row_num != 0: row = 16 else: row = 9 tmp.grid(row=row, column=1, columnspan=2,sticky=W) if self.time_rem_label: self.time_rem_label.destroy() self.time_rem_label = tmp def plot_on_GUI(self): if not self.current_simulation: return if len(self.current_simulation.results) == self.last_results_plotted: return self.last_results_plotted = len(self.current_simulation.results) if self.current_simulation.results: results = concat(self.current_simulation.results).sort_index() results = results[[d is not None for d in results['MFSP']]] # filter to make sure you aren't plotting None results else: results = DataFrame(columns=self.output_columns) fig_list =[] num_bins = 15 mfsp_fig = Figure(figsize = (3,3), facecolor=[240/255,240/255,237/255], tight_layout=True) b = mfsp_fig.add_subplot(111) b.hist(results['MFSP'], num_bins, facecolor='blue', edgecolor='black', alpha=1.0) b.set_title('MFSP') fig_list.append(mfsp_fig) for var, values in self.simulation_dist.items(): fig = Figure(figsize = (3,3), facecolor=[240/255,240/255,237/255], tight_layout=True) a = fig.add_subplot(111) _, bins, _ = a.hist(self.simulation_dist[var], num_bins, facecolor='white', edgecolor='black',alpha=1.0) a.hist(results[var], bins=bins, facecolor='blue',edgecolor='black', alpha=1.0) a.set_title(var) fig_list.append(fig) if self.univar_row_num != 0: row_num = 17 else: row_num = 10 frame_canvas = Frame(self.current_tab) frame_canvas.grid(row=row_num, column=1, columnspan = 3,pady=(5, 0)) frame_canvas.grid_rowconfigure(0, weight=1) frame_canvas.grid_columnconfigure(0, weight=1) frame_canvas.config(height = '10c', width='16c') main_canvas = Canvas(frame_canvas) main_canvas.grid(row=0, column=0, sticky="news") main_canvas.config(height = '10c', width='16c') vsb = Scrollbar(frame_canvas, orient="vertical", command=main_canvas.yview) vsb.grid(row=0, column=1,sticky = 'ns') main_canvas.configure(yscrollcommand=vsb.set) figure_frame = Frame(main_canvas) main_canvas.create_window((0, 0), window=figure_frame, anchor='nw') figure_frame.config(height = '10c', width='16c') row_num = 0 column = False for figs in fig_list: figure_canvas = FigureCanvasTkAgg(figs, master=figure_frame) if column: col = 4 else: col = 1 #figure_canvas.draw() figure_canvas.get_tk_widget().grid( row=row_num, column=col,columnspan=2, rowspan = 5, pady = 5,padx = 8, sticky=E) #figure_canvas._tkcanvas.grid(row=row_num, column = 0,columnspan = 10, rowspan = 10, sticky= W+E+N+S, pady = 5,padx = 5) if column: row_num += 5 column = not column figure_frame.update_idletasks() frame_canvas.config(width='16c', height='10c') # Set the canvas scrolling region main_canvas.config(scrollregion=figure_frame.bbox("all")) def plot_univ_on_GUI(self): if not self.current_simulation: return if len(self.current_simulation.results) == self.last_results_plotted: return self.last_results_plotted = len(self.current_simulation.results) current_var = self.current_simulation.vars_to_change[0] if self.current_simulation.results: results = concat(self.current_simulation.results).sort_index() results = results[[d is not None for d in results['MFSP']]] # filter to make sure you aren't plotting None results else: results = DataFrame(columns=self.output_columns) fig_list =[] var_fig = Figure(figsize = (3,3), facecolor=[240/255,240/255,237/255], tight_layout=True) a = var_fig.add_subplot(111) num_bins = 15 _, bins, _ = a.hist(self.simulation_dist[current_var], num_bins, facecolor='white',edgecolor='black', alpha=1.0) a.hist(results[current_var], bins=bins, facecolor='blue',edgecolor='black', alpha=1.0) a.set_title(current_var) fig_list.append(var_fig) mfsp_fig = Figure(figsize = (3,3), facecolor=[240/255,240/255,237/255], tight_layout=True) b = mfsp_fig.add_subplot(111) b.hist(results['MFSP'], num_bins, facecolor='blue', edgecolor='black', alpha=1.0) b.set_title('MFSP - ' + current_var) fig_list.append(mfsp_fig) figs_to_plot = self.finished_figures[:] + fig_list if len(self.current_simulation.results) == self.current_simulation.tot_sim: self.finished_figures += fig_list if self.univar_row_num != 0: row_num = 17 else: row_num = 10 frame_canvas = Frame(self.current_tab) frame_canvas.grid(row=row_num, column=1, columnspan = 3,pady=(5, 0)) frame_canvas.grid_rowconfigure(0, weight=1) frame_canvas.grid_columnconfigure(0, weight=1) frame_canvas.config(height = '10c', width='16c') main_canvas = Canvas(frame_canvas) main_canvas.grid(row=0, column=0, sticky="news") main_canvas.config(height = '10c', width='16c') vsb = Scrollbar(frame_canvas, orient="vertical", command=main_canvas.yview) vsb.grid(row=0, column=1,sticky = 'ns') main_canvas.configure(yscrollcommand=vsb.set) figure_frame = Frame(main_canvas) main_canvas.create_window((0, 0), window=figure_frame, anchor='nw') figure_frame.config(height = '10c', width='16c') row_num = 0 column = False for figs in figs_to_plot: figure_canvas = FigureCanvasTkAgg(figs, master=figure_frame) if column: col = 4 else: col = 1 #figure_canvas.draw() figure_canvas.get_tk_widget().grid( row=row_num, column=col,columnspan=2, rowspan = 5, pady = 5,padx = 8, sticky=E) #figure_canvas._tkcanvas.grid(row=row_num, column = 0,columnspan = 10, rowspan = 10, sticky= W+E+N+S, pady = 5,padx = 5) if column: row_num += 5 column = not column figure_frame.update_idletasks() frame_canvas.config(width='16c', height='10c') # Set the canvas scrolling region main_canvas.config(scrollregion=figure_frame.bbox("all")) def plot_init_dist(self): ''' This function will plot the distribution of variable calls prior to running the simulation. This will enable users to see whether the distributions are as they expected. ''' self.get_distributions() fig_list =[] for var, values in self.simulation_dist.items(): fig = Figure(figsize = (3,3), facecolor=[240/255,240/255,237/255], tight_layout=True) a = fig.add_subplot(111) num_bins = 15 a.hist(values, num_bins, facecolor='blue', edgecolor='black', alpha=1.0) a.set_title(var) fig_list.append(fig) if self.univar_row_num != 0: row_num = 17 else: row_num = 10 frame_canvas = Frame(self.current_tab) frame_canvas.grid(row=row_num, column=1, columnspan = 3,pady=(5, 0)) frame_canvas.grid_rowconfigure(0, weight=1) frame_canvas.grid_columnconfigure(0, weight=1) frame_canvas.config(height = '10c', width='16c') main_canvas = Canvas(frame_canvas) main_canvas.grid(row=0, column=0, sticky="news") main_canvas.config(height = '10c', width='16c') vsb = Scrollbar(frame_canvas, orient="vertical", command=main_canvas.yview) vsb.grid(row=0, column=2,sticky = 'ns') main_canvas.configure(yscrollcommand=vsb.set) figure_frame = Frame(main_canvas) main_canvas.create_window((0, 0), window=figure_frame, anchor='nw') figure_frame.config(height = '10c', width='16c') row_num = 0 column = False for figs in fig_list: figure_canvas = FigureCanvasTkAgg(figs, master=figure_frame) if column: col = 4 else: col = 1 figure_canvas.get_tk_widget().grid( row=row_num, column=col,columnspan=2, rowspan = 5, pady = 5,padx = 8, sticky=E) if column: row_num += 5 column = not column figure_frame.update_idletasks() frame_canvas.config(width='16c', height='10c') main_canvas.config(scrollregion=figure_frame.bbox("all")) def univar_gui_update(self): self.disp_status_update() self.disp_time_remaining() self.plot_univ_on_GUI() ####################### ADD AUTO UPDATE GRAPHS ############# self.after(10000, self.univar_gui_update) def multivar_gui_update(self): self.disp_status_update() self.disp_time_remaining() self.plot_on_GUI() ####################### ADD AUTO UPDATE GRAPHS ############# self.after(10000, self.multivar_gui_update) def fill_num_trials(self): ntrials = self.fill_num_sims.get() for name, slot in self.univar_ntrials_entries.items(): slot.delete(0, END) slot.insert(0, ntrials) def open_excel_file(self): filename = askopenfilename(title = "Select file", filetypes = (("csv files","*.csv"),("all files","*.*"))) self.input_csv_entry.delete(0, END) self.input_csv_entry.insert(0, filename) def open_aspen_file(self): filename = askopenfilename(title = "Select file", filetypes = (("Aspen Models",["*.bkp", "*.apw"]),("all files","*.*"))) self.aspen_file_entry.delete(0, END) self.aspen_file_entry.insert(0, filename) def open_solver_file(self): filename = askopenfilename(title = "Select file", filetypes = (("Excel Files","*.xlsm"),("all files","*.*"))) self.excel_solver_entry.delete(0, END) self.excel_solver_entry.insert(0, filename) def abort_sim(self): self.abort.value = True self.cleanup_thread = Thread(target=self.cleanup_processes_and_COMS) self.cleanup_thread.start() def abort_univar_overall_fun(self): self.abort_univar_overall.value = True self.abort_sim() def cleanup_processes_and_COMS(self): try: self.current_simulation.close_all_COMS() self.current_simulation.terminate_processes() save_data(self.current_simulation.output_file, self.current_simulation.results, self.current_simulation.directory) except: self.after(1000, self.cleanup_processes_and_COMS)
def load_variables_into_GUI(self): sens_vars = str(self.input_csv_entry.get()) single_pt_vars = [] univariate_vars = [] multivariate_vars = [] type_of_analysis = self.analysis_type.get() with open(sens_vars) as f: reader = DictReader(f)# Skip the header row for row in reader: if row['Toggle'].lower().strip() == 'true': if type_of_analysis =='Single Point Analysis': single_pt_vars.append((row["Variable Name"], float(row["Range of Values"].split(',')[0].strip()))) elif type_of_analysis == 'Multivariate Analysis': multivariate_vars.append(row["Variable Name"]) else: univariate_vars.append(( row["Variable Name"], row["Format of Range"].strip().lower( ), row['Range of Values'].split(','))) #now populate the gui with the appropriate tab and variables stored above if type_of_analysis == 'Single Point Analysis': self.current_tab.config(width = '5c', height = '5c') self.sp_value_entries = {} # Create a frame for the canvas with non-zero row&column weights frame_canvas = Frame(self.current_tab) frame_canvas.grid(row=2, column=1, pady=(5, 0)) frame_canvas.grid_rowconfigure(0, weight=1) frame_canvas.grid_columnconfigure(0, weight=1) frame_canvas.config(height = '5c') # Add a canvas in the canvas frame canvas = Canvas(frame_canvas) canvas.grid(row=0, column=0, sticky="news") canvas.config(height = '5c') # Link a scrollbar to the canvas vsb = Scrollbar(frame_canvas, orient="vertical", command=canvas.yview) vsb.grid(row=0, column=1,sticky = 'ns') canvas.configure(yscrollcommand=vsb.set) # Create a frame to contain the variables frame_vars = Frame(canvas) canvas.create_window((0, 0), window=frame_vars, anchor='nw') frame_vars.config(height = '5c') self.sp_row_num = 0 for name,value in single_pt_vars: self.sp_row_num += 1 key = str(self.sp_row_num) Label(frame_vars, text= name).grid(row=self.sp_row_num, column= 1, sticky = E,pady = 5,padx = 5) key=Entry(frame_vars) key.grid(row=self.sp_row_num, column=2,pady = 5,padx = 5) key.delete(first=0,last=END) key.insert(0,str(value)) self.sp_value_entries[name]= key # Determine the size of the Canvas frame_vars.update_idletasks() frame_canvas.config(width='5c', height='10c') # Set the canvas scrolling region canvas.config(scrollregion=canvas.bbox("all")) if type_of_analysis == 'Univariate Sensitivity': self.univar_ntrials_entries = {} Label(self.current_tab, text= 'Variable Name').grid(row=8, column= 1,pady = 5,padx = 5, sticky= E) Label(self.current_tab, text= 'Sampling Type').grid(row=8, column= 2,pady = 5,padx = 5, sticky=E) Label(self.current_tab, text= '# of Trials').grid(row=8, column= 3,pady = 5,padx = 5) # Create a frame for the canvas with non-zero row&column weights frame_canvas1 = Frame(self.current_tab) frame_canvas1.grid(row=9, column=1, columnspan =3, pady=(5, 0)) frame_canvas1.grid_rowconfigure(0, weight=1) frame_canvas1.grid_columnconfigure(0, weight=1) frame_canvas1.config(height = '3c') # Add a canvas in the canvas frame canvas1 = Canvas(frame_canvas1) canvas1.grid(row=0, column=0, sticky="news") canvas1.config(height = '3c') # Link a scrollbar to the canvas vsb = Scrollbar(frame_canvas1, orient="vertical", command=canvas1.yview) vsb.grid(row=0, column=1,sticky = 'ns') canvas1.configure(yscrollcommand=vsb.set) # Create a frame to contain the variables frame_vars1 = Frame(canvas1) frame_vars1.config(height = '3c') canvas1.create_window((0, 0), window=frame_vars1, anchor='nw') for name, format_of_data, vals in univariate_vars: Label(frame_vars1, text= name).grid(row=self.univar_row_num, column= 1,pady = 5,padx = 5) Label(frame_vars1, text= format_of_data).grid(row=self.univar_row_num, column= 2,pady = 5,padx = 5) if not(format_of_data == 'linspace' or format_of_data == 'list'): key2=Entry(frame_vars1) key2.grid(row=self.univar_row_num, column=3,pady = 5,padx = 5) #key2.insert(0,univariate_sims) self.univar_ntrials_entries[name]= key2 else: if format_of_data == 'linspace': Label(frame_vars1,text= str(vals[2])).grid(row=self.univar_row_num, column= 3,pady = 5,padx = 5) else: Label(frame_vars1,text= str(len(vals))).grid(row=self.univar_row_num, column= 3,pady = 5,padx = 5) self.univar_row_num += 1 # Update vars frames idle tasks to let tkinter calculate variable sizes frame_vars1.update_idletasks() # Determine the size of the Canvas frame_canvas1.config(width='5c', height='5c') # Set the canvas scrolling region canvas1.config(scrollregion=canvas1.bbox("all"))