def SetIcon(self,icon,size=None,top=False): from javafx.scene.control import ContentDisplay; if os.path.isfile(icon): iv = ImageView(Image(FileInputStream(icon))) if size: iv.setFitHeight(size); iv.setFitWidth(size) self.ctrl.setGraphic(iv) if top: self.ctrl.setContentDisplay(ContentDisplay.TOP)
def __init__(self,h,parent): if h.get('file'): self.ctrl = ImageView(Image(File(h['file']).toURI().toString())) else: self.ctrl = ImageView() self.ctrl.setPreserveRatio(True); if h.get('fitwidth'): self.ctrl.setFitWidth(h['fitwidth']) if h.get('fitheight'): self.ctrl.setFitHeight(h['fitheight']) if h.get('bindwidth'): self.ctrl.fitWidthProperty().bind(parent.widthProperty()) if h.get('bindheight'): self.ctrl.fitHeightProperty().bind(parent.heightProperty()) self.Initialize(h) if h.get('handler'): self.ctrl.setOnAction(h['handler'])
def start(self, stage): from javafx.application import Platform self.ctrl = _window__ctrl_table self.stage = stage self.stage.setTitle("FxApp Example") if self.title: self.stage.setTitle(self.title) if self.icon: self.stage.getIcons().add(Image(FileInputStream(self.icon))) if self.closeHandler: self.stage.setOnCloseRequest(self.closeHandler) Platform.setImplicitExit(True) pane = EzBorderPane(self) self.scene = Scene(pane.ctrl, 640, 400) self.stage.setScene(self.scene) if self.createdHandler: self.createdHandler() self.stage.show()
def start(self, stage): print('EzWindow.start()'); from javafx.application import Platform __vars.ctrl = _window__ctrl_table __vars.stage = stage if __vars.title: __vars.stage.setTitle(__vars.title) if __vars.icon: __vars.stage.getIcons().add(Image(FileInputStream(__vars.icon))) if __vars.closeHandler: __vars.stage.setOnCloseRequest(__vars.closeHandler) Platform.setImplicitExit(True) vbox = EzVBox() if __vars.menu: vbox.addItem(EzMenuBar(__vars.menu)) for m in __vars.tool: vbox.addItem(EzToolBar(m)) pane = EzBorderPane() if __vars.content: pane.setCenter(EzLayout(__vars.content,pane.ctrl)) pane.setTop(vbox.ctrl) pane.setBottom(EzStatusBar(__vars.status)) __vars.scene = Scene(pane.ctrl, __vars.width, __vars.height) __vars.stage.setScene(__vars.scene) if __vars.createdHandler: __vars.createdHandler() __vars.stage.show()
def SetIcon(self,icon,top=False): from javafx.scene.control import ContentDisplay; self.ctrl.setGraphic(ImageView(Image(FileInputStream(icon)))) if top: self.ctrl.setContentDisplay(ContentDisplay.TOP)
def show(self): from javafx.scene.control import CheckBox, Button #Make Stage always on top self.license_check_stage.setAlwaysOnTop(True) #Set Max Height/Width self.license_check_stage.setMaxWidth(900) self.license_check_stage.setMaxHeight(500) #Disallow resizing self.license_check_stage.setResizable(False) #Center on screen self.license_check_stage.centerOnScreen() #Get input focus self.license_check_stage.requestFocus() #Block Main Stage from recieving events! self.license_check_stage.initModality( Modality.APPLICATION_MODAL ) #Why is this not in setter bean notation? Hmm. #License Check self.license_check_stage.setTitle( "License Terms & Conditions - EmeraldFX") #License Answer Placeholder license_answer = str() #Buttons yes = CheckBox() no = CheckBox() enter = Button() #Grab, icon, graphics, button graphics try: self.license_check_stage.getIcons().addAll(self.icons.get(0), self.icons.get(1), self.icons.get(2), self.icons.get(3), self.icons.get(4)) license_graphic = ImageView( Image( String( File('../resources/icons/license.png').toURI(). toString()), True)) yes.setGraphic( ImageView( Image( String( File('../resources/icons/YES.png').toURI(). toString()), True))) no.setGraphic( ImageView( Image( String( File('../resources/icons/NO.png').toURI().toString( )), True))) enter.setGraphic( ImageView( Image( String( File('../resources/icons/GO.png').toURI().toString( )), True))) except NullPointerException: print( "Log: One or more Application resouce files could not be found." ) #Disallow Indeterminate yes.setAllowIndeterminate(False) no.setAllowIndeterminate(False) #Header if self.app.getCurrentTheme() == "Dark": top = ImageView( Image( File('../resources/icons/top_bar_license_dt.png').toURI(). toString())) elif self.app.getCurrentTheme() == "Light": top = ImageView( Image( File('../resources/icons/top_bar_license_lt.png').toURI(). toString())) #Middle middle = HBox(15) #Set up WebEngine license_webView = WebView() webEng = license_webView.getEngine() webEng.load(self.app._EmeraldFX__LICENSE) #License Image license_logo = VBox() license_logo.getChildren().add( ImageView( Image( String( File('../resources/icons/license.png').toURI(). toString()), True))) license_logo.setAlignment(Pos.CENTER) #Put it all together middle.getChildren().addAll(license_logo, license_webView) middle.setPadding(Insets(0, 10, 0, 10)) #CheckBox Grouping bottom = HBox() bottom.getChildren().addAll(yes, no, enter) bottom.setSpacing(50) bottom.setPadding(Insets(0, 0, 0, 200)) #Set Theme Accordingly try: if self.app.getCurrentTheme() == "Dark": BKG = File( '../resources/icons/bottom_bar_dt.png').toURI().toString() elif self.app.getCurrentTheme() == "Light": BKG = File( '../resources/icons/bottom_bar_lt.png').toURI().toString() else: pass except NullPointerException: print( "Log: One or more Application resouce files could not be found." ) #Footer background_bottom = Background( array(BackgroundImage, [ BackgroundImage(Image(BKG), BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT, BackgroundSize.DEFAULT) ])) bottom.setBackground(background_bottom) bottom.setAlignment(Pos.CENTER) bottom.setPrefHeight(15) #Root Pane license_check_stage_root = VBox() license_check_stage_root.getChildren().addAll(top, middle, bottom) #Scene license_check_scene = Scene(license_check_stage_root, 895, 498) #Shortcuts not available for this scene. We will use defaults, for now. #Set Scene on Stage self.license_check_stage.setScene(license_check_scene) #Handle Selection class AnonInnerCL_E(EventHandler): def __init__(self, outer, yes, no): self.outer = outer self.app = outer.app self.BS = outer.BS self.YES = yes self.NO = no self.license_check_stage_json = self.app._EmeraldFX__config #@Override def handle(self, action): if (yes.isSelected()) ^ (no.isSelected()): if self.app._EmeraldFX__LICENSE_ACCEPTANCE == "YES": #We're done here self.outer.license_check_stage.close() #Update properties.json self.license_check_stage_json['license'][ 'value'] = "YES" #Write Data, close stream with open("../resources/config/properties.json", "w") as prop: json.dump(self.license_check_stage_json, prop) else: # checked == "NO": BrowserSession.closeHistoryWriter(self.BS) Thread.sleep(300) Platform.exit() class AnonInnerCL_Y(EventHandler): def __init__(self, YES, NO, ENTER, app): self.YES = YES self.NO = NO self.ENTER = ENTER self.app = app #@Override def handle(self, action): if self.YES.isSelected(): self.NO.setSelected(False) self.ENTER.setDisabled( False) if self.ENTER.isDisabled() else None self.app._EmeraldFX__LICENSE_ACCEPTANCE = "YES" elif not self.YES.isSelected() and not self.NO.isSelected(): self.ENTER.setDisabled(True) class AnonInnerCL_N(EventHandler): def __init__(self, NO, YES, ENTER, app): self.NO = NO self.YES = YES self.ENTER = ENTER self.app = app #@Override def handle(self, action): if self.NO.isSelected(): self.YES.setSelected(False) self.ENTER.setDisabled( False) if self.ENTER.isDisabled() else None self.app._EmeraldFX__LICENSE_ACCEPTANCE = "NO" elif not self.NO.isSelected() and not self.YES.isSelected(): self.ENTER.setDisabled(True) #Disable Enter by Default enter.setDisabled(True) #Enter hit enter.setOnAction(AnonInnerCL_E(self, yes, no)) #Yes Checked yes.setOnAction(AnonInnerCL_Y(yes, no, enter, self.app)) #No Checked no.setOnAction(AnonInnerCL_N(no, yes, enter, self.app)) #If they enter no selection, exit self.license_check_stage.setOnCloseRequest( lambda event: [BrowserSession.closeHistoryWriter(self.BS), Platform.exit()]) #Display stage self.license_check_stage.show()
def show(self): #Root Pane root = VBox() #FXML Loader fxmlLoader = FXMLLoader() #TextArea from javafx.scene.control import TextArea textArea = TextArea("Loading . . .") #Configure Text Area textArea.setEditable(False) textArea.setPrefHeight(600) #Bottom Bar, Current Stylesheet if self.app.getCurrentTheme() == "Dark": fxmlLoader.setLocation( File("../resources/fxml/history_url_tab_dark.fxml").toURI(). toURL()) #For some odd reason this is broken? bottom_bar = self.app.bottom_bar_dt elif self.app.getCurrentTheme() == "Light": fxmlLoader.setLocation( File("../resources/fxml/history_url_tab_light.fxml").toURI(). toURL()) bottom_bar = ImageView( Image( String( File('../resources/icons/bottom_bar_lt.png').toURI(). toString()), True)) #Think about future themes else: pass #URL Bar try: url_bar = fxmlLoader.load( ) #BROKEN - For some reason this breaks after a couple toggles. except LoadException as e: print('Log: Exception: An FXML Load Exception has occured.' + str(e.getCause())) #Add Children to root pane root.getChildren().addAll(url_bar, textArea, bottom_bar) #Fill Width, assume Theme of Main Stage root.setFillWidth(True) #Set scene, title scene = Scene(root, 1350, 625) #We are leaving the default controls for now. #Make sure the Text Area's scroll bar is always visible. scene.getStylesheets().add( File("../resources/themes/text-area_scroll-pane.css").toURI(). toString()) self.stage.setScene(scene) self.stage.setTitle("History - EmeraldFX") #Position History Stage self.stage.setX(self.app.getMainStage().getX()) self.stage.setY(self.app.getMainStage().getY() + 52) #Display History Stage self.stage.show() #It is CSV, let us display as plain text. history_csv = File("../resources/history/HISTORY.csv") history_txt = File("../resources/history/HISTORY.txt") #Delete text copy if it exists history_txt.delete() if history_txt.exists() else None #Copy Files.copy(history_csv.toPath(), history_txt.toPath()) #Prevent Resizing self.stage.setResizable(False) #Flush Stream self.BS.triggerHistoryWrite() #GetController instance controller = fxmlLoader.getController() ''' Failed Attempts ''' #WebView # webView = WebView() #Grab Web Engine # webEng = webView.getEngine() #Enable JS # webEng.setJavaScriptEnabled(True) #Attempt #1 - Start scrolling from the bottom - FAILED # webEng.executeScript("window.scrollTo(" + "0" + ", " + "600" + ");") #Attempt #2 - Scroll Pane - FAILED # from javafx.scene.control import ScrollPane # wv_scroll = ScrollPane() # wv_scroll.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS) # wv_scroll.setContent(webView) # wv_scroll.setFitToWidth(True) # wv_scroll.setFitToHeight(True) # wv_scroll.setVvalue(wv_scroll.getVmin()) #Load History # try: # webEng.load(history_txt.toURI().toString()) # except Exception as e: # print ('Log: Load Exception: Error Loading History: ' + str(e.getCause())) # return #Attempt #3 - Execute Script for Scroll Bar - FAILD # webEng.executeScript( # "function scrollDown() { window.scrollTo(0,400); }" + # "scrollDown();" # ) #Set Position of Scroll Bar class AnonInnerCL_TA(ChangeListener): """Inner Class for Scrolling Down""" def __init__(self, textArea): self.textArea = textArea #@Override def changed(self, observable, old, new): if new > old: from java.lang import Double self.textArea.setScrollTop(Double.MAX_VALUE) else: pass textArea.textProperty().addListener(AnonInnerCL_TA(textArea)) #Show History after it is loaded if self.stage.isShowing( ): #May or may not be broken. If there is litle to no delay, "Loading . . ." will not be noticed. #Load History on separate thread. #Clear initial text: Loading . . . textArea.clear() #Instantate Service service = HistoryService(history_txt, textArea) #Algorithm improved. Start service service.start() '''Add resources to controller''' #Theme Resources controller.addThemeResources( self.app.getMainStage(), self.stage, self.app.getMainStage().getScene(), self.app.getCurrentTheme(), textArea ) #(Stage mainStage, Stage histStage, Scene scene, String theme, TextArea textArea) #Clear Resource controller.addClearResources(self.BS.isHistoryCleared()) #(boolean) #Quit Resources controller.addQuitResources( self.app.getAllStages(), self.BS.getHistoryWriter()) #(List<Stages>, PrintWriter) #Media Resources MMC = self.app.getMediaControls() controller.addMediaResources(MMC) #Create Bidirectional Bindings between Main Stage's media controls and history's controls from javafx.beans.binding import Bindings MMC_IT = MMC.listIterator() HMC = controller.getMediaControls() #Set history media controls to current state class HMCC(Consumer): def __init__(self, MMC_IT): self.MMC_IT = MMC_IT #@Override def accept(self, button): button.setDisabled(MMC_IT.next().isDisabled()) HMC.forEach(HMCC(MMC_IT)) #Fails - first arg cannot be coerced into Consumer? Odd. # history_media_controls.forEach(lambda button: button.setDisabled( main_media_controls.forEach(lambda button: button.isDisabled()) ) ) #Play #Won't work -- read only property does not inherit Property, seperate API. # Bindings.bindBidirectional(history_media_controls.get(0).disabledProperty(), main_media_controls[0].disabledProperty() ) #Stop # Bindings.bindBidirectional(history_media_controls.get(1).disabledProperty(), main_media_controls[1].disabledProperty() ) #Previous # Bindings.bindBidirectional(history_media_controls.get(2).disabledProperty(), main_media_controls[2].disabledProperty() ) #Next # Bindings.bindBidirectional(history_media_controls.get(3).disabledProperty(), main_media_controls[3].disabledProperty() ) #Shortcut Keys Allowed for History (CTRL + D, CTRL + Q, CTRL + T) scene.addEventFilter( KeyEvent.KEY_PRESSED, lambda event: self.handleHistoryShortcuts( event, self.BS, controller.getToggleTheme(), controller.getClearHistory())) #Python needs to fix lambdas so we don't have to resort to wrapping inner classes in collections. Yuck. class HistoryClosed: @staticmethod def printClosed(): print("Log: Quit Action: History just closed.") #Switch back to the main stage self.stage.setOnCloseRequest(lambda event: [ self.app.getMainStage().toFront(), self.stage.close(), HistoryClosed.printClosed() ]) #Log print('Log: History Notification: History data displayed @ ' + str(LocalDateTime.now()))