Beispiel #1
0
def CORE(S,M,f,port="z11",RS=0,RL=oo):

    Bode(fraction(f)[0], fraction(f)[1],port,fraction(f)[0],fraction(f)[1])

    if S==0:
        caer1(f,port=port,RS=RS,RL=RL)
    elif S==M: 
        caer2(f,port=port,RS=RS,RL=RL) 
    else: 
        bias={"type":"w","label":"unkw","dirrection":"right","parallel":False}
        print("solution one for",f)
        Append("solution one for "+str(f))    
        s1=caer1(f,repeat=abs(S-M))
        s2=caer2(s1[2],gener=s1[1],repeat=S)
        s1[0].append(bias)
        for i in s2[0]:
            s1[0].append(i)
        #draw(s1[0],port,RS,RL)
        Append(40*"- ")
        ans1=s1[0]
        print("\n","solution two for",f)
        Append("solution two for "+str(f))  
        s2=caer2(f,repeat=S)
        s1=caer1(s2[2],gener=s2[1],repeat=abs(S-M))
        s2[0].append(bias)
        for i in s1[0]:
            s2[0].append(i)
        Append("",finish=True)
        #draw(s2[0],port=port,rs=RS,rl=RL)
        window =ThemedTk(theme="adapta")
        window.title('Please choose to plot')
        window.rowconfigure([0,1], weight=1)
        window.columnconfigure([0], weight=1)
        label = ttk.Label(window,text='For any solution you can draw a schematic',anchor=tk.CENTER)
        label.grid(row=0,column=0,sticky=tk.N+tk.S+tk.E+tk.W)
        card_frame = ttk.Frame(window)
        card_frame.grid(row=1, column=0, sticky=tk.N+tk.S+tk.E+tk.W)
        card_frame.rowconfigure([0], weight=1)
        card_frame.columnconfigure([0,1], weight=1)
        solution1 = ttk.Button(card_frame,text="plot solution one",width=15,
                            command=lambda: draw(ans1,port,RS,RL))
        solution1.grid(row=0, column=0, sticky=tk.N+tk.S+tk.E+tk.W)
        solution2 = ttk.Button(card_frame,text="plot solution two",width=15,
                            command=lambda: draw(s2[0],port,RS,RL))
        solution2.grid(row=0, column=1, sticky=tk.N+tk.S+tk.E+tk.W)
        window.resizable(width=False, height=False)
        window.deiconify()
        window.mainloop()
class GUI:
    """This handles the GUI for ESMB"""
    def __init__(self):
        logging.debug("\tBuilding GUI...")

        # Build the application window
        self.gui = ThemedTk(theme="plastik")
        self.gui.title("ESMissionBuilder")
        self.gui.configure(bg="orange")

        # enable window resizing
        self.gui.columnconfigure(2, weight=1)
        self.gui.rowconfigure(0, weight=1)

        # set disabled styles
        self.disabledEntryStyle = ttk.Style()
        self.disabledEntryStyle.configure('D.TEntry', background='#D3D3D3')
        self.disabledComboboxStyle = ttk.Style()
        self.disabledComboboxStyle.configure('D.TCombobox',
                                             background='#D3D3D3')

        # Declare the frames
        self.option_pane = editor.OptionPane(self.gui)
        self.option_pane.grid(row=0, column=0, sticky="ns")

        self.center_pane = editor.MissionEditorPane(self.gui)
        self.center_pane.grid(row=0, column=1, sticky="ns")

        self.item_text_pane = editor.ItemTextPane(self.gui)
        self.item_text_pane.grid(row=0, column=2, sticky="nsew")

        config.gui = self
        self.gui.mainloop()

    #end init

    def update_option_pane(self):
        self.option_pane.update_pane()

    #end update_option_pane

    def update_center_pane(self):
        self.center_pane.update_pane()

    #end update_center_pane

    def update_item_text_pane(self):
        self.item_text_pane.update_pane()
class GUI(object):
    """This handles the GUI for ESMB"""
    def __init__(self, debug_mode):
        logging.debug("\tBuilding GUI...")
        self.debugging = debug_mode

        #TODO: Look into changing this to not need the dictionary
        self.missionList = []
        self.missionNameToObjectDict = {}
        self.missionNames = []

        if self.debugging:
            self.missionList = [Mission("Debugging", default=True)]
            self.missionNameToObjectDict = {
                self.missionList[0].missionName: self.missionList[0]
            }
            self.missionNames.append(self.missionList[0].missionName)
        #end if

        # Build the application window
        self.gui = ThemedTk(theme="plastik")
        self.gui.title("ESMissionBuilder")
        self.gui.configure(bg="orange")

        # enable window resizing
        self.gui.columnconfigure(0, weight=1)
        self.gui.rowconfigure(0, weight=1)

        self.disabledEntryStyle = ttk.Style()
        self.disabledEntryStyle.configure('D.TEntry', background='#D3D3D3')
        self.disabledComboboxStyle = ttk.Style()
        self.disabledComboboxStyle.configure('D.TCombobox',
                                             background='#D3D3D3')

        self.ofWidth = None
        self.cfWidth = None
        self.mfWidth = None

        # Declare the frames
        self.optionFrame = None
        self.centerFrame = None
        self.missionFrame = None

        # declare optionFrame components
        self.missionComboBox = None
        self.activeMission = None

        # declare centerFrame components
        self.displayNameComponent = None
        self.descriptionComponent = None
        self.blockedComponent = None
        self.deadlineComponent = None
        self.cargoComponent = None
        self.passengersComponent = None
        self.illegalComponent = None
        self.stealthComponent = None
        self.invisibleComponent = None
        self.priorityLevelComponent = None
        self.whereShownComponent = None
        self.repeatComponent = None
        self.clearanceComponent = None
        self.infiltratingComponent = None
        self.waypointComponent = None
        self.stopoverComponent = None
        self.sourceComponent = None
        self.destinationComponent = None

        # Triggers
        self.triggersFrame = None
        self.activeTrigger = None

        # declare missionFrame components
        self.missionTextBox = None

        # Build the different parts of the main window
        #self.buildMenu(self.gui)
        self.build_main_view(self.gui)

        self.activeMission = None
        if self.debugging:
            self.activeMission = self.missionList[0]
        # Run the program
        self.gui.mainloop()

    #end init

    # This may be used later, after shortcuts are introduced
    '''
    def buildMenu(self, window):
        #TODO: IMPLEMENT THIS
        # creating a menu instance
        menu = Menu()
        window.config(menu=menu)

        # create the file object
        file = Menu(menu)
        edit = Menu(menu)

        # adds a command to the menu option, names it, and set the command to run
        file.add_command(label="New", command=lambda: newFile(self))
        file.add_command(label="Open", command=lambda: open_file(self))
        file.add_command(label="Save", command=lambda: save_file(self))
        file.add_command(label="Exit", command=exit)

        # added "File" to our menu
        menu.add_cascade(label="File", menu=file)

        # adds a command to the menu option, names it, and set the command to run
        edit.add_command(label="Undo", command=lambda: undoAction(self))

        # added "Edit" to our menu
        menu.add_cascade(label="Edit", menu=edit)
    #end buildMenu
    '''

    def build_main_view(self, window):
        """
        Instantiate the three major frames, and call methods to build the respective GUI areas

        :param window: The ThemedTK object that the rest of the GUI is built off of
        """
        option_frame = ttk.Frame(window)
        center_frame = ScrollingCenterFrame(self, window)
        mission_frame = ttk.Frame(window)

        self.optionFrame = option_frame
        self.centerFrame = center_frame
        self.missionFrame = mission_frame

        # set up each of the frames
        self.build_option_frame()
        self.build_center_frame()
        self.build_mission_frame()

        logging.debug("\tGUI built")

    #end build_main_view

    ### BUILDING FRAMES ###

    def build_option_frame(self):
        """Add widgets to the optionFrame"""
        logging.debug("\tBuilding optionFrame...")
        self.optionFrame.grid(row=0, column=0, sticky="ns")

        of_title = ttk.Label(self.optionFrame, text="Mission")
        of_title.pack()

        # declare the combobox here, fill with missionNames
        self.missionComboBox = ttk.Combobox(self.optionFrame,
                                            state="readonly",
                                            values=self.missionNames)
        self.missionComboBox.bind("<<ComboboxSelected>>",
                                  self.mission_selected)
        self.missionComboBox.pack()

        if self.debugging:
            self.missionComboBox.current(0)

        # add function buttons
        new_mission_button = ttk.Button(self.optionFrame,
                                        text="New Mission",
                                        command=lambda: new_mission(self))
        new_mission_button.pack(fill='x')

        save_mission_file_button = ttk.Button(self.optionFrame,
                                              text="Save Mission File",
                                              command=lambda: save_file(self))
        save_mission_file_button.pack(fill='x')

        open_mission_file_button = ttk.Button(self.optionFrame,
                                              text="Open Mission File",
                                              command=lambda: open_file(self))
        open_mission_file_button.pack(fill='x')

        compile_mission_file_button = ttk.Button(
            self.optionFrame,
            text="Compile Mission",
            command=lambda: compile_mission(self))
        compile_mission_file_button.pack(fill='x')

        help_button = ttk.Button(self.optionFrame,
                                 text="Help",
                                 command=help_user)
        help_button.pack(fill='x')

        #TODO: Add functionality to change missionName and delete mission. Also, update button grouping to reflect

    #end build_option_frame

    def build_center_frame(self):
        """Add widgets to the centerFrame"""
        logging.debug("\tBuilding centerFrame...")

        self.centerFrame.grid(row=0, column=1, sticky="ns")

        cf = self.centerFrame.inner

        # Display name
        self.displayNameComponent = build_component_frame(
            cf, "Mission Display Name", 1, 0, ["<text>"])
        self.displayNameComponent.grid(row=0, column=0, sticky="ew")

        # Description
        self.descriptionComponent = build_component_frame(
            cf, "Description", 1, 0, ["<description>"])
        self.descriptionComponent.grid(row=1, column=0, sticky="ew")

        # isBlocked
        self.blockedComponent = build_component_frame(cf, "Blocked", 1, 0,
                                                      ["<message>"])
        self.blockedComponent.grid(row=2, column=0, sticky="ew")

        # Deadline
        self.deadlineComponent = build_component_frame(
            cf, "Deadline", 0, 2, ["[<days#>]", "[<multiplier#>]"])
        self.deadlineComponent.grid(row=3, column=0, sticky="ew")

        # Cargo
        self.cargoComponent = build_component_frame(cf, "Cargo", 2, 2, [
            "(random | <name>)", "<number#>", "[<number#>]", "[<probability#>]"
        ])
        self.cargoComponent.grid(row=4, column=0, sticky="ew")

        # Passengers
        self.passengersComponent = build_component_frame(
            cf, "Passengers", 1, 2,
            ["<number#>", "[<number#>]", "[<probability#>]"])
        self.passengersComponent.grid(row=5, column=0, sticky="ew")

        # Illegal
        self.illegalComponent = build_component_frame(
            cf, "Illegal", 1, 1, ["<fine#>", "[<message>]"])
        self.illegalComponent.grid(row=6, column=0, sticky="ew")

        # Stealth
        self.stealthComponent = build_component_frame(cf, "Stealth", 0, 0, [])
        self.stealthComponent.grid(row=7, column=0, sticky="ew")

        # Invisible
        self.invisibleComponent = build_component_frame(
            cf, "Invisible", 0, 0, [])
        self.invisibleComponent.grid(row=8, column=0, sticky="ew")

        # priorityLevel
        self.priorityLevelComponent = build_combo_component_frame(
            cf, "Priority Level", ["Priority", "Minor"])
        self.priorityLevelComponent.grid(row=9, column=0, sticky="ew")

        # whereShown
        self.whereShownComponent = build_combo_component_frame(
            cf, "Where Shown", ["Job", "Landing", "Assisting", "Boarding"])
        self.whereShownComponent.grid(row=10, column=0, sticky="ew")

        # Repeat
        self.repeatComponent = build_component_frame(cf, "Repeat", 0, 1,
                                                     ["[<times#>]"])
        self.repeatComponent.grid(row=11, column=0, sticky="ew")

        # Clearance
        self.clearanceComponent = build_component_frame(
            cf, "Clearance", 0, 1, ["[<message>]"])
        self.clearanceComponent.grid(row=12, column=0, sticky="ew")

        # Infiltrating
        self.infiltratingComponent = build_component_frame(
            cf, "Infiltrating", 0, 0, [])
        self.infiltratingComponent.grid(row=13, column=0, sticky="ew")

        # Waypoint
        self.waypointComponent = build_component_frame(cf, "Waypoint", 1, 0,
                                                       ["[<system>]"])
        self.waypointComponent.grid(row=14, column=0, sticky="ew")

        # Stopover
        self.stopoverComponent = build_component_frame(cf, "Stopover", 1, 0,
                                                       ["[<planet>]"])
        self.stopoverComponent.grid(row=15, column=0, sticky="ew")

        # Source
        self.sourceComponent = build_component_frame(cf, "Source", 1, 0,
                                                     ["[<planet>]"])
        self.sourceComponent.grid(row=16, column=0, sticky="ew")

        # Destination
        self.destinationComponent = build_component_frame(
            cf, "Destination", 1, 0, ["[<planet>]"])
        self.destinationComponent.grid(row=17, column=0, sticky="ew")

        # triggers
        self.triggersFrame = AggregatedTriggerFrame(self, cf)
        self.triggersFrame.grid(row=18, column=0, sticky="ew")

        # add a blank label to pad the bottom of the frame
        bl1 = ttk.Label(cf, textvariable=" ")
        bl1.grid(row=19, column=0, sticky="ew")

    #end build_center_frame

    def build_mission_frame(self):
        """Add widgets to the missionFrame"""
        logging.debug("\tBuilding missionFrame...")

        #Display a default mission template on launch
        self.missionFrame.grid(row=0, column=2, sticky="nsew")
        mf_title = ttk.Label(self.missionFrame, text="Mission Text")
        mf_title.pack()

        # Populate the Text with a mission template
        self.missionTextBox = Text(self.missionFrame,
                                   wrap=WORD,
                                   height=50,
                                   width=100)
        self.missionTextBox.pack(expand=1, fill='both')
        welcome_message = "\n"
        welcome_message += "\t\t\tWelcome to Endless Sky Mission Builder!\n"
        welcome_message += "\n\t - Click \"New Mission\" to get started\n"
        welcome_message += "\n\t - Click \"Save Mission File\" to save all the missions to a text file\n"
        welcome_message += "\n\t - Click \"Open Mission File\" to open a mission file for editing\n"
        welcome_message += "\n\t - Click \"Compile Mission\" to save save the current mission\n"
        welcome_message += "\n\t - Click \"Help\" to be directed to the Mission Creation wiki\n"
        self.missionTextBox.insert(END, welcome_message)
        self.missionTextBox.config(state=DISABLED)

    #end build_mission_frame

    ### UPDATING FRAMES ###

    def update_option_frame(self):
        """Update optionFrame to use the most recent data"""
        logging.debug("Updating optionFrame...")

        ### Start updating combobox
        ml = self.missionList
        self.missionNames = []
        for m in ml:
            self.missionNames.append(m.missionName)
        logging.debug("\tNew mission options: %s" % str(self.missionNames))

        # update options in the combobox
        self.missionComboBox['values'] = self.missionNames
        self.missionComboBox.current(0)
        ### Finish updating combobox

        # update the other two frames to reflect the current mission
        self.update_center_frame()
        self.update_mission_frame()

    #end update_option_frame

    def update_center_frame(self):
        """Update missionFrame to use the most recent data"""
        logging.debug("Updating centerFrame...")

        components = self.activeMission.components

        # missionDisplayName
        self.displayNameComponent.reset()
        if components.missionDisplayName is not None:
            self.displayNameComponent.set(0, 0, components.missionDisplayName)

        # description
        self.descriptionComponent.reset()
        if components.description is not None:
            description = components.description
            self.descriptionComponent.set(0, 0, description)
        #end if

        # blocked
        self.blockedComponent.reset()
        if components.blocked is not None:
            self.blockedComponent.set(0, 0, components.blocked)

        # deadline
        self.deadlineComponent.reset()
        if components.deadline.isDeadline is True:
            self.deadlineComponent.set(0, None, "isDeadlineCheckbutton")
            if components.deadline.deadline[0] is not None:
                self.deadlineComponent.set(1, 0,
                                           components.deadline.deadline[0])
                if components.deadline.deadline[1] is not None:
                    self.deadlineComponent.set(2, 1,
                                               components.deadline.deadline[1])
            #end if
        #end if

        # cargo
        self.cargoComponent.reset()
        if components.cargo.isCargo is True:
            self.cargoComponent.set(0, 0, components.cargo.cargo[0])
            self.cargoComponent.set(0, 1, components.cargo.cargo[1])
            if components.cargo.cargo[2] is not None:
                self.cargoComponent.set(1, 2, components.cargo.cargo[2])
                if components.cargo.cargo[2] is not None:
                    self.cargoComponent.set(2, 3, components.cargo.cargo[3])
            #end if
        #end if

        # passengers
        self.passengersComponent.reset()
        if components.passengers.isPassengers is True:
            self.passengersComponent.set(0, 0,
                                         components.passengers.passengers[0])
            if components.passengers.passengers[1] is not None:
                self.passengersComponent.set(
                    1, 1, components.passengers.passengers[1])
                if components.passengers.passengers[2] is not None:
                    self.passengersComponent.set(
                        2, 2, components.passengers.passengers[2])
            #end if
        #end if

        # illegal
        self.illegalComponent.reset()
        if components.illegal.isIllegal is True:
            self.illegalComponent.set(0, 0, components.illegal.illegal[0])
            if components.illegal.illegal[1] is not None:
                self.illegalComponent.set(1, 1, components.illegal.illegal[1])
            # end if
        # end if

        # stealth
        self.stealthComponent.reset()
        if components.isStealth is True:
            self.stealthComponent.set(0, None, "stealthCheckbutton")

        # invisible
        self.invisibleComponent.reset()
        if components.isInvisible is True:
            self.invisibleComponent.set(0, None, "isInvisibleCheckbutton")

        # priorityLevel
        self.priorityLevelComponent.reset()
        if components.priorityLevel is not None:
            self.priorityLevelComponent.set(components.priorityLevel)

        # whereShown
        self.whereShownComponent.reset()
        if components.whereShown is not None:
            self.whereShownComponent.set(components.whereShown)

        # repeat
        self.repeatComponent.reset()
        if components.isRepeat is True:
            self.repeatComponent.set(0, None, "isRepeatCheckbutton")
            if components.repeat is not None:
                self.repeatComponent.set(1, 0, components.repeat)
        #end if

        # clearance
        self.clearanceComponent.reset()
        if components.clearance.isClearance is True:
            self.clearanceComponent.set(0, None, "isClearanceCheckbutton")
            if components.clearance.clearance is not None:
                self.clearanceComponent.set(1, 0,
                                            components.clearance.clearance)
        #end if

        # infiltrating
        self.infiltratingComponent.reset()
        if components.isInfiltrating is True:
            self.infiltratingComponent.set(0, None,
                                           "isInfiltratingCheckbutton")

        # waypoint
        self.waypointComponent.reset()
        if components.waypoint is not None:
            self.waypointComponent.set(0, 0, components.waypoint)

        # stopover
        self.stopoverComponent.reset()
        if components.stopover.isStopover is True:
            self.stopoverComponent.set(0, 0, components.stopover.stopover)

        # source
        self.sourceComponent.reset()
        if components.source.isSource is True:
            self.sourceComponent.set(0, 0, components.source.source)

        # destination
        self.destinationComponent.reset()
        if components.destination.isDestination is True:
            self.destinationComponent.set(0, 0,
                                          components.destination.destination)

        # Clear out the AggregatedTriggerFrame
        self.triggersFrame.grid_forget()
        self.triggersFrame = AggregatedTriggerFrame(self,
                                                    self.centerFrame.inner)
        self.triggersFrame.grid(row=18, column=0, sticky="ew")

        # Triggers
        if components.triggerList:
            logging.debug("\tTriggers found")
            for trigger in components.triggerList:
                self.triggersFrame.populate_trigger(trigger)

    #end update_center_frame

    def update_mission_frame(self):
        """Update missionFrame to use the most recent data"""
        logging.debug("Updating missionFrame...")

        self.missionTextBox.forget()
        self.missionTextBox = Text(self.missionFrame,
                                   height=50,
                                   width=100,
                                   wrap=WORD)
        self.missionTextBox.pack()
        self.missionTextBox.insert(
            END, self.activeMission.print_mission_lines_to_text())
        self.missionTextBox.config(state=DISABLED)

    #end update_mission_frame

    ### MISC METHODS ###

    def mission_selected(self, event=None):
        """Set activeMission to the combobox option selected by the user"""
        selected_mission_name = self.missionComboBox.get()
        logging.debug("Opening mission \"%s\"" % selected_mission_name)
        self.activeMission = self.missionNameToObjectDict.get(
            selected_mission_name)
        self.update_center_frame()
        self.update_mission_frame()
Beispiel #4
0
def main():
    root = ThemedTk()
    root.columnconfigure(0, weight=1)
    root.rowconfigure(0, weight=1)
    makeGUI = MakeGUI(root)
    root.mainloop()
Beispiel #5
0
subframe.grid(column=0, row=2, columnspan=5, pady=5)
imageframe.grid(column=0, row=0, columnspan=3, rowspan=2, padx=5)

c1.grid(column=0, row=2, padx=5)
c2.grid(column=1, row=2, padx=5)
c3.grid(column=2, row=2, padx=5)
ok.grid(column=3, row=2, columnspan=2, padx=5)

label.grid(column=3, row=0, columnspan=2, padx=15)  # pad edges nicely
box.grid(column=3, row=1, columnspan=2, padx=15)
pic.grid()
namelbl.grid(sticky=E)

# give weights to the row and column expansions
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)

content.columnconfigure(0, weight=1)
content.columnconfigure(1, weight=1)
content.columnconfigure(2, weight=1)
content.columnconfigure(3, weight=1)
content.columnconfigure(4, weight=1)
content.rowconfigure(0, weight=1)
content.rowconfigure(1, weight=1)
content.rowconfigure(2, weight=1)

subframe.columnconfigure(0, weight=1)
subframe.columnconfigure(1, weight=1)
subframe.columnconfigure(2, weight=1)
subframe.columnconfigure(3, weight=1)
subframe.columnconfigure(4, weight=1)
    # only run once, no listener
    cmd = "python3 /usr/bin/apod_linux.py & disown"
    array = cmd.split()

    # non-blocking subprocess
    subprocess.Popen(array)

    # NB: don't close window

# create the main window (titlebar and frame)
# https://ttkthemes.readthedocs.io/en/latest/themes.html
main_window = ThemedTk(theme="equilux")
main_window.title("APOD_Linux config")
main_window.columnconfigure(0, weight=1)
main_window.rowconfigure(0, weight=1)
main_window.resizable(False, False)

# set main womdow's icon
icon = PhotoImage(
    file = "/usr/share/icons/hicolor/128x128/apps/apod_linux_icon.png")
main_window.iconphoto(False, icon)

# register the validate function with the main window (%S is the user input,
# whether typed or pasted)
validate_func = (main_window.register(validate), "%S")

# set variables/defults
# NB: needs to be done after main window creation
var_enabled = IntVar()
var_enabled.set(1)
Beispiel #7
0
class MainForm():
    def __init__(self):
        """
        Inicializa as variaveis usadas
        e também carrega o form principal
        """
        # Dicionário de ambientes (aba + exame)
        self.envDict = {}
        # Dicionário de exames
        self.examDict = {}
        # Lista de threads para carregar os exames
        self.loaderList = []
        self.envActive = None
        self.setForm()
        self.root.mainloop()

    def setForm(self):
        """
        Basicamente chama os metodos de construção do form,
        separado por estrutura (menus, abas, etc)
        """
        self.setRoot()
        self.setMainFrame()
        self.setEditMenu()
        self.setNotebook()
        self.setTopMenu()

    def setRoot(self):
        self.root = ThemedTk(theme="Adapta")
        self.root.rowconfigure(0, weight=1)
        self.root.columnconfigure(0, weight=1)
        self.root.state('zoomed')

    def setMainFrame(self):
        self.mainFrame = ttk.Frame(self.root)
        self.mainFrame.grid(row=0, column=0, sticky=tk.NSEW)
        self.mainFrame.rowconfigure(1, weight=1)
        self.mainFrame.columnconfigure(0, weight=1, uniform="mainframe")
        self.mainFrame.columnconfigure(1, weight=4, uniform="mainframe")
        self.mainFrame.bind(("<Escape>", self.clearCursor))

    def setEditMenu(self):
        self.drawThickness = tk.DoubleVar(self.root)

        self.editMenu = ttk.Frame(self.mainFrame)
        self.editMenu.grid(row=1, column=0, sticky=tk.NSEW)
        #self.editMenu.columnconfigure(0,weight=1)
        ttk.Button(self.editMenu,
                   text=btns.RECTANGLE,
                   command=lambda: self.cbRoi(Shape.RECTANGLE)).grid(
                       row=1, column=0, sticky=tk.NW)
        ttk.Button(self.editMenu,
                   text=btns.CIRCLE,
                   command=lambda: self.cbRoi(Shape.CIRCLE)).grid(row=2,
                                                                  column=0,
                                                                  sticky=tk.NW)
        ttk.Button(self.editMenu,
                   text=btns.DRAW,
                   command=lambda: self.cbDraw()).grid(row=3,
                                                       column=0,
                                                       sticky=tk.NW)
        ttk.Button(self.editMenu,
                   text=btns.ZOOM_IN,
                   command=lambda: self.cbZoom(True)).grid(row=4,
                                                           column=0,
                                                           sticky=tk.NW)
        ttk.Button(self.editMenu,
                   text=btns.ZOOM_OUT,
                   command=lambda: self.cbZoom(False)).grid(row=5,
                                                            column=0,
                                                            sticky=tk.NW)

        ttk.Scale(self.editMenu,
                  orient=tk.HORIZONTAL,
                  variable=self.drawThickness).grid(row=3,
                                                    column=1,
                                                    sticky=tk.NW)

    def setNotebook(self):
        self.notebook = ttk.Notebook(self.mainFrame, name=txt.NOTEBOOK)
        self.notebook.grid(row=1, column=1, sticky=tk.NSEW)
        self.root.update()
        self.notebook.bind("<<NotebookTabChanged>>", self.onEnvChange)

    def setTopMenu(self):
        #self.menubar = tk.Menu(self.root,tearoff=False)
        self.ttkMenubar = ttk.Menubutton(self.root)
        self.menubar = tk.Menu(self.root, tearoff=False)
        self.ttkMenubar['menu'] = self.menubar
        self.fileMenu = tk.Menu(self.menubar, tearoff=False)
        self.menubar.add_cascade(label=lblsTop.FILE,
                                 underline=0,
                                 menu=self.fileMenu)
        self.fileMenu.add_command(label=lblsTop.LOADEXAM,
                                  underline=0,
                                  compound=tk.LEFT,
                                  command=self.loadExam)
        self.root.config(menu=self.menubar)

    def loader(self, examID, dicomList):
        """
        Alvo da thread para criação de novos ambientes (abas)
        """
        self.envActive = Environment(examID, dicomList)
        self.loadImageNotebook()

    def loadExam(self):
        """
        Carrega os exames através do handler
        """
        examDict = dcmHandler.openDicomFiles()
        for examID, dicomList in examDict.items():
            self.loader(examID, dicomList)
            # t = Thread(target=self.loader,args=(img,))
            # loaderList.append(t)
            # t.start()

    def onEnvChange(self, event):
        print(self.notebook.index('current'))
        self.envActive = self.envDict[self.notebook.index(
            self.notebook.select())]
        self.clearCursor()

    def cbRoi(self, shape):
        cnv = self.envActive.resultCanvas
        cnv.bind(
            "<ButtonPress-1>", lambda event: edit.callbackRoi(
                env=self.envActive, event=event, shape=shape))
        cnv.bind("<B1-Motion>",
                 lambda event: edit.onMoveRoi(env=self.envActive, event=event))
        cnv.bind(
            "<ButtonRelease-1>",
            lambda event: edit.releaseRoi(env=self.envActive, event=event))

    def cbDraw(self):
        cnv = self.envActive.resultCanvas
        # cnv.bind("<ButtonPress-1>", lambda event: edit.callbackDraw(event=event))
        cnv.bind(
            "<B1-Motion>",
            lambda event: edit.onMoveDraw(event=event,
                                          env=self.envActive,
                                          thickness=self.drawThickness.get()))
        # cnv.bind("<ButtonRelease-1>", lambda event: edit.releaseDraw(event=event))

    def cbZoom(self, zoomIn):
        cnv = self.envActive.resultCanvas
        cnv.bind(
            "<ButtonRelease-1>", lambda event: edit.zoom(
                env=self.envActive, zoomIn=zoomIn, event=event))

    def loadImageNotebook(self):
        """
        Create a image in the notebook for the environment. The image is loaded in a tab in
        the notebook
        Input: Environment (env)
        Output: Frame inside the tab where the image is set (frm)
        """
        try:
            # Cria o frame e o canvas do exame usando o frame
            # definido como tab dentro do notebook
            self.envActive.createExamViewer(
                self.createTab(self.envActive.examID))
            self.envActive.updateImage()
            # self.envDict[len(self.notebook.tabs())-1] = self.envActive
            # self.notebook.select(len(self.notebook.tabs())-1)
            self.envDict[len(self.notebook.tabs())] = self.envActive
            self.root.update()
            self.notebook.select(len(self.notebook.tabs()) - 1)
        except Exception as ex:
            printLog(LOGTYPE.ERROR_LOAD_IMG_NOTEBOOK, ex)

    def createTab(self, exam):
        frm = ttk.Frame(self.notebook, name=exam)
        self.notebook.add(frm, text=exam)
        frm.rowconfigure(0, weight=1)
        frm.columnconfigure(0, weight=2, uniform='notebook')
        frm.columnconfigure(1, weight=1, uniform='notebook')
        return frm

    def clearCursor(self):
        frmName = self.notebook.select()
        frm = self.root.nametowidget(frmName)
        for cnvName in frm.children[txt.EXAMIMAGE].children:
            # Pega o canvas atual
            cnv = self.root.nametowidget(".".join(
                (frmName, txt.EXAMIMAGE, cnvName)))
            cnv.unbind("<ButtonPress-1>")
            cnv.unbind("<B1-Motion>")
            cnv.unbind("<ButtonRelease-1>")
Beispiel #8
0
    if mode == 0:
        print('is eco')
    if mode == 1:
        print('is normal')
    if mode == 2:
        print('is sport')

BUTTON_W = 25
BUTTON_H = int(BUTTON_W/2)

m = ThemedTk(className="Start Screen", theme="xpnative")
m.geometry('480x360')

rows = 0
while rows < 50:
    m.rowconfigure(rows, weight=1)
    m.columnconfigure(rows, weight=1)
    rows += 1

nb = ttk.Notebook(m)
nb.grid(row=1, column=0, columnspan='50', rowspan='49', sticky='NESW')

hometab = ttk.Frame(nb)
nb.add(hometab, text='Home')

measurement_tab = ttk.Frame(nb)
nb.add(measurement_tab, text='Measurements')
# displaying SOC

soc = 50
soc_label = ttk.Label(hometab, text=soc)