def init(self): box = PictureBox() box.Dock = DockStyle.Fill box.SizeMode = PictureBoxSizeMode.AutoSize box.Image = self.image self.image = box.Image self.Controls.Add(box) self.ClientSize = box.Size
def __init__(self, bitmap): Form.__init__(self) picBox = PictureBox() picBox.SizeMode = PictureBoxSizeMode.AutoSize picBox.Image = bitmap picBox.Dock = DockStyle.Fill self.Controls.Add(picBox) self.Show() self.Width = bitmap.Width + 20 self.Height = bitmap.Height + 20
def init(self): """Initialize the form. Returns ------- None """ box = PictureBox() box.Dock = DockStyle.Fill box.SizeMode = PictureBoxSizeMode.AutoSize box.Image = self.image self.image = box.Image self.Controls.Add(box) self.ClientSize = box.Size
def setup(self, filename, title): # adjust the form's client area size to the picture self.ClientSize = Size(300, 300) self.Text = title self.filename = filename self.image = Image.FromFile(self.filename) pictureBox = PictureBox() # this will fit the image to the form pictureBox.SizeMode = PictureBoxSizeMode.StretchImage pictureBox.Image = self.image # fit the picture box to the frame pictureBox.Dock = DockStyle.Fill self.Controls.Add(pictureBox) self.Show()
def setup(self, filename, title): # adjust the form's client area size to the picture self.ClientSize = Size(300, 300) self.Text = title self.filename = filename self.image = Image.FromFile(self.filename) pictureBox = PictureBox() # this will fit the image to the form pictureBox.SizeMode = PictureBoxSizeMode.StretchImage pictureBox.Image = self.image # fit the picture box to the frame pictureBox.Dock = DockStyle.Fill self.Controls.Add(pictureBox) self.Show()
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)
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)