import clr
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')
from System.Windows.Forms import (Application, Form, FormBorderStyle, Label)
from System.Drawing import (Color, Font, FontStyle, Point)


class MainForm(Form):
    def __init__(self):
        self.Text = "Hello World"
        self.FormBorderStyle = FormBorderStyle.Fixed3D
        self.Height = 150

        newFont = Font("Verdana", 16, FontStyle.Bold | FontStyle.Italic)

        label = Label()
        label.AutoSize = True
        label.Text = "My Hello World Label"
        label.Location = Point(10, 50)
        label.BackColor = Color.Aquamarine
        label.ForeColor = Color.DarkMagenta
        label.Font = newFont

        self.Controls.Add(label)


mainForm = MainForm()
Application.Run(mainForm)
Beispiel #2
0
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

doc = DocumentManager.Instance.CurrentDBDocument
app = DocumentManager.Instance.CurrentUIApplication.Application
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

import sys
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Windows.Forms import Application, Form, Label
from System.Drawing import Size, Color, Point

class IForm(Form):
    def __init__(self):
        self.BackColor = Color.LightGray
        self.CenterToScreen()
        self.Text = 'Window_text'
        self.Size = Size(200, 200)

        self.label = Label()
        self.label.Parent = self
        self.label.Text = "HELLO"
        self.label.Location = Point(75, 75)
        self.label.Size = Size(200, 200)

Application.Run(IForm())

OUT = "rererere"
Beispiel #3
0
        timer.Interval = 6000
        timer.Tick += self.onTick
        timer.Start()

    def initNotifyIcon(self):
        self.notifyIcon = NotifyIcon()
        self.notifyIcon.Icon = Icon("test.ico")
        self.notifyIcon.Visible = True
        self.notifyIcon.ContextMenu = self.initContextMenu()

    def onTick(self, sender, event):
        self.notifyIcon.BalloonTipTitle = "Hello, I'm IronPython"
        self.notifyIcon.BalloonTipText = "Who are you?"
        self.notifyIcon.ShowBalloonTip(1000)

    def initContextMenu(self):
        contextMenu = ContextMenu()
        exitMenuItem = MenuItem("Exit")
        exitMenuItem.Click += self.onExit
        contextMenu.MenuItems.Add(exitMenuItem)
        return contextMenu

    def onExit(self, sender, event):
        self.notifyIcon.Visible = False
        Application.Exit()


if __name__ == "__main__":
    main = Main()
    Application.Run()
            return
        if self.ChDisplaydns.Checked == True:
            ipconfig = subprocess.Popen(["ipconfig", DisplayDNS],
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE)
            out, error = ipconfig.communicate()
            self.Wyswietlacz.Text = out
            self.ChDisplaydns.Checked = False
            return
        if self.ChFlushdns.Checked == True:
            ipconfig = subprocess.Popen(["ipconfig", FlushDNS],
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE)
            out, error = ipconfig.communicate()
            self.Wyswietlacz.Text = out
            self.ChFlushdns.Checked = False
            return
        else:
            ipconfig = subprocess.Popen(["ipconfig"],
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE)
            out, error = ipconfig.communicate()
            self.Wyswietlacz.Text = out
            return


#MessageBox.Show(MessageBoxButtons.OK ,"W przypadku wybrania opcji -t prosze nie wybierac innej z opcji", MessageBoxIcon.Information)

form = PythonAPP()
Application.Run(form)
Beispiel #5
0
def run_form():
    form = pyRevitPlusForm()
    Application.Run(form)
Beispiel #6
0
    def dropDownOutput(
        self, sender, args
    ):  #self is the instance of the GUI form. Sender is the control/widget. args is the argument/event provided from the control
        self.userOutput = sender.SelectedItem  #output the selected item.

    def okButtonPressed(self, sender, args):
        self.Close()  #trigger to close the GUI when button is pressed
        self.runNextOutput = True  #if the ok button is pressed set runNextOutput as True

    def CnlButtonPressed(self, sender, args):
        self.Close()
        self.runNextOutput = False  #if the ok button is pressed set runNextOutput as False

    def openLink(self, sender, event):
        webbrowser.open(sender.Tag)  #open a weblink
        #System.Diagnostics.Process.Start(sender.Tag);  #to open a PDF
        self.Close()
        self.runNextOutput = False

ddForm = DropDownForm()

if run:  #if input is true run the application.
    Application.Run(ddForm)

    if ddForm.userOutput == userOutputDefaultStr:  #if the user does not select a item So the userOutput value is still the default text
        results = ddForm.userOutput, False  #output the default string and runNextOutput
    else:
        results = ddForm.userOutput, ddForm.runNextOutput  #else if someone has selected a item output it and the runNextOutput

    OUT = results
            return 'Britain'
        elif 2100 <= x < 2690 and 1280 <= y < 2030:
            return 'Cove'
        elif 1385 <= x < 2690 and 2030 <= y < 3075:
            return 'Trinsic'
        elif 1900 <= x < 2690 and 3075 <= y <= 4096:
            return 'Valor'
        elif 2580 <= x < 3250 and y < 1890:
            return 'Vesper'
        elif 3250 <= x < 4100 and y < 1890:
            return "Nujel'm"
        elif 2100 <= x < 3850 and 1890 <= y < 3075:
            return 'Bucca'
        elif 2690 <= x < 3850 and 3075 <= y <= 4096:
            return 'Fire'
        elif x >= 4100 and y < 1890:
            return 'Moonglow'
        elif x >= 3850 and 1890 <= y < 2890:
            return 'Sea Market'
        elif x >= 3850 and y >= 2890:
            return 'Hythloth'
        else:
            return 'None'


Misc.SendMessage('Select the SOS container.', 67)
sbag = Target.PromptTarget()
if sbag > -1:
    SH = SOSManager(sbag)
    Application.Run(SH)
Beispiel #8
0
def main():
    app=App()
    Application.Run(app)
Beispiel #9
0
##############################################################################
#
#  Copyright (c) Microsoft Corporation. All rights reserved.
#
# This source code is subject to terms and conditions of the Apache License,
# Version 2.0. A copy of the license can be found in the License.html file at
# the root of this distribution. If you cannot locate the  Apache License,
# Version 2.0, please send an email to [email protected]. By using this
# source code in any fashion, you are agreeing to be bound by the terms of
# the Apache License, Version 2.0.
#
# You must not remove this notice, or any other, from this software.
#
#
##############################################################################

import clr
clr.AddReference("System.Windows.Forms")

from System.Windows.Forms import Application, Form


class FormV1(Form):
    def __init__(self):
        self.Text = "Hello World (" + __file__ + ")"


Application.Run(FormV1())
Beispiel #10
0
import clr
import Settings

Settings.SIMULATION = True  #this has to be set before importing Graphics
Settings.NJJ_SUBSECTIONS_LIST = [
    64, 32, 16, 8, 4, 2, 1, 1, 128, 256, 512, 1024, 2048, 4096
]  #number of junctions of each subarray, starting from V- to V+
Settings.NOT_BIASED_SINGLE_JUNCTION_POS = 8  #the 8th subsections (starting from 1) is the second single junction, that is never biased during the waveform synthesis
Settings.QUANTIZATION_TEST_BITS = [
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1
]  # all subarrays biased on 1 step, except the last one that is biased on the -1 step --> the overall voltage should be zero
Settings.VOLT_MAX_AWG = 12.0  #V for Active Technologies AT-AWG1104

import Graphics

clr.AddReference("System.Windows.Forms")

from System.Windows.Forms import Application

#For running the Graphic User Interface
PJVS_control = Graphics.PJVS_GUI()
Application.Run(PJVS_control)
Beispiel #11
0
print dir(font)
font = System.Activator.CreateInstance(font, "Arial", 12)
print "dir ", dir(font)
####################################
#    GUI Iform CODE STARTS HERE    #
####################################


class IForm(Form):
    def __init__(self):

        self.my_label = Label()
        self.my_label.Text = "Fonts work"
        self.my_label.Location = Point(10, 35)
        self.my_label.Height = 30
        self.my_label.Width = self.Width - 150
        try:
            self.my_label.Font = System.Drawing.Font("Arial", 12)
        except:
            self.my_label.Text = "font not found"
        self.Controls.Add(self.my_label)

        self.my_label.Font = font  #Font("Arial", 20)


##############################
#   end    GUI stuff         #
##############################

Application.Run(IForm())  #run the Iform...
Beispiel #12
0
# -*- coding:utf8 -*-

import clr

clr.AddReference("System.Windows.Forms")


from System.Windows.Forms import Application, Form 

class TestForm(Form):
  def __init__(self):
    self.Text = "Test"
    self.Width = 320
    self.Height = 200
    self.CenterToScreen()

Application.Run(TestForm())

# vi: set sw=4 sts=4 et
Beispiel #13
0
		
		# Register event
		button.Click += self.ButtonClicked
		
	def ButtonClicked(self, sender, args):
		if sender.Click:
			# Handle non numeric cases
			try:
				self.value = self.textboxDiv.Text
				self.Close()
			except:
				self.Close()

# Call the CreateWindow class and create the input for Drawer
formDrawer = CreateWindow("Change Parameter Drawn By", "Drawn by")
Application.Run(formDrawer)

# Assign the input to variable
nameDrawer = formDrawer.value

# Call the CreateWindow class and create the input for Checker
formChecker = CreateWindow("Change Parameter Checked By", "Checked by")
Application.Run(formChecker)

# Assign the input to variable
nameChecker = formChecker.value

# Store current document to variable
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
roomNameDoors = forms.SelectFromList.show(
    roomNames,
    "Select Rooms with Doors to Add Parameters",
    600,
    600,
    multiselect=True)

# Select doors to modify
modiDoors = [
    d for d in doorsCollector
    if d.LookupParameter("Room Name").AsString() in roomNameDoors
]

# Call the CreateWindow class
formDoorType = MultiStringWindow("Door Parameters")
Application.Run(formDoorType)
# Assign the input to variable
dParams = formDoorType.finalValue

# Set parameters for doors
# Create a individual transaction to change the parameters
t = DB.Transaction(doc, "Set Door Parameters")
# Start individual transaction
t.Start()
for d in modiDoors:
    # Use overloads with a string as IronPython will throw an error by using same string
    d.LookupParameter("Door Type").Set.Overloads[str](dParams[0])
    d.LookupParameter("Door Frame Type").Set.Overloads[str](dParams[1])
    d.LookupParameter("Door Frame Finish").Set.Overloads[str](dParams[2])
    d.LookupParameter("Door Leaf Type").Set.Overloads[str](dParams[3])
    d.LookupParameter("Meeting Styles").Set.Overloads[str](dParams[4])
            alt /= 3.28084
        return round(alt, 3)

    def convert_file(self, sender, event):
        try:
            output_file_type = poly_file
            num_reverse_passes = 0
            if sender == self.btn_output_wp:
                output_file_type = wp_file
                if self.spn_num_perimeter_passes.Enabled and int(
                        self.spn_num_perimeter_passes.Value):
                    num_reverse_passes = int(
                        self.spn_num_perimeter_passes.Value)
            filename = path.join(self.txt_path.Text,
                                 self.lst_files.SelectedItem)
            default_altitude = self.get_default_altitude()
            result = WaypointConverter(filename, output_file_type,
                                       num_reverse_passes,
                                       default_altitude).output_filename
            result = '{old_f}   →   {new_f}'.format(
                old_f=path.basename(filename), new_f=path.basename(result))
        except InvalidFile:
            result = 'Conversion failed - invalid file/filetype'
        self.refresh_filenames(None, None, False)
        self.lbl_status.Text = result


print('Running...')
Application.Run(WaypointFileToolForm())
print('Done')
Beispiel #16
0
    def draw(self, show=True, filename=None, update=False, usecoords=False):
        """Create a 2D depiction of the molecule.

        Optional parameters:
          show -- display on screen (default is True)
          filename -- write to file (default is None)
          update -- update the coordinates of the atoms to those
                    determined by the structure diagram generator
                    (default is False)
          usecoords -- don't calculate 2D coordinates, just use
                       the current coordinates (default is False)

        Tkinter and Python Imaging Library are required for image display.
        """
        if update:
            mol = self.Mol
        else:
            mol = self.Mol.clone()
        if not usecoords:
            mol.layout()
        if show or filename:
            renderer = IndigoRenderer(indigo)
            indigo.setOption("render-output-format", "png")
            indigo.setOption("render-margins", 10, 10)
            indigo.setOption("render-coloring", "True")
            indigo.setOption("render-image-size", 300, 300)
            indigo.setOption("render-background-color", "1.0, 1.0, 1.0")
            if self.title:
                indigo.setOption("render-comment", self.title)
            if filename:
                filedes = None
            else:
                filedes, filename = tempfile.mkstemp()

            renderer.renderToFile(mol, filename)

            if show:
                if sys.platform[:4] == "java":
                    image = javax.imageio.ImageIO.read(java.io.File(filename))
                    frame = javax.swing.JFrame(visible=1)
                    frame.getContentPane().add(
                        javax.swing.JLabel(javax.swing.ImageIcon(image)))
                    frame.setSize(300, 300)
                    frame.setDefaultCloseOperation(
                        javax.swing.WindowConstants.DISPOSE_ON_CLOSE)
                    frame.show()

                elif sys.platform[:3] == "cli":
                    if filedes:
                        errormessage = (
                            "It is only possible to show the molecule if you "
                            "provide a filename. The reason for this is that I kept "
                            "having problems when using temporary files.")
                        raise RuntimeError(errormessage)
                    form = Form()
                    form.ClientSize = Size(300, 300)
                    form.Text = self.title
                    image = Image.FromFile(filename)
                    box = PictureBox()
                    box.SizeMode = PictureBoxSizeMode.StretchImage
                    box.Image = image
                    box.Dock = DockStyle.Fill
                    form.Controls.Add(box)
                    form.Show()
                    Application.Run(form)

                else:
                    if not PILtk:
                        errormessage = (
                            "Tkinter or Python Imaging "
                            "Library not found, but is required for image "
                            "display. See installation instructions for "
                            "more information.")
                        raise ImportError, errormessage

                    root = tk.Tk()
                    root.title((hasattr(self, "title") and self.title)
                               or self.__str__().rstrip())
                    frame = tk.Frame(root, colormap="new",
                                     visual='truecolor').pack()
                    image = PIL.open(filename)
                    imagedata = PILtk.PhotoImage(image)
                    label = tk.Label(frame, image=imagedata).pack()
                    quitbutton = tk.Button(
                        root, text="Close",
                        command=root.destroy).pack(fill=tk.X)
                    root.mainloop()

            if filedes:
                os.close(filedes)
                os.remove(filename)
Beispiel #17
0
		self.checkLabel.Text = labeltext
		#self.Controls.Add(self.Text) maybe this is needed?


def renameROI(ROIname, plan, case):
	Popup = SelectROIForm(plan)
	Popup.redefine_text('Select the roi that is %s' %ROIname)
	Application.Run(Popup)

	with CompositeAction('Apply ROI changes (%s)' %Popup.roi_name_list[0]):
		case.PatientModelRegionsOfInterest['%s' %Popup.roi_name_list[0]].Name = ROIname
		
plan = get_current("Plan")

form = SelectROIForm(plan)
Application.Run(form)


case = get_current("Case")
examination = get_current("Examination")

#Try to copy ROI specified from UI

with CompositeAction('ROI Algebra (GTV68, Image set: CT 1)'):

	retval_GTV68 = case.PatientModel.CreateRoi(Name = "GTV68", Color = "255, 140, 0", Type = "Gtv", TissueName = None, RoiMaterial = None)

	retval_GTV68.CreateAlgebraGeometry(Examination=examination, Algorithm="Auto", 
									ExpressionA={ 'Operation': "Union", 'SourceRoiNames': [i for i in form.roi_name_list], 'MarginSettings': { 'Type': "Expand", 'Superior': 0, 'Inferior': 0, 'Anterior': 0, 'Posterior': 0, 'Right': 0, 'Left': 0 } }, 
									ExpressionB={ 'Operation': "Union", 'SourceRoiNames': [], 'MarginSettings': { 'Type': "Expand", 'Superior': 0, 'Inferior': 0, 'Anterior': 0, 'Posterior': 0, 'Right': 0, 'Left': 0 } }, 
									ResultOperation="None", ResultMarginSettings={ 'Type': "Expand", 'Superior': 0, 'Inferior': 0, 'Anterior': 0, 'Posterior': 0, 'Right': 0, 'Left': 0 })
def crane_launcher():

    class CraneLauncher(Form):
        def __init__(self):
            self.Text = "Plan de crâne stéréo"

            self.Width = 700
            self.Height = 900

            self.setupHeaderWindow()
            self.setupMainWindow()

            self.Controls.Add(self.HeaderWindow)
            self.Controls.Add(self.MainWindow)
            
            #Automatically populate ROI selection comboboxes
            self.PTV1combo.Items.Add("Choisissez ROI")
            self.PTV2combo.Items.Add("Choisissez ROI")
            self.PTV3combo.Items.Add("Choisissez ROI")    
            self.OAR1combo.Items.Add("Choisissez OAR")
            self.OAR2combo.Items.Add("Choisissez OAR")
            self.OAR3combo.Items.Add("Choisissez OAR")
            for roi in patient.PatientModel.RegionsOfInterest:       
                if 'PTV' in roi.Name.upper():
                    self.PTV1combo.Items.Add(roi.Name)
                    self.PTV2combo.Items.Add(roi.Name)
                    self.PTV3combo.Items.Add(roi.Name)      
                if 'PTV' not in roi.Name.upper():
                    self.OAR1combo.Items.Add(roi.Name)
                    self.OAR2combo.Items.Add(roi.Name)
                    self.OAR3combo.Items.Add(roi.Name)
                    
            #Determine whether to add dose color table by looking for existing plans
            try:
                existing_plan = patient.TreatmentPlans[0]
                self.isodosecombo.SelectedIndex = self.isodosecombo.FindStringExact('Ne pas créer')
            except:
                self.isodosecombo.SelectedIndex = self.isodosecombo.FindStringExact('Créer')
                
            
        def Panel(self, x, y):
            panel = Panel()
            panel.Width = 700
            panel.Height = 800
            panel.Location = Point(x, y)
            panel.BorderStyle = BorderStyle.None
            return panel

        def miniPanel(self, x, y):
            panel = Panel()
            panel.Width = 700
            panel.Height = 60
            panel.Location = Point(x, y)
            panel.BorderStyle = BorderStyle.None
            return panel                           
            
        def setupHeaderWindow(self):
            self.HeaderWindow = self.miniPanel(0, 0)     

            self.PatientIDHeader = Label()
            self.PatientIDHeader.Text = "Patient: " + patient.PatientName.replace('^', ', ')
            self.PatientIDHeader.Location = Point(25, 25)
            self.PatientIDHeader.Font = Font("Arial", 12, FontStyle.Bold)
            self.PatientIDHeader.AutoSize = True          

            self.HeaderWindow.Controls.Add(self.PatientIDHeader)
            
        def setupMainWindow(self):
            self.MainWindow = self.Panel(0, 60)
            
            vert_spacer = 30
            offset = 50   
            
            self.toplabel = Label()
            self.toplabel.Text = "PTV                      Dose (Gy)"
            self.toplabel.Font = Font("Arial", 10, FontStyle.Bold)
            self.toplabel.Location = Point(60, 20)
            self.toplabel.AutoSize = True  
                   
            self.PTV1combo = ComboBox()
            self.PTV1combo.Parent = self
            self.PTV1combo.Size = Size(120,40)
            self.PTV1combo.Location = Point(25, offset)
            self.PTV1combo.Text = "Choisissez ROI" 
     
            self.dose1_value = TextBox()
            self.dose1_value.Text = ""
            self.dose1_value.Location = Point(180, offset)
            self.dose1_value.Width = 50              

            self.PTV2combo = ComboBox()
            self.PTV2combo.Parent = self
            self.PTV2combo.Size = Size(120,40)
            self.PTV2combo.Location = Point(25, offset + vert_spacer)
            self.PTV2combo.Text = "Choisissez ROI" 

            self.dose2_value = TextBox()
            self.dose2_value.Text = ""
            self.dose2_value.Location = Point(180, offset + vert_spacer)
            self.dose2_value.Width = 50                                

            self.PTV3combo = ComboBox()
            self.PTV3combo.Parent = self
            self.PTV3combo.Size = Size(120,40)
            self.PTV3combo.Location = Point(25, offset + 2*vert_spacer)
            self.PTV3combo.Text = "Choisissez ROI" 
                      
            self.dose3_value = TextBox()
            self.dose3_value.Text = ""
            self.dose3_value.Location = Point(180, offset + 2*vert_spacer)
            self.dose3_value.Width = 50                   
         
         
            self.fxlabel = Label()
            self.fxlabel.Text = "Nb de fx"
            self.fxlabel.Location = Point(25, offset + 3.5*vert_spacer)
            self.fxlabel.Font = Font("Arial", 10, FontStyle.Bold)
            self.fxlabel.AutoSize = True              
            
            self.fxbox = TextBox()
            self.fxbox.Parent = self
            self.fxbox.Size = Size(50,40)
            self.fxbox.Location = Point(150, offset + 3.5*vert_spacer)
            self.fxbox.Text = "1"                 
            
            self.techlabel = Label()
            self.techlabel.Text = "Technique"
            self.techlabel.Location = Point(25, offset + 4.5*vert_spacer)
            self.techlabel.Font = Font("Arial", 10, FontStyle.Bold)
            self.techlabel.AutoSize = True              
            
            self.techcombo = ComboBox()
            self.techcombo.Parent = self
            self.techcombo.Size = Size(90,40)
            self.techcombo.Location = Point(150, offset + 4.5*vert_spacer)
            self.techcombo.Text = "VMAT" 
            self.techcombo.Items.Add('VMAT')
            self.techcombo.Items.Add('IMRT')
            self.techcombo.Items.Add('3DC')        
            
            self.sitelabel = Label()
            self.sitelabel.Text = "Nom du site"
            self.sitelabel.Location = Point(25, offset + 5.5*vert_spacer)
            self.sitelabel.Font = Font("Arial", 10, FontStyle.Bold)
            self.sitelabel.AutoSize = True              
            
            self.sitebox = TextBox()
            self.sitebox.Parent = self
            self.sitebox.Size = Size(50,40)
            self.sitebox.Location = Point(150, offset + 5.5*vert_spacer)
            self.sitebox.Text = "A1"    
            
            
            self.isolabel = Label()
            self.isolabel.Text = "Isocentre"
            self.isolabel.Location = Point(25, offset + 6.5*vert_spacer)
            self.isolabel.Font = Font("Arial", 10, FontStyle.Bold)
            self.isolabel.AutoSize = True              
            
            self.isocombo = ComboBox()
            self.isocombo.Parent = self
            self.isocombo.Size = Size(90,40)
            self.isocombo.Location = Point(150, offset + 6.5*vert_spacer)
            for poi in patient.PatientModel.PointsOfInterest:
                self.isocombo.Items.Add(poi.Name)
                if poi.Name == 'ISO':
                    self.isocombo.Text = 'ISO'
                elif self.isocombo.Text != 'ISO' and poi.Name == 'REF SCAN':
                    self.isocombo.Text = 'REF SCAN'
            
            
            self.scanlabel = Label()
            self.scanlabel.Text = "CT de planif"
            self.scanlabel.Location = Point(25, offset + 7.5*vert_spacer)
            self.scanlabel.Font = Font("Arial", 10, FontStyle.Bold)
            self.scanlabel.AutoSize = True              
            
            self.scancombo = ComboBox()
            self.scancombo.Parent = self
            self.scancombo.Size = Size(90,40)
            self.scancombo.Location = Point(150, offset + 7.5*vert_spacer)
            for ct in patient.Examinations:
                self.scancombo.Items.Add(ct.Name)         
                if ct.Name == 'CT 1':
                    self.scancombo.Text = 'CT 1'
            
            
            self.machinelabel = Label()
            self.machinelabel.Text = "Appareil"
            self.machinelabel.Location = Point(25, offset + 8.5*vert_spacer)
            self.machinelabel.Font = Font("Arial", 10, FontStyle.Bold)
            self.machinelabel.AutoSize = True              
            
            self.machinecombo = ComboBox()
            self.machinecombo.Parent = self
            self.machinecombo.Size = Size(90,40)
            self.machinecombo.Location = Point(150, offset + 8.5*vert_spacer)
            self.machinecombo.Text = "BeamMod"                  
            self.machinecombo.Items.Add('BeamMod')
            self.machinecombo.Items.Add('Infinity')
            

            self.isodoselabel = Label()
            self.isodoselabel.Text = "Dose table"
            self.isodoselabel.Location = Point(25, offset + 9.5*vert_spacer)
            self.isodoselabel.Font = Font("Arial", 10, FontStyle.Bold)
            self.isodoselabel.AutoSize = True              
            
            self.isodosecombo = ComboBox()
            self.isodosecombo.Parent = self
            self.isodosecombo.Size = Size(90,40)
            self.isodosecombo.Location = Point(150, offset + 9.5*vert_spacer)
            self.isodosecombo.Text = "Créer"                  
            self.isodosecombo.Items.Add('Créer')            
            self.isodosecombo.Items.Add('Ne pas créer')            


            self.couchlabel = Label()
            self.couchlabel.Text = "Couch table"
            self.couchlabel.Location = Point(25, offset + 10.5*vert_spacer)
            self.couchlabel.Font = Font("Arial", 10, FontStyle.Bold)
            self.couchlabel.AutoSize = True              
            
            self.couchcombo = ComboBox()
            self.couchcombo.Parent = self
            self.couchcombo.Size = Size(90,40)
            self.couchcombo.Location = Point(150, offset + 10.5*vert_spacer)
            self.couchcombo.Text = "Ne pas ajouter"                  
            self.couchcombo.Items.Add('Ne pas ajouter')            
            #self.couchcombo.Items.Add('Ajouter')                  

            
            self.message = Label()
            self.message.Text = "Sélectionnez le(s) ROI(s) à traiter (chaque\ncontour distinct devrait être indiqué\nséparément). Seulement les ROIs avec\nPTV dans leurs noms sont disponibles.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nLes plans IMRT/3DC avec plusieurs PTVs\ndistincts auront une optimisation automatique\ndu collimateur. SVP ne touchez pas à\nl'ordinateur pendant cette optimisation\n(4 à 5 minutes environ)"
            self.message.Location = Point(300, offset)
            self.message.Font = Font("Arial", 11, FontStyle.Italic)
            self.message.AutoSize = True                
            
            self.status = Label()
            self.status.Text = ""
            self.status.Location = Point(25, 760)
            self.status.Font = Font("Arial", 11, FontStyle.Bold)
            self.status.AutoSize = True    
            

            self.OARlabel = Label()
            self.OARlabel.Text = "Max doses custom (Gy)"
            self.OARlabel.Location = Point(25, offset + 13*vert_spacer)
            self.OARlabel.Font = Font("Arial", 10, FontStyle.Bold)
            self.OARlabel.AutoSize = True              
            
            self.OAR1combo = ComboBox()
            self.OAR1combo.Parent = self
            self.OAR1combo.Size = Size(120,40)
            self.OAR1combo.Location = Point(25, offset + 14*vert_spacer)
            self.OAR1combo.Text = "Choisissez OAR"     

            self.OAR1_value = TextBox()
            self.OAR1_value.Text = ""
            self.OAR1_value.Location = Point(160, offset + 14*vert_spacer)
            self.OAR1_value.Width = 50                  
            
            self.OAR2combo = ComboBox()
            self.OAR2combo.Parent = self
            self.OAR2combo.Size = Size(120,40)
            self.OAR2combo.Location = Point(25, offset + 15*vert_spacer)
            self.OAR2combo.Text = "Choisissez OAR"     
            
            self.OAR2_value = TextBox()
            self.OAR2_value.Text = ""
            self.OAR2_value.Location = Point(160, offset + 15*vert_spacer)
            self.OAR2_value.Width = 50                
            
            self.OAR3combo = ComboBox()
            self.OAR3combo.Parent = self
            self.OAR3combo.Size = Size(120,40)
            self.OAR3combo.Location = Point(25, offset + 16*vert_spacer)
            self.OAR3combo.Text = "Choisissez OAR"                 
            
            self.OAR3_value = TextBox()
            self.OAR3_value.Text = ""
            self.OAR3_value.Location = Point(160, offset + 16*vert_spacer)
            self.OAR3_value.Width = 50    

            
            evalButton = Button()
            evalButton.Text = "Évaluer les PTVs"
            evalButton.Location = Point(25, offset + 18 * vert_spacer)
            evalButton.Width = 200
            evalButton.Click += self.evalClicked                           
            
            addplanButton = Button()
            addplanButton.Text = "Ajouter plan"
            addplanButton.Location = Point(25, offset + 19 * vert_spacer)
            addplanButton.Width = 200
            addplanButton.Click += self.addplanClicked   


            self.stepcombo = ComboBox()
            self.stepcombo.Parent = self
            self.stepcombo.Size = Size(250,40)
            self.stepcombo.Location = Point(25, offset + 20 * vert_spacer)
            self.stepcombo.Text = "Rouler le script au complet"                  
            self.stepcombo.Items.Add('Rouler le script au complet')            
            self.stepcombo.Items.Add('Multi-PTV: Arrêtez avant optimization collimateur')            
            self.stepcombo.Items.Add('Multi-PTV: Reprendre après optimization collimateur')                   
            
            
            eraseROIButton = Button()
            eraseROIButton.Text = "Effacer les ROIs de prédiction"
            eraseROIButton.Location = Point(25, offset + 21.5 * vert_spacer)
            eraseROIButton.Width = 200
            eraseROIButton.Click += self.eraseROIClicked   
            
            
            
            self.MainWindow.Controls.Add(self.toplabel)
            
            self.MainWindow.Controls.Add(self.PTV1combo)
            self.MainWindow.Controls.Add(self.dose1_value)
            self.MainWindow.Controls.Add(self.PTV2combo)
            self.MainWindow.Controls.Add(self.dose2_value)
            self.MainWindow.Controls.Add(self.PTV3combo)
            self.MainWindow.Controls.Add(self.dose3_value)          

            self.MainWindow.Controls.Add(self.fxlabel)
            self.MainWindow.Controls.Add(self.fxbox)   
            
            self.MainWindow.Controls.Add(self.techlabel)          
            self.MainWindow.Controls.Add(self.techcombo)          
         
            self.MainWindow.Controls.Add(self.sitelabel)
            self.MainWindow.Controls.Add(self.sitebox)            

            self.MainWindow.Controls.Add(self.isolabel)
            self.MainWindow.Controls.Add(self.isocombo) 
            
            self.MainWindow.Controls.Add(self.scanlabel)          
            self.MainWindow.Controls.Add(self.scancombo)    
            
            self.MainWindow.Controls.Add(self.machinelabel)          
            self.MainWindow.Controls.Add(self.machinecombo)          

            self.MainWindow.Controls.Add(self.isodoselabel)          
            self.MainWindow.Controls.Add(self.isodosecombo)     

            self.MainWindow.Controls.Add(self.couchlabel)          
            self.MainWindow.Controls.Add(self.couchcombo)             
            
            self.MainWindow.Controls.Add(self.OARlabel)
            self.MainWindow.Controls.Add(self.OAR1combo)
            self.MainWindow.Controls.Add(self.OAR1_value)
            self.MainWindow.Controls.Add(self.OAR2combo)
            self.MainWindow.Controls.Add(self.OAR2_value)
            self.MainWindow.Controls.Add(self.OAR3combo)
            self.MainWindow.Controls.Add(self.OAR3_value)
            
            self.MainWindow.Controls.Add(self.message)            
            self.MainWindow.Controls.Add(self.status)     

            self.MainWindow.Controls.Add(evalButton)
            self.MainWindow.Controls.Add(addplanButton)            
            
            self.MainWindow.Controls.Add(self.stepcombo) 
            
            self.MainWindow.Controls.Add(eraseROIButton) 

            
            #Label empty contours
            exam_list = []
            for CT in patient.Examinations:
                exam_list.append(CT.Name)
                
            for contour in patient.PatientModel.RegionsOfInterest:
                VolCT1 = roi.get_roi_volume(contour.Name, exam=patient.Examinations["CT 1"])
                if "CT 2" in exam_list:
                    VolCT2 = roi.get_roi_volume(contour.Name, exam=patient.Examinations["CT 2"])
                else:
                    VolCT2 = 0

                if VolCT1 == 0 and VolCT2 == 0:
                    contour.Name = ("vide_" + contour.Name)               
            
            
            
        def compile_plan_data(self):            
                               
            self.status.Text = "Compilation des données du plan"      
            
            ptv_names = []
            rx = []  
            custom_max = []
            error_message = ""
            
            if roi.roi_exists(self.PTV1combo.Text):       
                ptv_names.append(self.PTV1combo.Text)
                try:
                    rx.append(int(float(self.dose1_value.Text) * 100))
                except:
                    error_message = "Dose du PTV 1 illisible"                    

            if roi.roi_exists(self.PTV2combo.Text):       
                ptv_names.append(self.PTV2combo.Text)
                try:
                    rx.append(int(float(self.dose2_value.Text) * 100))
                except:
                    error_message = "Dose du PTV 2 illisible"

            if roi.roi_exists(self.PTV3combo.Text):       
                ptv_names.append(self.PTV3combo.Text)
                try:
                    rx.append(int(float(self.dose3_value.Text) * 100))
                except:
                    error_message = "Dose du PTV 3 illisible"              
            
            if len(ptv_names) == 0:
                error_message = "Aucun PTV sélectionné"
            
            try:
                nb_fx = int(self.fxbox.Text)
            except:
                error_message = "Nb de fractions illisible"
                
            technique = self.techcombo.Text
                    
            if self.isocombo.Text == '':
                error_message = "Choisissez un isocentre avant de continuer"

            if self.scancombo.Text == '':
                error_message = "Choisissez un scan avant de continuer"
                
            if self.couchcombo.Text == 'Ajouter':
                couch = True
            else:
                couch = False                    
                                  
            name = self.sitebox.Text + ' ' + technique
            if couch:
                name += ' Couch'    
            if self.stepcombo.Text != "Multi-PTV: Reprendre après optimization collimateur": #We need to skip this step if completing a plan that was started earlier           
                try:    
                    existing_plan = patient.TreatmentPlans[name]
                    error_message = "Un plan avec le nom %s exist déjà, SVP le renommez avant de commencer" % name
                except:
                    pass                    
                
            if self.stepcombo.Text == "Multi-PTV: Arrêtez avant optimization collimateur" or self.stepcombo.Text == "Multi-PTV: Reprendre après optimization collimateur":
                if technique == 'VMAT':
                    error_message = "Le script partiel devrait seulement être utilisé pour les cas d'IMRT et 3DC"
                elif len(ptv_names) == 1:
                    error_message = "Le script partiel devrait seulement être utilisé pour les cas avec plus qu'un PTV"
                
            if roi.roi_exists(self.OAR1combo.Text):
                try:
                    custom_max.append((self.OAR1combo.Text,float(self.OAR1_value.Text))) #Yes, you need all those parentheses for this to work
                except:
                    error_message = "Impossible de lire custom max dose 1"
            if roi.roi_exists(self.OAR2combo.Text):
                try:
                    custom_max.append((self.OAR2combo.Text,float(self.OAR2_value.Text)))
                except:
                    error_message = "Impossible de lire custom max dose 2"
            if roi.roi_exists(self.OAR3combo.Text):
                try:
                    custom_max.append((self.OAR3combo.Text,float(self.OAR3_value.Text)))
                except:
                    error_message = "Impossible de lire custom max dose 3"         
                
                
            oar_list = crane.crane_stereo_kbp_identify_rois(patient)
            if oar_list[0] == 'ERROR':
                error_message = 'OAR essentiel pas trouvé: ' + oar_list[1]                     

            if error_message != '': #In case of any error, abort and send error message back
                d = []
                return d,error_message
            
            #Compile plan data to send to scripts
            d = dict(patient = patient,
                     site_name = self.sitebox.Text,
                     exam = patient.Examinations[self.scancombo.Text],
                     iso_name = self.isocombo.Text,
                     machine = self.machinecombo.Text,
                     nb_fx = nb_fx,
                     rx = rx,
                     rx_dose = max(rx), #Needed for isodose creation
                     ptv_names = ptv_names,
                     oar_list = oar_list,
                     technique = technique,
                     couch = couch,
                     custom_max = custom_max)      
            
            return d,error_message

            
        def evalClicked(self, sender, args):

            self.status.ForeColor = Color.Black
            self.status.Text = "Évaluation en cours, veuillez patienter"        
            
            d,error_message = self.compile_plan_data()
            
            if error_message != "": #If an error is noticed, cancel script execution
                self.status.Text = error_message
                self.status.ForeColor = Color.Red
                return                 
            
            rx = d['rx']
            ptv_names = d['ptv_names']
            
            #Predict dose to brain (and generate ROIs)
            self.status.ForeColor = Color.Black
            self.status.Text = "Estimation de la dose au cerveau"
            predicted_vol = crane.crane_stereo_kbp_predict_dose(plan_data = d)
            cerv_ptv_vol = patient.PatientModel.StructureSets[d['exam'].Name].RoiGeometries["CERVEAU-PTV_"+d['site_name']].GetRoiVolume()
            
            #Display predicted results
            self.message.Text = 'Volumes prédits dans le cerveau-PTV:\n   V100%%: %.2fcc\n   V90%%:  %.2fcc\n   V80%%:  %.2fcc\n   V70%%: %.2fcc\n   V60%%:  %.2fcc\n   V50%%:  %.2fcc\n   V40%%:  %.2fcc' % (predicted_vol[0],predicted_vol[1],predicted_vol[2],predicted_vol[3],predicted_vol[4],predicted_vol[5],predicted_vol[6])
            v10 = crane.estimate_vx(predicted_vol=predicted_vol,rx_dose=max(rx),dose_level=1000)
            v12 = crane.estimate_vx(predicted_vol=predicted_vol,rx_dose=max(rx),dose_level=1200)
            self.message.Text += '\n\nV10 Cerveau-PTV estimé: %s\nV12 Cerveau-PTV estimé: %s' % (v10,v12)
            if max(rx) >= 2000:
                v20 = crane.estimate_vx(predicted_vol=predicted_vol,rx_dose=max(rx),dose_level=2000)
                self.message.Text += '\nV20 Cerveau-PTV estimé: %s' % (v20)            
            
            self.status.Text = "Terminé"
            
            #Use bounding boxes to determine PTV diameters
            small_ptvs = 0
            medium_ptvs = 0
            for ptv in d['ptv_names']:
                bb = patient.PatientModel.StructureSets[d['exam'].Name].RoiGeometries[ptv].GetBoundingBox()
                ptv_vol = patient.PatientModel.StructureSets[d['exam'].Name].RoiGeometries[ptv].GetRoiVolume()
                dia = [abs(bb[0].x-bb[1].x),abs(bb[0].y-bb[1].y),abs(bb[0].z-bb[1].z)]
                self.message.Text += "\n\nCible: %s\n   Vol (cc): %.2f\n   Dimensions: %.2fcm x %.2fcm x %.2fcm" % (ptv,ptv_vol,dia[0],dia[1],dia[2])
                if min(dia)<1:
                    self.message.Text += "\nCe PTV est plus petit que 1cm, consultez la physique"
                elif min(dia)<2:
                    small_ptvs += 1
                elif min(dia)<3:
                    medium_ptvs +=1
                    
            if len(ptv_names) == 1 and small_ptvs == 0:                
                if medium_ptvs == 0:
                    self.message.Text += "\n\nLe VMAT devrait être utilisé pour ce plan"
                    self.techcombo.Text = 'VMAT'
                elif medium_ptvs == 1:
                    self.message.Text += "\n\nComme le PTV est relativement petit, faites une\ncomparaison 3DC/VMAT"
                    self.techcombo.Text = '3DC'
            elif len(ptv_names) == 1 and small_ptvs > 0:
                    self.message.Text += "\n\nLe PTV est trop petit pour un plan VMAT, utilisez le 3DC"
                    self.techcombo.Text = '3DC'
            elif len(ptv_names) > 1:
                if small_ptvs == 0:
                    self.message.Text += "\n\nL'IMRT devrait être utilisé pour ce plan"
                    self.techcombo.Text = 'IMRT'
                else:
                    self.message.Text += "\n\nAu moins un PTV <2cm, faites une comparaison\n3DC/IMRT et consultez la physique"
                    self.techcombo.Text = '3DC'            
   
   
        def addplanClicked(self, sender, args):
            self.status.ForeColor = Color.Black
            self.status.Text = "Compilation des données du plan"
            
            d,error_message = self.compile_plan_data()
            
            if error_message != "": #If an error is noticed, cancel script execution
                self.status.Text = error_message
                self.status.ForeColor = Color.Red
                return                  
        
            rx = d['rx']       
            ptv_names = d['ptv_names']
            technique = d['technique']
            site = d['site_name']
                                            
            #Predict dose to brain (and generate ROIs)
            self.status.Text = "Estimation de la dose au cerveau"
            predicted_vol = crane.crane_stereo_kbp_predict_dose(plan_data = d)
            cerv_ptv_vol = patient.PatientModel.StructureSets[d['exam'].Name].RoiGeometries["CERVEAU-PTV_"+d['site_name']].GetRoiVolume()            
            
            #Display predicted results
            self.message.Text = 'Volumes prédits dans le cerveau-PTV:\n   V100%%: %.2fcc\n   V90%%:  %.2fcc\n   V80%%:  %.2fcc\n   V70%%:  %.2fcc\n   V60%%:  %.2fcc\n   V50%%:  %.2fcc\n   V40%%:  %.2fcc' % (predicted_vol[0],predicted_vol[1],predicted_vol[2],predicted_vol[3],predicted_vol[4],predicted_vol[5],predicted_vol[6])
            v10 = crane.estimate_vx(predicted_vol=predicted_vol,rx_dose=max(rx),dose_level=1000)
            v12 = crane.estimate_vx(predicted_vol=predicted_vol,rx_dose=max(rx),dose_level=1200)
            self.message.Text += '\n\nV10 Cerveau-PTV estimé: %s\nV12 Cerveau-PTV estimé: %s' % (v10,v12)
            if max(rx) >= 2000:
                v20 = crane.estimate_vx(predicted_vol=predicted_vol,rx_dose=max(rx),dose_level=2000)
                self.message.Text += '\nV20 Cerveau-PTV estimé: %s' % (v20)
            
            self.status.Text = "Estimation de la dose max au tronc cerebral"
            tronc_max = crane.crane_stereo_kbp_predict_oar_dose(plan_data = d)    
            
            #Check which steps of the script are to be performed
            if self.stepcombo.Text == "Rouler le script au complet":
                add_plan = True
                optimize_collimator_angles = True
                optimize_plan = True               
            elif self.stepcombo.Text == "Multi-PTV: Arrêtez avant optimization collimateur":
                add_plan = True
                optimize_collimator_angles = False
                optimize_plan = False              
            elif self.stepcombo.Text == "Multi-PTV: Reprendre après optimization collimateur":
                add_plan = False
                optimize_collimator_angles = False
                optimize_plan = True            
            
            if add_plan:
                
                if patient.BodySite == '':
                    patient.BodySite = 'Crâne'  
                
                if self.isodosecombo.Text == "Créer":
                    self.status.Text = "Ajout du dose color table"
                    crane.crane_stereo_create_isodose_lines(plan_data = d)           
                    
                #Create/assign types to POIs and ROIs (only if this is the first plan for the patient)
                try:
                    existing_plan = patient.TreatmentPlans[0]
                except:                
                    if d['iso_name'] == 'REF SCAN': #Need to skip this step if planner is intentionally using a different isocenter
                        self.status.Text = "Création de l'isocentre à partir du REF SCAN"
                        poi.create_iso()
                    self.status.Text = "Gestion des POIs"
                    poi.auto_assign_poi_types()
                    
                    self.status.Text = "Suppression des overrides de densité"
                    for rois in patient.PatientModel.RegionsOfInterest:
                        rois.SetRoiMaterial(Material=None)    
                    
                    self.status.Text = "Création du contour externe"
                    roi.generate_BodyRS_using_threshold()
                    
                    #Create TISSU SAINS à 1cm
                    if not roi.roi_exists("TISSU SAIN 1cm "+site):
                        patient.PatientModel.CreateRoi(Name="TISSU SAIN 1cm "+site, Color="Magenta", Type="Organ", TissueName=None, RoiMaterial=None)
                        patient.PatientModel.RegionsOfInterest["TISSU SAIN 1cm "+site].SetAlgebraExpression(ExpressionA={'Operation': "Union", 'SourceRoiNames': ["BodyRS"], 'MarginSettings': {'Type': "Expand", 'Superior': 0, 'Inferior': 0, 'Anterior': 0, 'Posterior': 0, 'Right': 0, 'Left': 0}}, ExpressionB={'Operation': "Union", 'SourceRoiNames': ['sum_ptvs_'+site], 'MarginSettings': {'Type': "Expand", 'Superior': 1, 'Inferior': 1, 'Anterior': 1, 'Posterior': 1, 'Right': 1, 'Left': 1}}, ResultOperation="Subtraction", ResultMarginSettings={'Type': "Expand", 'Superior': 0, 'Inferior': 0, 'Anterior': 0, 'Posterior': 0, 'Right': 0, 'Left': 0})
                        patient.PatientModel.RegionsOfInterest["TISSU SAIN 1cm "+site].UpdateDerivedGeometry(Examination=exam)                    
                
                #Assign proper contour type to all PTVs
                self.status.Text = "Assignation du statut PTV"
                for ptv in ptv_names:
                    try:
                        roi.set_roi_type(ptv, 'Ptv', 'Target')
                    except:
                        pass #In a perfect world, I would copy the ROI, replace the PTV with the copy in ptv_names and then change its type
                
                #Add plan, beamset and beams
                self.status.Text = "Ajout du plan, beamset et faisceaux"
                if technique == 'VMAT': #Only case where we don't need a 3DC plan at all
                    plan,beamset = crane.crane_stereo_kbp_add_VMAT_plan_and_beamset(plan_data = d)
                
                elif technique == 'IMRT' and len(ptv_names) == 1:
                    plan,beamset = crane.crane_stereo_kbp_add_IMRT_plan_and_beamset(plan_data = d)
            
                elif technique == 'IMRT' and len(ptv_names) > 1:
                    if optimize_collimator_angles:
                        self.status.Text = "Ajout du plan, beamset et faisceaux (touchez pas à l'ordinateur SVP)"
                        plan,beamset = crane.crane_stereo_kbp_add_3DC_plan(plan_data = d)
                        
                        self.status.Text = "Optimisation angles collimateur (touchez pas à l'ordinateur SVP)"
                        crane.optimize_collimator_angles()
                        
                        self.status.Text = "Conversion du plan 3DC > IMRT (touchez pas à l'ordinateur SVP)"
                        crane.crane_stereo_convert_3DC_IMRT(plan=plan,beamset=beamset)
                    
                    else:
                        self.status.Text = "Ajout du plan, beamset et faisceaux"
                        plan,beamset = crane.crane_stereo_kbp_add_IMRT_plan_and_beamset(plan_data = d)
                        self.status.Text = "Prêt pour optimisation manuelle des angles de collimateur"
                        self.status.ForeColor = Color.Green
                        return
                    
                elif technique == '3DC':
                    self.status.Text = "Ajout du plan, beamset et faisceaux (touchez pas à l'ordinateur SVP)"
                    plan,beamset = crane.crane_stereo_kbp_add_3DC_plan(plan_data = d)
                    
                    #if len(ptv_names)>1:
                    if optimize_collimator_angles and len(ptv_names) > 1:
                        self.status.Text = "Optimisation angles collimateur (touchez pas à l'ordinateur SVP)"
                        crane.optimize_collimator_angles()  
                    elif not optimize_collimator_angles:
                        self.status.Text = "Prêt pour optimisation manuelle des angles de collimateur"
                        self.status.ForeColor = Color.Green
                        return

            if add_plan == False:
                plan = lib.get_current_plan()
                beamset = lib.get_current_beamset()
                
            if optimize_plan:
                            
                # Add clinical goals (conveniently the same for all types of plan)
                self.status.Text = "Ajout des clinical goals"
                clinical_goals.add_dictionary_cg('Crane Stereo', 15, 1, plan = plan)
                eval.add_clinical_goal("CERVEAU-PTV_"+d['site_name'], 1000, 'AtMost', 'AbsoluteVolumeAtDose', 10, plan=plan)
                eval.add_clinical_goal("CERVEAU-PTV_"+d['site_name'], 1200, 'AtMost', 'AbsoluteVolumeAtDose', 8, plan=plan)
                if max(rx) >= 2000:
                    eval.add_clinical_goal("CERVEAU-PTV_"+d['site_name'], 2000, 'AtMost', 'AbsoluteVolumeAtDose', 20, plan=plan)
                for i,ptv in enumerate(ptv_names):
                    eval.add_clinical_goal(ptv, rx[i], 'AtLeast', 'VolumeAtDose', 99, plan=plan)
                    eval.add_clinical_goal(ptv, 1.5 * rx[i], 'AtMost', 'DoseAtAbsoluteVolume', 0.1, plan=plan)
                    #if technique == '3DC':
                    #    optim.copy_clinical_goals(old_plan = plan,new_plan = patient.TreatmentPlans[d['site_name']+' 3DC optimised'])                    
                        
                #Add objectives and optimize plan
                if technique == '3DC':
                    self.status.Text = "Optimisation du plan 3DC (touchez pas à l'ordinateur SVP)"
                    plan,beamset = crane.crane_stereo_kbp_optimize_3DC_plan(plan_data=d,plan=plan,beamset=beamset) 
                    obtained_vol,initial_ptv_cov = crane.crane_stereo_kbp_scale_dose(plan_data=d,beamset=beamset,reset_dose=False)            
                else:
                    self.status.Text = "Ajout des objectifs d'optimisation"
                    crane.crane_stereo_kbp_initial_optimization_objectives(plan_data=d,plan=plan,predicted_vol=predicted_vol,tronc_max=tronc_max)
                    
                    #Make a copy of plan before optimizing for dosimetrists
                    patient.CopyPlan(PlanName=plan.Name, NewPlanName=plan.Name + ' non-optimisé')
                    
                    self.status.Text = "Optimization du plan initial"
                    plan.PlanOptimizations[beamset.Number-1].ResetOptimization() 
                    if len(ptv_names) == 1:
                        optim.triple_optimization(plan=plan,beamset=beamset)
                    elif len(ptv_names) > 1:
                        optim.optimization_90_30(plan=plan,beamset=beamset)  
                        
                    self.status.Text = "Modification du plan"
                    if len(ptv_names) == 1:
                        crane.crane_stereo_kbp_modify_plan_single_ptv(plan_data=d,plan=plan,beamset=beamset,predicted_vol=predicted_vol,tronc_max=tronc_max)
                        self.status.Text = "Optimization du plan modifié"
                        optim.triple_optimization(plan=plan,beamset=beamset)
                        self.status.Text = "Scaling couverture à la prescription"
                        obtained_vol,initial_ptv_cov = crane.crane_stereo_kbp_scale_dose(plan_data=d,beamset=beamset,reset_dose=False)
                    elif len(ptv_names) > 1:     
                        obtained_vol,initial_ptv_cov = crane.crane_stereo_kbp_scale_dose(plan_data=d,beamset=beamset,reset_dose=True)
                        self.message.Text += '\n\nV10 obtenu (plan initial): %.2fcc\nV12 obtenu (plan initial): %.2fcc' % (obtained_vol[0]*cerv_ptv_vol,obtained_vol[1]*cerv_ptv_vol)
                        continue_optimization = True
                        best_vol = 100000
                        for i in range(4): #i IS EQUAL TO THE NUMBER OF COMPLETED ITERATIONS!
                            if continue_optimization:
                                self.status.Text = "Modification du plan et réoptimisation (étape %d/4)" % (i+1)
                                continue_optimization = crane.crane_stereo_kbp_modify_plan_multi_ptv(plan_data=d,plan=plan,beamset=beamset) #Evaluates PTV coverage, adjusts and reoptimizes if necessary
                                obtained_vol,initial_ptv_cov = crane.crane_stereo_kbp_scale_dose(plan_data=d,beamset=beamset,reset_dose=True)
                                if (obtained_vol[0] + obtained_vol[1]) < best_vol:
                                    best_vol = obtained_vol[0] + obtained_vol[1]
                                    best_iteration = i
                                #if continue_optimization: #If crane_stereo_kbp_modify_plan_multi_ptv returns False, then the plan hasn't changed since last time and we don't need to print these values again
                                self.message.Text += '\n\nV10 obtenu (après %d révision(s)): %.2fcc\nV12 obtenu (après %d révision(s)): %.2fcc' % (i+1,obtained_vol[0]*cerv_ptv_vol,i+1,obtained_vol[1]*cerv_ptv_vol)                            
                        self.status.Text = "Scaling de la couverture à la prescription"
                        obtained_vol,initial_ptv_cov = crane.crane_stereo_kbp_scale_dose(plan_data=d,beamset=beamset,reset_dose=False)
                        
                        #Now we have to check if the final plan is better than the previous plans. If not, we will reoptimize and stop and the correct point.
                        self.status.Text = "Meilleur plan: plan initial avec %d itérations" % best_iteration
                        
                        #if (obtained_vol[0]+obtained_vol[1]*0.9) > best_vol:
                        if (obtained_vol[0]+obtained_vol[1]) > best_vol:
                            self.status.Text = "Retour vers le meilleur plan, veuillez patientez svp"
                            optim.erase_objectives(plan,beamset)
                            plan.PlanOptimizations[beamset.Number-1].ResetOptimization() 
                            crane.crane_stereo_kbp_initial_optimization_objectives(plan_data=d,plan=plan,predicted_vol=predicted_vol,tronc_max=tronc_max)
                            optim.optimization_90_30(plan=plan,beamset=beamset)
                            for i in range(best_iteration+1):
                                self.status.Text = "Modification du plan et réoptimisation (étape %d/%d)" % (i+1,best_iteration+1)
                                continue_optimization = crane.crane_stereo_kbp_modify_plan_multi_ptv(plan_data=d,plan=plan,beamset=beamset)
                            self.status.Text = "Scaling de la couverture à la prescription"
                            obtained_vol,initial_ptv_cov = crane.crane_stereo_kbp_scale_dose(plan_data=d,beamset=beamset,reset_dose=False)                            
                
                
                #Display results of plan
                self.message.Text += '\n\nV10 obtenu: %.2fcc\nV12 obtenu: %.2fcc' % (obtained_vol[0]*cerv_ptv_vol,obtained_vol[1]*cerv_ptv_vol)
                
                #Write results to file (this is put into a try because it will crash if someone has the destination file open when it tries to write to it)
                try:
                    crane.crane_kbp_write_results_to_file(plan_data=d,plan=plan,beamset=beamset,predicted_vol=predicted_vol,initial_ptv_cov=initial_ptv_cov,obtained_vol=obtained_vol)
                except:
                    pass
                
                #If the plan is VMAT or IMRT, copy it and set it up using the old technique for comparison
                if technique != '3DC':
                    kbp_plan_name = site + ' ' + technique
                    old_style_plan_name = site + ' ' + technique + ' RINGS'
                    self.status.Text = "Ajout du plan RINGS"
                    patient.CopyPlan(PlanName=kbp_plan_name, NewPlanName=old_style_plan_name)
                    plan = patient.TreatmentPlans[old_style_plan_name]
                    self.status.Text = "Nom du nouveau plan: " + plan.Name
                    beamset = plan.BeamSets[old_style_plan_name]
                    self.status.Text = "Préparation des ROIs et objectifs pour plan RINGS"
                    crane.crane_add_old_plan(plan_data=d,plan=plan,beamset=beamset)
                    #Create TISSU SAINS à 1cm (because sometimes I guess this wasn't happening for some reason)
                    if not roi.roi_exists("TISSU SAIN 1cm "+site):
                        patient.PatientModel.CreateRoi(Name="TISSU SAIN 1cm "+site, Color="Magenta", Type="Organ", TissueName=None, RoiMaterial=None)
                        patient.PatientModel.RegionsOfInterest["TISSU SAIN 1cm "+site].SetAlgebraExpression(ExpressionA={'Operation': "Union", 'SourceRoiNames': ["BodyRS"], 'MarginSettings': {'Type': "Expand", 'Superior': 0, 'Inferior': 0, 'Anterior': 0, 'Posterior': 0, 'Right': 0, 'Left': 0}}, ExpressionB={'Operation': "Union", 'SourceRoiNames': ['sum_ptvs_'+site], 'MarginSettings': {'Type': "Expand", 'Superior': 1, 'Inferior': 1, 'Anterior': 1, 'Posterior': 1, 'Right': 1, 'Left': 1}}, ResultOperation="Subtraction", ResultMarginSettings={'Type': "Expand", 'Superior': 0, 'Inferior': 0, 'Anterior': 0, 'Posterior': 0, 'Right': 0, 'Left': 0})
                        patient.PatientModel.RegionsOfInterest["TISSU SAIN 1cm "+site].UpdateDerivedGeometry(Examination=exam)     
                    plan.PlanOptimizations[beamset.Number-1].ResetOptimization()
                    self.status.Text = "Optimization du plan RINGS"
                    optim.optimization_90_30(plan=plan,beamset=beamset)
                
            self.isodosecombo.Text = 'Ne pas créer'
            self.status.Text = "Terminé avec succès!"
            self.status.ForeColor = Color.Green
        
    
    
        def eraseROIClicked(self, sender, args):

            self.status.ForeColor = Color.Black
            self.status.Text = "En cours, veuillez patienter"        
            
            erased_rois = 0
            
            for roi in patient.PatientModel.RegionsOfInterest:
                if 'predicted_r' in roi.Name or 'ptvs_smooth' in roi.Name:
                    try:
                        patient.PatientModel.RegionsOfInterest[roi.Name].DeleteRoi()
                        erased_rois += 1
                    except:
                        pass
    
            self.status.ForeColor = Color.Green
            self.status.Text = "%d ROIs effacés" % erased_rois
    
    
    #Check for common errors while importing patient, plan, beamset and examination
    try:
        patient = lib.get_current_patient()
    except:
        message.message_window('Aucun patient sélectionné')
        return                    
    try:
        exam = lib.get_current_examination()
    except:
        message.message_window('Aucun examination trouvé')
        return
        
    form = CraneLauncher()
    Application.Run(form)   
Beispiel #19
0
        # Display the window form to show in the middle of the screen
        self.CenterToScreen()

    # Functions to retrieve users input
    def ButtonClicked(self, sender, event):
        self.Close()

    def OnChanged(self, sender, event):
        if sender.Checked:
            self.value = sender.Text


# Call for the options form
buttonForm = IForm()
Application.Run(buttonForm)

# Check to move files or delete them
delMov = buttonForm.value

# Check if user selected backup option and store path for backups to var
backupDir = ""
if delMov == "Move to Folder":
    backupDir = windBrowser()


# Function to clean the backup files
def directoryClean(directory, backupDir):
    # Empty list to store the filenames that have been removed or moved
    modFiles = list()
    # Collect all files in directory and subdirectories
Beispiel #20
0
        if not self.m_disposed:
            if (self.m_req != None):
                self.m_req.Update -= self.m_req_Update
                self.m_req.Dispose()
                self.m_req = None
            if (self.m_ps != None):
                self.m_ps.FieldsUpdated -= self.m_ps_FieldsUpdated
                self.m_ps.Dispose()
                self.m_ps = None
        #Begin shutdown the TT API
        ttapi.TTAPI.ShutdownCompleted += self.TTAPI_ShutdownCompleted
        ttapi.TTAPI.Shutdown()
        self.m_disposed = True
        self.statusbar.Text = 'Disconnected... U R OUT'

# Unattached callbacks and dispose of all subscriptions
# Begin shutdown the TT API

    def TTAPI_ShutdownCompleted(self, sender, e):
        """ <summary>
		 Event notification for completion of TT API shutdown
		 </summary>
        """
        # Shutdown the Dispatcher
        if self.m_disp != None:
            self.m_disp.Dispose()
            self.m_disp = None

tr = TTAPIReadForm()
Application.Run(tr)
                int(self.config[0].split(',')[1]))
            self.chk_sticky.Checked = bool(int(self.config[0].split(',')[2]))
        self.toggle_width(self.chk_hide_factors, None)
        self.set_sticky(self.chk_sticky, None)
        if self.config is not None:
            self.configure_messages()
        print('Running...')

    def on_exit(self, sender, event):
        for attr_name in dir(MAVLink.MAVLINK_MSG_ID):
            if attr_name.upper() == attr_name:
                attr = getattr(MAVLink.MAVLINK_MSG_ID, attr_name)
                self.msg_ids[attr.value__] = attr
                MAV.UnSubscribeToPacketType(attr)
        print('Saving config: {}'.format(path.join(getcwd(), CONFIG_FILENAME)))
        f = open(CONFIG_FILENAME, 'w')
        f.write(str(self.spn_num_messages.Text) + ',')
        f.write(str(int(self.chk_hide_factors.Checked)) + ',')
        f.write(str(int(self.chk_sticky.Checked)) + ',\n')
        for widget in self.msg_widgets:
            for control in widget.items():
                if 'lbl' not in control[0]:
                    f.write('{},'.format(control[1].Text))
            f.write('\n')
        f.close()


print('Loading interface...')
Application.Run(MinMonitorForm())
print('Done')
Beispiel #22
0
    def draw(self, show=True, filename=None, update=False, usecoords=False):
        """Create a 2D depiction of the molecule.

        Optional parameters:
          show -- display on screen (default is True)
          filename -- write to file (default is None)
          update -- update the coordinates of the atoms to those
                    determined by the structure diagram generator
                    (default is False)
          usecoords -- don't calculate 2D coordinates, just use
                       the current coordinates (default is False)

        Tkinter and Python Imaging Library are required for image display.
        """
        obconversion = ob.OBConversion()
        formatok = obconversion.SetOutFormat("_png2")
        if not formatok:
            raise ImportError("PNG depiction support not found. You should "
                              "compile Open Babel with support for Cairo. See "
                              "installation instructions for more "
                              "information.")

        # Need to copy to avoid removing hydrogens from self
        workingmol = Molecule(ob.OBMol(self.OBMol))
        workingmol.removeh()

        if not usecoords:
            _operations['gen2D'].Do(workingmol.OBMol)
        if update:
            if workingmol.OBMol.NumAtoms() != self.OBMol.NumAtoms():
                raise RuntimeError("It is not possible to update the original "
                                   "molecule with the calculated coordinates, "
                                   "as the original molecule contains "
                                   "explicit hydrogens for which no "
                                   "coordinates have been calculated.")
            else:
                for i in range(workingmol.OBMol.NumAtoms()):
                    self.OBMol.GetAtom(i + 1).SetVector(
                        workingmol.OBMol.GetAtom(i + 1).GetVector())
        if filename:
            filedes = None
        else:
            if sys.platform[:3] == "cli" and show:
                raise RuntimeError("It is only possible to show the molecule "
                                   "if you provide a filename. The reason for "
                                   "this is that I kept having problems "
                                   "when using temporary files.")

            filedes, filename = tempfile.mkstemp()

        workingmol.write("_png2", filename=filename, overwrite=True)

        if show:
            if sys.platform[:4] == "java":
                image = javax.imageio.ImageIO.read(java.io.File(filename))
                frame = javax.swing.JFrame(visible=1)
                frame.getContentPane().add(
                    javax.swing.JLabel(javax.swing.ImageIcon(image)))
                frame.setSize(300, 300)
                frame.setDefaultCloseOperation(
                    javax.swing.WindowConstants.DISPOSE_ON_CLOSE)
                frame.show()
            elif sys.platform[:3] == "cli":
                form = _MyForm()
                form.setup(filename, self.title)
                Application.Run(form)
            else:
                if not tk:
                    raise ImportError("Tkinter or Python Imaging Library not "
                                      "found, but is required for image "
                                      "display. See installation instructions "
                                      "for more information.")
                root = tk.Tk()
                root.title((hasattr(self, "title") and self.title)
                           or self.__str__().rstrip())
                frame = tk.Frame(root, colormap="new",
                                 visual='truecolor').pack()
                image = PIL.open(filename)
                imagedata = piltk.PhotoImage(image)
                tk.Label(frame, image=imagedata).pack()
                tk.Button(root, text="Close",
                          command=root.destroy).pack(fill=tk.X)
                root.mainloop()
        if filedes:
            os.close(filedes)
            os.remove(filename)
Beispiel #23
0
def main():
    f = Form()
    f.Text = "HelloIronPython"
    Application.Run(f)
Beispiel #24
0
        cell = self.getcell(event)
        rowidx, colidx = getcellidxs(event)
        # overrides Windows selection color
        #   sometimes flashes blue for a split second
        clearselection(self.dgv)
        # if dealing with one valid data cell (not header)
        if cell:
            cell.Style.Font = BOLD
            cell.Style.BackColor = SELECTCOLOR
            selected.append(cell.Value)
        # if a row header is clicked, select row
        if colidx == INDEXERROR:
            # need to make sure that upper left header is not clicked
            if rowidx != INDEXERROR:
                row = self.dgv.Rows[rowidx]
                cells = row.Cells
                # highlight all the cells in the row
                for cell in cells:
                    cell.Style.Font = BOLD
                    cell.Style.BackColor = SELECTCOLOR
                    selected.append(cell.Value)
                # highlight the row header
                row.HeaderCell.Style.BackColor = SELECTCOLOR
        # get mouseover coloration reset
        self.onmouseovercell(sender, event)
        copytoclipboard(selected)


DGF = DataGridForm(NUMCOLS, NUMROWS)
Application.Run(DGF)
Beispiel #25
0
def main():
    form = IForm()
    Application.Run(form)
Beispiel #26
0
# This source code is subject to terms and conditions of the Apache License,
# Version 2.0. A copy of the license can be found in the License.html file at
# the root of this distribution. If you cannot locate the  Apache License,
# Version 2.0, please send an email to [email protected]. By using this
# source code in any fashion, you are agreeing to be bound by the terms of
# the Apache License, Version 2.0.
#
# You must not remove this notice, or any other, from this software.
#
#
##############################################################################

import clr
clr.AddReference("System.Windows.Forms")

from System.Windows.Forms import Application, Button, Form, MessageBox


class FormV2(Form):
    def __init__(self):
        self.Text = "Hello World (" + __file__ + ")"
        msgButton = Button(Text="Message", Left=20, Top=20)
        msgButton.Click += self.OnMsgButtonClick
        self.Controls.Add(msgButton)

    def OnMsgButtonClick(self, *args):
        MessageBox.Show("Hello World")


Application.Run(FormV2())
 def Main():
     """The main entry point for the application."""
     Application.EnableVisualStyles()
     Application.SetCompatibleTextRenderingDefault(False)
     Application.Run(MainForm())