def createMenuBar(self): menuBar = JMenuBar() fileMenu = JMenu('File') data = [['Spam', self.spam], ['Eggs', self.eggs], ['Bacon', self.bacon]] bGroup = ButtonGroup() for name, handler in data: rb = JRadioButtonMenuItem(name, actionPerformed=handler, selected=(name == 'Spam')) bGroup.add(rb) fileMenu.add(rb) fileMenu.add(JSeparator()) # Using JSeparator() for name, handler in data: fileMenu.add(JCheckBoxMenuItem(name, actionPerformed=handler)) fileMenu.addSeparator() # Using addSeparator() exitItem = fileMenu.add( JMenuItem('Exit', KeyEvent.VK_X, actionPerformed=self.exit, accelerator=KeyStroke.getKeyStroke( 'x', InputEvent.ALT_DOWN_MASK))) menuBar.add(fileMenu) helpMenu = JMenu('Help') aboutItem = helpMenu.add( JMenuItem('About', KeyEvent.VK_A, actionPerformed=self.about)) menuBar.add(helpMenu) return menuBar
def init(self): w, h, aa, threads = (512, 512, 1, 2) canvas = RayTracePanel(w, h, aa, threads) self.getContentPane().add(JScrollPane(canvas)) #Save FileChooser #fcS = JFileChooser() #fcS.addChoosableFileFilter(FileNameExtensionFilter('Windows Bitmap (*.bmp)', ['bmp'])) #fcS.addChoosableFileFilter(FileNameExtensionFilter('JPEG / JFIF (*.jpg)', ['jpg'])) #fcS.addChoosableFileFilter(FileNameExtensionFilter('Portable Network Graphics (*.png)', ['png'])) #def saveFile(event): # '''Performed when the save button is pressed''' # result = fcS.showSaveDialog(frame) # if result == JFileChooser.APPROVE_OPTION: # file = fcS.getSelectedFile() # fname = file.getPath() # ext = fcS.getFileFilter().getExtensions()[0] # if not fname.endswith('.' + ext): # file = File(fname + '.' + ext) # canvas.saveToFile(file, ext) #Open FileChooser #fcO = JFileChooser() #fcO.addChoosableFileFilter(FileNameExtensionFilter('RayTrace Scene File (*.rts)', ['rts'])) #def openFile(event): # '''Performed when the open button is pressed''' # result = fcO.showOpenDialog(frame) # if result == JFileChooser.APPROVE_OPTION: # fname = fcO.getSelectedFile().getPath() # if fname.endswith('.rts'): # f = open(fname, 'rb') # newScene = SceneFactory().buildScene(f) # f.close() # Painter(canvas, newScene, openButton, saveButton, stopButton).start() def stop(event): '''Peformed when the stop button is pressed''' canvas.stopRendering() #Setup Menu menuBar = JMenuBar() menu = JMenu("File") menuBar.add(menu) #openButton = JMenuItem("Open...", actionPerformed=openFile) #openButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)) #menu.add(openButton) #saveButton = JMenuItem("Save as...", actionPerformed=saveFile) #saveButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)) #menu.add(saveButton) menu.addSeparator() stopButton = JMenuItem('Stop Render', actionPerformed=stop) stopButton.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0)) stopButton.setEnabled(False) menu.add(stopButton) menu.addSeparator() #closeButton = JMenuItem('Close', actionPerformed=exit) #closeButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK)) #menu.add(closeButton) self.setJMenuBar(menuBar)
def init(self): w, h, aa, threads = (512, 512, 1, 2) canvas = RayTracePanel(w, h, aa, threads) self.getContentPane().add(JScrollPane(canvas)) # Save FileChooser # fcS = JFileChooser() # fcS.addChoosableFileFilter(FileNameExtensionFilter('Windows Bitmap (*.bmp)', ['bmp'])) # fcS.addChoosableFileFilter(FileNameExtensionFilter('JPEG / JFIF (*.jpg)', ['jpg'])) # fcS.addChoosableFileFilter(FileNameExtensionFilter('Portable Network Graphics (*.png)', ['png'])) # def saveFile(event): # '''Performed when the save button is pressed''' # result = fcS.showSaveDialog(frame) # if result == JFileChooser.APPROVE_OPTION: # file = fcS.getSelectedFile() # fname = file.getPath() # ext = fcS.getFileFilter().getExtensions()[0] # if not fname.endswith('.' + ext): # file = File(fname + '.' + ext) # canvas.saveToFile(file, ext) # Open FileChooser # fcO = JFileChooser() # fcO.addChoosableFileFilter(FileNameExtensionFilter('RayTrace Scene File (*.rts)', ['rts'])) # def openFile(event): # '''Performed when the open button is pressed''' # result = fcO.showOpenDialog(frame) # if result == JFileChooser.APPROVE_OPTION: # fname = fcO.getSelectedFile().getPath() # if fname.endswith('.rts'): # f = open(fname, 'rb') # newScene = SceneFactory().buildScene(f) # f.close() # Painter(canvas, newScene, openButton, saveButton, stopButton).start() def stop(event): """Peformed when the stop button is pressed""" canvas.stopRendering() # Setup Menu menuBar = JMenuBar() menu = JMenu("File") menuBar.add(menu) openButton = JMenuItem("Open...", actionPerformed=openFile) openButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)) menu.add(openButton) # saveButton = JMenuItem("Save as...", actionPerformed=saveFile) # saveButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)) # menu.add(saveButton) menu.addSeparator() stopButton = JMenuItem("Stop Render", actionPerformed=stop) stopButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)) stopButton.setEnabled(False) menu.add(stopButton) menu.addSeparator() # closeButton = JMenuItem('Close', actionPerformed=exit) # closeButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK)) # menu.add(closeButton) self.setJMenuBar(menuBar)
def __init__(self, app, menuTitle): JMenu.__init__(self, menuTitle) self.app = app #quat dialog item dialogItem = JCheckBoxMenuItem(self.app.dlg.toggleAction) self.add(dialogItem) self.addSeparator() #tool submenu for tool in self.app.tools: if tool.name == "favourites": self.addSeparator() toolMenu = JMenu(tool.title) toolMenu.setIcon(tool.bigIcon) if tool.uri != "": #Website link iconFile = File.separator.join( [self.app.SCRIPTDIR, "images", "icons", "browser.png"]) urlItem = JMenuItem(tool.title) urlItem.setIcon(ImageIcon(iconFile)) urlItem.addActionListener( QatMenuActionListener(self.app, "link", tool)) toolMenu.add(urlItem) toolMenu.addSeparator() #View submenu for view in tool.views: viewMenu = JMenu(view.title) if tool.name == "favourites": self.app.favouritesMenu = viewMenu #Check item for check in view.checks: self.add_check_item(tool, view, check, viewMenu) toolMenu.add(viewMenu) self.add(toolMenu) #Local file with errors localFileItem = JMenuItem(self.app.strings.getString("Open_GPX")) localFileItem.setIcon(ImageProvider.get("open")) localFileItem.addActionListener( QatMenuActionListener(self.app, "local file")) self.add(localFileItem) self.addSeparator() #False positive dialog falsepositiveItem = JMenuItem( self.app.strings.getString("False_positives...")) falsepositiveItem.addActionListener( QatMenuActionListener(self.app, "dialog")) self.add(falsepositiveItem) #Preferences dialog preferencesItem = JMenuItem( self.app.strings.getString("Preferences...")) preferencesItem.addActionListener( QatMenuActionListener(self.app, "dialog")) self.add(preferencesItem) #About dialog item aboutItem = JMenuItem(self.app.strings.getString("About...")) aboutItem.addActionListener(QatMenuActionListener(self.app, "dialog")) self.add(aboutItem)
def __init__(self, app, menuTitle): JMenu.__init__(self, menuTitle) self.app = app #quat dialog item dialogItem = JCheckBoxMenuItem(self.app.dlg.toggleAction) self.add(dialogItem) self.addSeparator() #tool submenu for tool in self.app.tools: if tool.name == "favourites": self.addSeparator() toolMenu = JMenu(tool.title) toolMenu.setIcon(tool.bigIcon) if tool.uri != "": #Website link iconFile = File.separator.join([self.app.SCRIPTDIR, "images", "icons", "browser.png"]) urlItem = JMenuItem(tool.title) urlItem.setIcon(ImageIcon(iconFile)) urlItem.addActionListener(QatMenuActionListener(self.app, "link", tool)) toolMenu.add(urlItem) toolMenu.addSeparator() #View submenu for view in tool.views: viewMenu = JMenu(view.title) if tool.name == "favourites": self.app.favouritesMenu = viewMenu #Check item for check in view.checks: self.add_check_item(tool, view, check, viewMenu) toolMenu.add(viewMenu) self.add(toolMenu) #Local file with errors localFileItem = JMenuItem(self.app.strings.getString("Open_GPX")) localFileItem.setIcon(ImageProvider.get("open")) localFileItem.addActionListener(QatMenuActionListener(self.app, "local file")) self.add(localFileItem) self.addSeparator() #False positive dialog falsepositiveItem = JMenuItem(self.app.strings.getString("False_positives...")) falsepositiveItem.addActionListener(QatMenuActionListener(self.app, "dialog")) self.add(falsepositiveItem) #Preferences dialog preferencesItem = JMenuItem(self.app.strings.getString("Preferences...")) preferencesItem.addActionListener(QatMenuActionListener(self.app, "dialog")) self.add(preferencesItem) #About dialog item aboutItem = JMenuItem(self.app.strings.getString("About...")) aboutItem.addActionListener(QatMenuActionListener(self.app, "dialog")) self.add(aboutItem)
def __init__(self): self.running = True menuBar = JMenuBar() menu = JMenu("File") menu.add(OpenAction(self)) menu.add(CloseAction(self)) menu.addSeparator() menu.add(QuitAction(self)) self.addWindowListener(ProfelisWindowAdapter(self)) menuBar.add(menu) self.setJMenuBar(menuBar) self.contentPane = JPanel() self.contentPane.layout = GridBagLayout() constraints = GridBagConstraints() self.blastLocation = JTextField( System.getProperty("user.home") + "/blast") self.databaseLocation = JTextField( System.getProperty("user.home") + "/blast/db") self.projects = JTabbedPane() constraints.gridx, constraints.gridy = 0, 0 constraints.gridwidth, constraints.gridheight = 1, 1 constraints.fill = GridBagConstraints.NONE constraints.weightx, constraints.weighty = 0, 0 self.contentPane.add(JLabel("Blast Location"), constraints) constraints.gridx, constraints.gridy = 1, 0 constraints.fill = GridBagConstraints.HORIZONTAL constraints.weightx, constraints.weighty = 1, 0 self.contentPane.add(self.blastLocation, constraints) constraints.gridx, constraints.gridy = 2, 0 constraints.fill = GridBagConstraints.NONE constraints.weightx, constraints.weighty = 0, 0 self.contentPane.add(JButton(BlastAction(self)), constraints) constraints.gridx, constraints.gridy = 3, 0 constraints.fill = GridBagConstraints.NONE constraints.weightx, constraints.weighty = 0, 0 self.contentPane.add(JLabel("Database Location"), constraints) constraints.gridx, constraints.gridy = 4, 0 constraints.fill = GridBagConstraints.HORIZONTAL constraints.weightx, constraints.weighty = 1, 0 self.contentPane.add(self.databaseLocation, constraints) constraints.gridx, constraints.gridy = 5, 0 constraints.fill = GridBagConstraints.NONE constraints.weightx, constraints.weighty = 0, 0 self.contentPane.add(JButton(DatabaseAction(self)), constraints) constraints.gridx, constraints.gridy = 0, 1 constraints.gridwidth, constraints.gridheight = 6, 1 constraints.fill = GridBagConstraints.BOTH constraints.weightx, constraints.weighty = 1, 1 self.contentPane.add(self.projects, constraints)
def __init__(self): self.running = True menuBar = JMenuBar() menu = JMenu("File") menu.add(OpenAction(self)) menu.add(CloseAction(self)) menu.addSeparator() menu.add(QuitAction(self)) self.addWindowListener(ProfelisWindowAdapter(self)) menuBar.add(menu) self.setJMenuBar(menuBar) self.contentPane = JPanel() self.contentPane.layout = GridBagLayout() constraints = GridBagConstraints() self.blastLocation = JTextField(System.getProperty("user.home") + "/blast") self.databaseLocation = JTextField(System.getProperty("user.home") + "/blast/db") self.projects = JTabbedPane() constraints.gridx, constraints.gridy = 0, 0 constraints.gridwidth, constraints.gridheight = 1, 1 constraints.fill = GridBagConstraints.NONE constraints.weightx, constraints.weighty = 0, 0 self.contentPane.add(JLabel("Blast Location"), constraints) constraints.gridx, constraints.gridy = 1, 0 constraints.fill = GridBagConstraints.HORIZONTAL constraints.weightx, constraints.weighty = 1, 0 self.contentPane.add(self.blastLocation, constraints) constraints.gridx, constraints.gridy = 2, 0 constraints.fill = GridBagConstraints.NONE constraints.weightx, constraints.weighty = 0, 0 self.contentPane.add(JButton(BlastAction(self)), constraints) constraints.gridx, constraints.gridy = 3, 0 constraints.fill = GridBagConstraints.NONE constraints.weightx, constraints.weighty = 0, 0 self.contentPane.add(JLabel("Database Location"), constraints) constraints.gridx, constraints.gridy = 4, 0 constraints.fill = GridBagConstraints.HORIZONTAL constraints.weightx, constraints.weighty = 1, 0 self.contentPane.add(self.databaseLocation, constraints) constraints.gridx, constraints.gridy = 5, 0 constraints.fill = GridBagConstraints.NONE constraints.weightx, constraints.weighty = 0, 0 self.contentPane.add(JButton(DatabaseAction(self)), constraints) constraints.gridx, constraints.gridy = 0, 1 constraints.gridwidth, constraints.gridheight = 6, 1 constraints.fill = GridBagConstraints.BOTH constraints.weightx, constraints.weighty = 1, 1 self.contentPane.add(self.projects, constraints)
def createMenuItems(self, invocation): menu = JMenu(self._actionName) # create import file menu. import_menu = JMenu("import file") as_json_menu_item = JMenuItem("as JSON") as_json_menu_item.actionPerformed = self.generateSelectFileAction( invocation, as_json_menu_item) import_menu.add(as_json_menu_item) menu.add(import_menu) menu.addSeparator() # load snippets json file. snippets_data = None try: with open(self.snippets_file_path, "r") as f: snippets_data = json.load(f) except Exception as e: print("Load JSON Error!") print(e) # create payload menu. # # if snippets_data is not set. if snippets_data is None: return [menu] try: for i in snippets_data: type_menu = JMenu(i["type"]) for j in i["items"]: key = j["key"] payload = j["value"] a = JMenuItem( key, None, actionPerformed=self.generateClickAction( invocation, payload), ) type_menu.add(a) menu.add(type_menu) except Exception as e: print("Convert snippets Error!") print(e) return [menu]
def setMenuBar(self): menuBar = JMenuBar() menuApp = JMenu("Apps") menuApp.setMnemonic('A') menuSettings = JMenu("Settings") menuSettings.setMnemonic('S') #set submenus menuPlayNow = JMenu("PlayNow" ) menuPlayNowOpen = JMenuItem("Open", actionPerformed = (lambda x, param="open": self.playNowApp_startThread(param)) ) menuPlayNow.add(menuPlayNowOpen) menuPlayNowLogin = JMenuItem("Login", actionPerformed = lambda x, action="playNowLogin": self.playNowApp_startThread(action) ) menuPlayNow.add(menuPlayNowLogin) menuPlayNowClose = JMenuItem("Close", actionPerformed = lambda x, action="playNowClose": self.playNowApp_startThread(action) ) menuPlayNow.add(menuPlayNowClose) menuPokerTable = JMenu("PokerTable") menuPokerTableJoin = JMenuItem("Find Practice Table", actionPerformed = lambda x, action="practiceTable": self.playNowApp_startThread(action) ) menuPokerTable.add(menuPokerTableJoin) menuPokerTableJoin = JMenuItem("Join Table", actionPerformed = lambda x, action="joinTable": self.playNowApp_startThread(action) ) menuPokerTable.add(menuPokerTableJoin) menuPokerTableAddChips = JMenuItem("Add Chips", actionPerformed = lambda x, action="addChips": self.playNowApp_startThread(action) ) menuPokerTable.add(menuPokerTableAddChips) menuPokerTableSitOut = JMenuItem("Sit Out", actionPerformed = lambda x, action="sitOut": self.playNowApp_startThread(action) ) menuPokerTable.add(menuPokerTableSitOut) menuPokerTableLeaveTable = JMenuItem("Leave Table", actionPerformed = lambda x, action="leaveTable": self.playNowApp_startThread(action) ) menuPokerTable.add(menuPokerTableLeaveTable) menuPokerAppExit = JMenuItem("Exit") menuApp.add(menuPlayNow) menuApp.add(menuPokerTable) menuApp.addSeparator() menuApp.add(menuPokerAppExit) menuBar.add(menuApp) menuBar.add(menuSettings) self._frame.setJMenuBar(menuBar)
def makeMenu(self): menuBar = JMenuBar(background=Color.blue, foreground=Color.white) showMenu = JMenu('Show', background=Color.blue, foreground=Color.white) self.deprecated = JCheckBoxMenuItem('Deprecated', 1, actionPerformed=self.showItems) showMenu.add(self.deprecated) self.protected = JCheckBoxMenuItem('Protected', 1, actionPerformed=self.showItems) showMenu.add(self.protected) showMenu.addSeparator() showMenu.add(JMenuItem('Exit', actionPerformed=self.exit)) menuBar.add(showMenu) return menuBar
def initUI(self): menubar = JMenuBar() start = JMenu("Start") start.setMnemonic(KeyEvent.VK_S) apps = JMenu("Applications") apps.setPreferredSize(Dimension(200, 35)) apps.setToolTipText("Stylus Applications") web = JMenuItem("Internet", actionPerformed=self.internet) web.setPreferredSize(Dimension(200, 35)) web.setToolTipText("Stylus Web Browser") apps.add(web) image = JMenuItem("Image Viewer", actionPerformed=self.photos) image.setPreferredSize(Dimension(200, 35)) image.setToolTipText("Stylus Image Viewer") apps.add(image) start.add(apps) utility = JMenu("Utility") utility.setPreferredSize(Dimension(200, 35)) utility.setToolTipText("Stylus Utility") voice = JMenuItem("Anna", actionPerformed=self.vocal) voice.setPreferredSize(Dimension(200, 35)) voice.setToolTipText("Anna Vocal Assistant") utility.add(voice) clc = JMenuItem("Calculator", actionPerformed=self.calc) clc.setPreferredSize(Dimension(200, 35)) clc.setToolTipText("Stylus Calculator") utility.add(clc) fman = JMenuItem("File Manager", actionPerformed=self.file_manager) fman.setPreferredSize(Dimension(200, 35)) fman.setToolTipText("Stylus File Manager") utility.add(fman) txted = JMenuItem("Notepad", actionPerformed=self.notepad) txted.setPreferredSize(Dimension(200, 35)) txted.setToolTipText("Stylus Notepad") utility.add(txted) terminal = JMenuItem("Terminal (as root)", actionPerformed=self.lxterminal) terminal.setPreferredSize(Dimension(200, 35)) terminal.setToolTipText("Stylus Terminal") utility.add(terminal) start.add(utility) games = JMenu("Games") games.setPreferredSize(Dimension(200, 35)) games.setToolTipText("PyOS Games") g1 = JMenuItem("2048", actionPerformed=self.d2048) g1.setPreferredSize(Dimension(200, 35)) g1.setToolTipText("Play 2048 Game") games.add(g1) g2 = JMenuItem("Ping Pong", actionPerformed=self.ppong) g2.setPreferredSize(Dimension(200, 35)) g2.setToolTipText("Play Ping Pong Game") games.add(g2) start.add(games) start.addSeparator() exit = JMenuItem("Exit", actionPerformed=self.onExit) exit.setPreferredSize(Dimension(200, 35)) exit.setToolTipText("Stylus Exit") start.add(exit) menubar.add(start) file = JMenu("File") file.setMnemonic(KeyEvent.VK_F) tk = Toolkit.getDefaultToolkit() xSize = (int(tk.getScreenSize().getWidth())) ySize = (int(tk.getScreenSize().getHeight())) self.setSize(xSize, ySize) filebg = open("/icons/background.txt", "r") path = filebg.readline() filebg.close() panel2 = bg.background(path, self.getWidth(), self.getHeight() - 100) theme = JMenuItem("Change background", actionPerformed=lambda e: self.bg(panel2, e)) theme.setPreferredSize(Dimension(200, 35)) theme.setToolTipText("Stylus Background") file.add(theme) menubar.add(file) info = JMenu("?") info.setMnemonic(KeyEvent.VK_I) inf = JMenuItem("Info", actionPerformed=self.onInfo) inf.setToolTipText("Stylus Information") info.add(inf) menubar.add(info) menubar.add(Box.createHorizontalGlue()) timedate = JMenu(time.strftime("%a, %Y %b %d, %H:%M")) timedate.setMnemonic(KeyEvent.VK_C) calendar = JMenuItem("Calendar", actionPerformed=self.calendar) calendar.setPreferredSize(Dimension(200, 35)) timedate.add(calendar) menubar.add(timedate) menubar.add(JLabel(" ")) menubar.setPreferredSize(Dimension(200, 35)) self.setJMenuBar(menubar) self.setTitle("Stylus OS") self.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) #self.setSize(1360, 768) self.setLocationRelativeTo(None) """time = JPanel() time.setBorder(BorderFactory.createEtchedBorder()) time.setBackground(Color(153, 203, 255)) time.setLayout(GridLayout(0, 1)) f = Font("", Font.PLAIN, 60) t = JLabel("11:51") t.setHorizontalAlignment(JLabel.CENTER) t.setFont(f) time.add(t) f2 = Font("", Font.PLAIN, 50) d = JLabel("Tuesday, 2016/07/12") d.setHorizontalAlignment(JLabel.CENTER) d.setFont(f2) time.add(d) self.getContentPane().add(time) self.add(time, BorderLayout.NORTH)""" panel = JPanel() self.getContentPane().add(panel) b0 = JButton(ImageIcon("/icons/file-manager.png"), actionPerformed=self.file_manager) b0.setToolTipText("File Manager") panel.add(b0) b1 = JButton(ImageIcon("/icons/internet.png"), actionPerformed=self.internet) b1.setToolTipText("Internet") panel.add(b1) b2 = JButton(ImageIcon("/icons/mail.png")) b2.setToolTipText("Mail") #panel.add(b2) b3 = JButton(ImageIcon("/icons/music.png")) b3.setToolTipText("Music") #panel.add(b3) b4 = JButton(ImageIcon("/icons/video.png")) b4.setToolTipText("Video") #panel.add(b4) b5 = JButton(ImageIcon("/icons/photos.png"), actionPerformed=self.photos) b5.setToolTipText("Photos") panel.add(b5) b6 = JButton(ImageIcon("/icons/calculator.png"), actionPerformed=self.calc) b6.setToolTipText("Calculator") panel.add(b6) b7 = JButton(ImageIcon("/icons/notepad.png"), actionPerformed=self.notepad) b7.setToolTipText("Notepad") panel.add(b7) b8 = JButton(ImageIcon("/icons/settings.png")) b8.setToolTipText("Settings") #panel.add(b8) b9 = JButton(ImageIcon("/icons/trash.png")) b9.setToolTipText("Trash") #panel.add(b9) #panel.setBackground(Color(153, 203, 255)) self.add(panel, BorderLayout.SOUTH) self.getContentPane().add(panel2) #panel2.setBorder(BorderFactory.createEtchedBorder()) #panel2.setLayout(GridLayout(0, 1)) #panel.setLayout(None) #panel2.setBackground(Color(153, 203, 255)) #panel2.add(JLabel(ImageIcon("logo.png"))) #panel2.add(JButton("Icon 0")) #panel2.add(JButton("Icon 1")) #panel2.add(JButton("Icon 2")) #panel2.add(JButton("Icon 3")) #panel2.add(JButton("Icon 4")) #panel2.add(JButton("Icon 5")) #panel2.add(JButton("Icon 6")) #panel2.add(JButton("Icon 7")) #panel2.add(JButton("Icon 8")) #panel2.add(JButton("Icon 9")) self.add(panel2) self.setExtendedState(JFrame.MAXIMIZED_BOTH) self.setUndecorated(True) self.setVisible(True)
def createMenuBar(manager): global menuHandles, isDominant, isTemporal menuHandles = {} menuBar = JMenuBar() fmenu = JMenu("File") menuHandles['File'] = fmenu fmenu.setMnemonic(KeyEvent.VK_F) menuBar.add(fmenu) fmenu.add(createMenuItem('Open Genepop data', "Open", manager)) fmenu.add(createMenuItem('Use Example data', "Example", manager)) fmenu.addSeparator() fmenu.add(createMenuItem('Citation', "Citation", manager)) fmenu.addSeparator() fmenu.add(createMenuItem("Exit", "Exit", manager)) if not isTemporal: pmenu = JMenu("Populations") menuHandles['Populations'] = pmenu pmenu.setEnabled(False) pmenu.setMnemonic(KeyEvent.VK_P) menuBar.add(pmenu) pmenu.add(createMenuItem('Load population names', "LoadPop", manager)) pmenu.add(createMenuItem('Edit population names', "EditPop", manager)) pmenu.add(createMenuItem('Save population names', "SavePop", manager)) umenu = JMenu("Data used") menuHandles['Data used'] = umenu umenu.setEnabled(False) umenu.setMnemonic(KeyEvent.VK_U) menuBar.add(umenu) umenu.add(createMenuItem('Loci Analyzed', "ChooseLoci", manager)) if isTemporal: umenu.add(createMenuItem('Samples Analyzed', "ChoosePops", manager)) else: umenu.add(createMenuItem('Populations Analyzed', "ChoosePops", manager)) if isDominant: fdmenu = JMenu("DFDist") elif isTemporal: fdmenu = JMenu("FTemp") else: fdmenu = JMenu("FDist") menuHandles['FDist'] = fdmenu fdmenu.setEnabled(False) fdmenu.setMnemonic(KeyEvent.VK_D) menuBar.add(fdmenu) if isTemporal: fdmenu.add(createMenuItem('Run FTemp', "RunFDist", manager)) else: fdmenu.add(createMenuItem('Run FDist', "RunFDist", manager)) item5000 = createMenuItem('Run more 5000 sims', "Run5000", manager) item5000.setEnabled(False) menuHandles['item5000'] = item5000 fdmenu.add(item5000) checkLoci = createMenuItem('Check Loci Status', "CheckLoci", manager) checkLoci.setEnabled(False) menuHandles['checkLoci'] = checkLoci fdmenu.add(checkLoci) gmenu = JMenu("Graphic") gmenu.setEnabled(False) menuHandles['Graphic'] = gmenu gmenu.setMnemonic(KeyEvent.VK_G) menuBar.add(gmenu) gmenu.add(createMenuItem('Colors and loci labels', "ConfGrp", manager)) #gmenu.add(createMenuItem('Save Graphic as PNG', "SavePNG", manager)) gmenu.add(createMenuItem('Save as PNG', "SavePNG", manager)) gmenu.add(createMenuItem('Export as PDF', "SavePDF", manager)) gmenu.add(createMenuItem('Export as SVG', "SaveSVG", manager)) menuBar.add(Box.createHorizontalGlue()) hmenu = JMenu("Help") hmenu.setMnemonic(KeyEvent.VK_H) menuBar.add(hmenu) hmenu.add(createMenuItem('Help', "Help", manager)) return menuBar
menuBar = JMenuBar() fileMenu = JMenu("File") fileMenu.add(JLMenuItem("Open Dataset",JyVis.promptUserToOpenDataTable)) fileMenu.add(JLMenuItem("Save Session",JyVis.promptUserToSaveSession)) fileMenu.add(JLMenuItem("Load Session",JyVis.promptUserToReplaySession)) fileMenu.add(JLMenuItem("Export Selection as CSV",JyVis.promptUserToExportSelection)) fileMenu.add(JLMenuItem("Export Image as PNG",JyVis.promptUserToExportImageAsPNG)) fileMenu.addSeparator() fileMenu.add(JLMenuItem("Properties","JyVis.showSystemPropertyPanel()")) #TODO remove this fileMenu.add(JLMenuItem("RTest","JyVis.doRTest()")) menuBar.add(fileMenu) # build the Visualizations menu from the contents of the plugin directory visMenu = JyVis.createMenuForScriptDirectory("run//Visualizations") if(visMenu != None): menuBar.add(visMenu) baseWindow.setJMenuBar(menuBar) baseWindow.setVisible(1)
def make_menubar(self): shortcut = Toolkit.getDefaultToolkit().menuShortcutKeyMask menubar = JMenuBar() def new_item(title, cmd, key, mod=shortcut): item = JMenuItem(title, actionCommand=cmd) item.accelerator = KeyStroke.getKeyStroke(key, mod) item.addActionListener(self) return item filemenu = JMenu("File") menubar.add(filemenu) fm = self.file_manager = FileManager(self) item = new_item("Run Python File...", "load", KeyEvent.VK_L) filemenu.add(item) item = new_item("Run Python File", "reload", KeyEvent.VK_R) item.enabled = False self.reload_menuitem = item filemenu.add(item) filemenu.addSeparator() item = new_item("Open Python Script...", "open", KeyEvent.VK_O) filemenu.add(item) item = new_item("Save Python Script", "save", KeyEvent.VK_S) item.enabled = False self.save_menuitem = item filemenu.add(item) item = new_item("Save Python Script As...", "save_as", KeyEvent.VK_S, mod = shortcut + ActionEvent.SHIFT_MASK) filemenu.add(item) editmenu = JMenu("Edit") menubar.add(editmenu) editmenu.add(new_item("Cut", "cut", KeyEvent.VK_X)) editmenu.add(new_item("Copy", "copy", KeyEvent.VK_C)) editmenu.add(new_item("Paste", "paste", KeyEvent.VK_V)) editmenu.addSeparator() item = new_item("Run Script", "runscript", KeyEvent.VK_E) editmenu.add(item) item = new_item("Run Selection", "runselection", KeyEvent.VK_E, mod=shortcut | ActionEvent.SHIFT_MASK) editmenu.add(item) editmenu.addSeparator() item = new_item("Indent Selection", "indentselection", KeyEvent.VK_CLOSE_BRACKET) editmenu.add(item) item = new_item("Dedent Selection", "dedentselection", KeyEvent.VK_OPEN_BRACKET) editmenu.add(item) shellmenu = JMenu("Interactive") menubar.add(shellmenu) item = new_item("Previous Input", "up", KeyEvent.VK_UP, mod=ActionEvent.ALT_MASK) shellmenu.add(item) item = new_item("Next Input", "down", KeyEvent.VK_DOWN, mod=ActionEvent.ALT_MASK) shellmenu.add(item) self.frame.setJMenuBar(menubar)
fileMenu = JMenu("File") fileMenu.add(JLMenuItem("Open Dataset", JyVis.promptUserToOpenDataTable)) fileMenu.add(JLMenuItem("Save Session", JyVis.promptUserToSaveSession)) fileMenu.add(JLMenuItem("Load Session", JyVis.promptUserToReplaySession)) fileMenu.add( JLMenuItem("Export Selection as CSV", JyVis.promptUserToExportSelection)) fileMenu.add( JLMenuItem("Export Image as PNG", JyVis.promptUserToExportImageAsPNG)) fileMenu.addSeparator() fileMenu.add(JLMenuItem("Properties", "JyVis.showSystemPropertyPanel()")) #TODO remove this fileMenu.add(JLMenuItem("RTest", "JyVis.doRTest()")) menuBar.add(fileMenu) # build the Visualizations menu from the contents of the plugin directory visMenu = JyVis.createMenuForScriptDirectory("run//Visualizations") if (visMenu != None): menuBar.add(visMenu) baseWindow.setJMenuBar(menuBar) baseWindow.setVisible(1)
def __init__(self, windowManager, commandConsoleFactory, subject, windowTitle): self._windowManager = windowManager self.onCloseRequestListener = None # EDIT MENU transferActionListener = _TransferActionListener() editMenu = JMenu( 'Edit' ) if Platform.getPlatform() is Platform.MAC: command_key_mask = ActionEvent.META_MASK else: command_key_mask = ActionEvent.CTRL_MASK; self.__editUndoItem = JMenuItem( 'Undo' ) undoAction = _action( 'undo', self.__onUndo ) self.__editUndoItem.setActionCommand( undoAction.getValue( Action.NAME ) ) self.__editUndoItem.addActionListener( undoAction ) self.__editUndoItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_Z, command_key_mask ) ) self.__editUndoItem.setMnemonic( KeyEvent.VK_U ) editMenu.add( self.__editUndoItem ) self.__editRedoItem = JMenuItem( 'Redo' ) redoAction = _action( 'redo', self.__onRedo ) self.__editRedoItem.setActionCommand( redoAction.getValue( Action.NAME ) ) self.__editRedoItem.addActionListener( redoAction ) self.__editRedoItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_Y, command_key_mask ) ) self.__editRedoItem.setMnemonic( KeyEvent.VK_R ) editMenu.add( self.__editRedoItem ) editMenu.addSeparator() editCutItem = JMenuItem( 'Cut' ) editCutItem.setActionCommand( TransferHandler.getCutAction().getValue( Action.NAME ) ) editCutItem.addActionListener( transferActionListener ) editCutItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_X, command_key_mask ) ) editCutItem.setMnemonic( KeyEvent.VK_T ) editMenu.add( editCutItem ) editCopyItem = JMenuItem( 'Copy' ) editCopyItem.setActionCommand( TransferHandler.getCopyAction().getValue( Action.NAME ) ) editCopyItem.addActionListener( transferActionListener ) editCopyItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_C, command_key_mask ) ) editCopyItem.setMnemonic( KeyEvent.VK_C ) editMenu.add( editCopyItem ) editPasteItem = JMenuItem( 'Paste' ) editPasteItem.setActionCommand( TransferHandler.getPasteAction().getValue( Action.NAME ) ) editPasteItem.addActionListener( transferActionListener ) editPasteItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_V, command_key_mask ) ) editPasteItem.setMnemonic( KeyEvent.VK_P ) editMenu.add( editPasteItem ) editMenu.addSeparator() self.__showUndoHistoryItem = JMenuItem( 'Show undo history' ) self.__showUndoHistoryItem.addActionListener( _action( 'Show undo history', self.__onShowUndoHistory ) ) editMenu.add( self.__showUndoHistoryItem ) # HELP MENU helpMenu = JMenu( 'Help' ) helpToggleTooltipHighlightsItem = JMenuItem( 'Toggle tooltip highlights' ) toggleTooltipHighlightsAction = _action( 'Toggle tooltip highlights', self.__onToggleTooltipHighlights ) helpToggleTooltipHighlightsItem.setActionCommand( toggleTooltipHighlightsAction.getValue( Action.NAME ) ) helpToggleTooltipHighlightsItem.addActionListener( toggleTooltipHighlightsAction ) helpToggleTooltipHighlightsItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_F2, 0 ) ) helpMenu.add( helpToggleTooltipHighlightsItem ) helpMenu.add( _action( 'Show all tip boxes', self.__onShowAllTipBoxes ) ) # MENU BAR menuBar = JMenuBar() menuBar.add( editMenu ) menuBar.add( helpMenu ) # BROWSER # Initialise here, as the browser listener may invoke methods upon the browser's creation class _BrowserListener (TabbedBrowser.TabbedBrowserListener): def createNewBrowserWindow(_self, subject): self._onOpenNewWindow( subject ) def onTabbledBrowserChangePage(_self, browser): pass def inspectFragment(fragment, sourceElement, triggeringEvent): return self._windowManager.world.inspectFragment( fragment, sourceElement, triggeringEvent ) def onChangeHistoryChanged(history): self.__refreshChangeHistoryControls( history ) self._browser = TabbedBrowser( self._windowManager.world.rootSubject, subject, inspectFragment, _BrowserListener(), commandConsoleFactory ) self._browser.getComponent().setPreferredSize( Dimension( 800, 600 ) ) changeHistory = self._browser.getChangeHistory() self._browser.getChangeHistory().addChangeHistoryListener(onChangeHistoryChanged) # MAIN PANEL windowPanel = JPanel() windowPanel.setLayout( BoxLayout( windowPanel, BoxLayout.Y_AXIS ) ) windowPanel.add( self._browser.getComponent() ) # WINDOW class _WindowLister (WindowListener): def windowActivated(listenerSelf, event): pass def windowClosed(listenerSelf, event): pass def windowClosing(listenerSelf, event): if self.onCloseRequestListener is not None: self.onCloseRequestListener( self ) def windowDeactivated(listenerSelf, event): pass def windowDeiconified(listenerSelf, event): pass def windowIconified(listenerSelf, event): pass def windowOpened(listenerSelf, event): pass self.__frame = JFrame( windowTitle ) self.__frame.setJMenuBar( menuBar ) self.__frame.add( windowPanel ) self.__frame.addWindowListener( _WindowLister() ) self.__frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ) self.__frame.pack() # Cause command history controls to refresh self.__refreshChangeHistoryControls( None )
def run(scene, w=512, h=512, aa=1, threads=1): '''Create GUI and perform ray-tracing.''' #Make Swing not look like garbage (so much) UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()) #Setup frame frame = JFrame( "RayTracer", defaultCloseOperation=JFrame.EXIT_ON_CLOSE, size=(w, h) ) frame.setIconImage(ImageIcon('resources/icon.png').getImage()) canvas = RayTracePanel(w, h, aa, threads) frame.getContentPane().add(JScrollPane(canvas)) #Save FileChooser fcS = JFileChooser() fcS.addChoosableFileFilter(FileNameExtensionFilter('Windows Bitmap (*.bmp)', ['bmp'])) fcS.addChoosableFileFilter(FileNameExtensionFilter('JPEG / JFIF (*.jpg)', ['jpg'])) fcS.addChoosableFileFilter(FileNameExtensionFilter('Portable Network Graphics (*.png)', ['png'])) def saveFile(event): '''Performed when the save button is pressed''' result = fcS.showSaveDialog(frame) if result == JFileChooser.APPROVE_OPTION: file = fcS.getSelectedFile() fname = file.getPath() ext = fcS.getFileFilter().getExtensions()[0] if not fname.endswith('.' + ext): file = File(fname + '.' + ext) canvas.saveToFile(file, ext) #Open FileChooser fcO = JFileChooser() fcO.addChoosableFileFilter(FileNameExtensionFilter('RayTrace Scene File (*.rts)', ['rts'])) def openFile(event): '''Performed when the open button is pressed''' result = fcO.showOpenDialog(frame) if result == JFileChooser.APPROVE_OPTION: fname = fcO.getSelectedFile().getPath() if fname.endswith('.rts'): f = open(fname, 'rb') newScene = SceneFactory().buildScene(f) f.close() Painter(canvas, newScene, openButton, saveButton).start() def exit(event): '''Performed when the exit button is pressed''' import sys sys.exit(0) #Setup Menu menuBar = JMenuBar() menu = JMenu("File") menuBar.add(menu) openButton = JMenuItem("Open...", actionPerformed=openFile) openButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)) menu.add(openButton) saveButton = JMenuItem("Save as...", actionPerformed=saveFile) saveButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)) menu.add(saveButton) menu.addSeparator() closeButton = JMenuItem('Close', actionPerformed=exit) closeButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK)) menu.add(closeButton) frame.setJMenuBar(menuBar) #Finish initializing GUI frame.pack() #frame.setLocationRelativeTo(None) frame.setVisible(True) #Perform ray-tracing if scene is not None: Thread(Painter(canvas, scene, openButton, saveButton)).start()
def run(scene, w=512, h=512, aa=1, threads=1): """Create GUI and perform ray-tracing.""" # Make Swing not look like garbage (so much) UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()) # Setup frame frame = JFrame("RayTracer", defaultCloseOperation=JFrame.EXIT_ON_CLOSE, size=(w, h)) frame.setIconImage(ImageIcon("resources/icon.png").getImage()) canvas = RayTracePanel(w, h, aa, threads) frame.getContentPane().add(JScrollPane(canvas)) # Save FileChooser fcS = JFileChooser() fcS.addChoosableFileFilter(FileNameExtensionFilter("Windows Bitmap (*.bmp)", ["bmp"])) fcS.addChoosableFileFilter(FileNameExtensionFilter("JPEG / JFIF (*.jpg)", ["jpg"])) fcS.addChoosableFileFilter(FileNameExtensionFilter("Portable Network Graphics (*.png)", ["png"])) def saveFile(event): """Performed when the save button is pressed""" result = fcS.showSaveDialog(frame) if result == JFileChooser.APPROVE_OPTION: file = fcS.getSelectedFile() fname = file.getPath() ext = fcS.getFileFilter().getExtensions()[0] if not fname.endswith("." + ext): file = File(fname + "." + ext) canvas.saveToFile(file, ext) # Open FileChooser fcO = JFileChooser() fcO.addChoosableFileFilter(FileNameExtensionFilter("RayTrace Scene File (*.rts)", ["rts"])) def openFile(event): """Performed when the open button is pressed""" result = fcO.showOpenDialog(frame) if result == JFileChooser.APPROVE_OPTION: fname = fcO.getSelectedFile().getPath() if fname.endswith(".rts"): f = open(fname, "rb") newScene = SceneFactory().buildScene(f) f.close() Painter(canvas, newScene, openButton, saveButton, stopButton).start() def exit(event): """Performed when the exit button is pressed""" import sys sys.exit(0) def stop(event): """Peformed when the stop button is pressed""" canvas.stopRendering() # Setup Menu menuBar = JMenuBar() menu = JMenu("File") menuBar.add(menu) openButton = JMenuItem("Open...", actionPerformed=openFile) openButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)) menu.add(openButton) saveButton = JMenuItem("Save as...", actionPerformed=saveFile) saveButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)) menu.add(saveButton) menu.addSeparator() stopButton = JMenuItem("Stop Render", actionPerformed=stop) stopButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)) stopButton.setEnabled(False) menu.add(stopButton) menu.addSeparator() closeButton = JMenuItem("Close", actionPerformed=exit) closeButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK)) menu.add(closeButton) frame.setJMenuBar(menuBar) # Finish initializing GUI self.pack()
def __init__(self, repository): self.repository = repository # want a better solution, with domains, perhaps user specifies self.currentUserReference = System.getProperty("user.name") self.currentRecord = None self.window = JFrame("Pointrel browser", windowClosing=self.exit) self.window.contentPane.layout = BorderLayout() # redundant as the default self.window.bounds = (100, 100, 800, 600) self.menuBar = JMenuBar() self.window.JMenuBar = self.menuBar fileMenu = JMenu("File") fileMenu.add(JMenuItem("Open...", actionPerformed=self.open)) fileMenu.add(JMenuItem("Reload", actionPerformed=self.reloadPressed)) fileMenu.addSeparator() fileMenu.add(JMenuItem("Import from other repository...", actionPerformed=self.importFromOtherRepository)) fileMenu.addSeparator() fileMenu.add(JMenuItem("Close", actionPerformed=self.close)) self.menuBar.add(fileMenu) exportMenu = JMenu("Export") exportMenu.add(JMenuItem("Choose current export file...", actionPerformed=self.exportChooseCurrentFile)) exportMenu.addSeparator() exportMenu.add(JMenuItem("Export selected record", actionPerformed=self.exportSelectedRecord)) exportMenu.add(JMenuItem("Export record history for selected attribute", actionPerformed=self.exportAllRecordsForSelectedAttribute)) exportMenu.addSeparator() exportMenu.add(JMenuItem("Export current records for all attributes of selected entity", actionPerformed=self.exportLatestRecordsForSelectedEntity)) exportMenu.add(JMenuItem("Export entire record history for all attributes of selected entity", actionPerformed=self.exportAllRecordsForSelectedEntity)) self.menuBar.add(exportMenu) self.exportFileName = "export.pointrel" #self.reloadButton = JButton("Reload Repository", actionPerformed=self.reloadPressed) self.entitiesList = JList(DefaultListModel(), mouseClicked=self.entitiesListClicked) self.entitiesList.model.addElement("root") self.entitiesList.mousePressed = self.entitiesListMousePressed self.entitiesList.mouseReleased = self.entitiesListMousePressed self.attributesList = JList(DefaultListModel(), mouseClicked=self.attributesListClicked) self.versionsList = JList(DefaultListModel(), mouseClicked=self.versionsListClicked) self.listPanel = JPanel(layout=GridLayout(1, 2)) self.listPanel.add(JScrollPane(self.entitiesList)) self.listPanel.add(JScrollPane(self.attributesList)) self.listPanel.add(JScrollPane(self.versionsList)) self.navigationPanel = JPanel(layout=BorderLayout()) #self.navigationPanel.add(self.reloadButton, BorderLayout.NORTH) self.navigationPanel.add(self.listPanel, BorderLayout.CENTER) self.entityTextField = JTextField(preferredSize=(200,20)) self.attributeTextField = JTextField(preferredSize=(200,20)) self.deletedButton = JCheckBox("Deleted", actionPerformed=self.deletedPressed) # only one right now -- and no support for switching editor panels yet examples = ["pointrel:text/utf-8", ] self.valueTypeComboBox = JComboBox(examples, preferredSize=(200,20), editable=True) self.attributePanel = Box(BoxLayout.X_AXIS) self.attributePanel.add(Box.createRigidArea(Dimension(5,0))) self.attributePanel.add(JLabel("Entity:")) self.attributePanel.add(Box.createRigidArea(Dimension(2,0))) self.attributePanel.add(self.entityTextField) self.attributePanel.add(Box.createRigidArea(Dimension(5,0))) self.attributePanel.add(JLabel("Attribute:")) self.attributePanel.add(Box.createRigidArea(Dimension(2,0))) self.attributePanel.add(self.attributeTextField) self.attributePanel.add(Box.createRigidArea(Dimension(5,0))) self.attributePanel.add(JLabel("Value type:")) self.attributePanel.add(Box.createRigidArea(Dimension(2,0))) self.attributePanel.add(self.valueTypeComboBox) self.attributePanel.add(Box.createRigidArea(Dimension(5,0))) self.attributePanel.add(self.deletedButton) self.attributePanel.add(Box.createRigidArea(Dimension(5,0))) self.showAllDeletedButton = JCheckBox("Show all deleted", actionPerformed=self.showAllDeletedPressed) self.statusText = JTextField(preferredSize=(100,20)) self.saveButton = JButton("Save", actionPerformed=self.savePressed) self.normalSaveButtonColor = self.saveButton.background self.changedSaveButtonColor = Color.YELLOW self.statusPanel = Box(BoxLayout.X_AXIS) self.statusPanel.add(Box.createRigidArea(Dimension(5,0))) self.statusPanel.add(self.showAllDeletedButton) self.statusPanel.add(Box.createRigidArea(Dimension(25,0))) self.statusPanel.add(JLabel("Message:") ) self.statusPanel.add(Box.createRigidArea(Dimension(2,0))) self.statusPanel.add(self.statusText) self.statusPanel.add(Box.createRigidArea(Dimension(5,0))) self.statusPanel.add(self.saveButton) self.statusPanel.add(Box.createRigidArea(Dimension(1,0))) self.currentEditorPanel = EditorPanel_text_utf_8(self, "pointrel:text/utf-8") self.topPanel = Box(BoxLayout.Y_AXIS) self.topPanel.add(Box.createRigidArea(Dimension(0,5))) self.topPanel.add(self.attributePanel) self.topPanel.add(Box.createRigidArea(Dimension(0,5))) self.editorPanel = JPanel(layout=BorderLayout()) self.editorPanel.add(self.topPanel, BorderLayout.NORTH) self.editorPanel.add(self.currentEditorPanel, BorderLayout.CENTER) self.editorPanel.add(self.statusPanel, BorderLayout.SOUTH) self.browserPanel = JSplitPane(JSplitPane.VERTICAL_SPLIT) self.browserPanel.add(self.navigationPanel) self.browserPanel.add(self.editorPanel) self.window.contentPane.add(self.browserPanel, BorderLayout.CENTER) self.setTitleForRepository() self.window.show() # background timer for updating save button color self.timer = Timer(1000, CallbackActionListener(self.timerEvent)) self.timer.initialDelay = 1000 self.timer.start()
def run(scene, w=512, h=512, aa=1, threads=1): '''Create GUI and perform ray-tracing.''' #Make Swing not look like garbage (so much) UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()) #Setup frame frame = JFrame("RayTracer", defaultCloseOperation=JFrame.EXIT_ON_CLOSE, size=(w, h)) frame.setIconImage(ImageIcon('resources/icon.png').getImage()) canvas = RayTracePanel(w, h, aa, threads) frame.getContentPane().add(JScrollPane(canvas)) #Save FileChooser fcS = JFileChooser() fcS.addChoosableFileFilter( FileNameExtensionFilter('Windows Bitmap (*.bmp)', ['bmp'])) fcS.addChoosableFileFilter( FileNameExtensionFilter('JPEG / JFIF (*.jpg)', ['jpg'])) fcS.addChoosableFileFilter( FileNameExtensionFilter('Portable Network Graphics (*.png)', ['png'])) def saveFile(event): '''Performed when the save button is pressed''' result = fcS.showSaveDialog(frame) if result == JFileChooser.APPROVE_OPTION: file = fcS.getSelectedFile() fname = file.getPath() ext = fcS.getFileFilter().getExtensions()[0] if not fname.endswith('.' + ext): file = File(fname + '.' + ext) canvas.saveToFile(file, ext) #Open FileChooser fcO = JFileChooser() fcO.addChoosableFileFilter( FileNameExtensionFilter('RayTrace Scene File (*.rts)', ['rts'])) def openFile(event): '''Performed when the open button is pressed''' result = fcO.showOpenDialog(frame) if result == JFileChooser.APPROVE_OPTION: fname = fcO.getSelectedFile().getPath() if fname.endswith('.rts'): f = open(fname, 'rb') newScene = SceneFactory().buildScene(f) f.close() Painter(canvas, newScene, openButton, saveButton).start() def exit(event): '''Performed when the exit button is pressed''' import sys sys.exit(0) #Setup Menu menuBar = JMenuBar() menu = JMenu("File") menuBar.add(menu) openButton = JMenuItem("Open...", actionPerformed=openFile) openButton.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)) menu.add(openButton) saveButton = JMenuItem("Save as...", actionPerformed=saveFile) saveButton.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)) menu.add(saveButton) menu.addSeparator() closeButton = JMenuItem('Close', actionPerformed=exit) closeButton.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK)) menu.add(closeButton) frame.setJMenuBar(menuBar) #Finish initializing GUI frame.pack() #frame.setLocationRelativeTo(None) frame.setVisible(True) #Perform ray-tracing if scene is not None: Thread(Painter(canvas, scene, openButton, saveButton)).start()