Exemplo n.º 1
0
 def __init__(self,gap=0,pad=0):
     self.ctrl = HBox( gap )
     self.setExpand = lambda x : HBox.setHgrow(x, Priority.ALWAYS)
     self.setAlignLeft = lambda : self.ctrl.setAlignment(Pos.CENTER_LEFT)
     self.setAlignRight = lambda : self.ctrl.setAlignment(Pos.CENTER_RIGHT)
     self.separatorOrientation = Orientation.VERTICAL
     self.ctrl.setAlignment(Pos.CENTER)
     self.ctrl.setSpacing( gap )
     self.ctrl.setPadding( Insets( pad, pad, pad, pad ) )
Exemplo n.º 2
0
def FxLayout(content,parent):
    from javafx.scene.control import Tooltip
    from javafx.scene.layout import Region     
    vbox = FxVBox(1,1)
    for v in content:
        hbox = FxHBox(1,1)
        expand = False
        for h in v:
            name = h.get('name')
            if not name:
                if h.get('expand'): expand = h['expand']
                continue
            if name == '<>' or name == 'Spacer':
                space = Region()
                HBox.setHgrow(space, Priority.ALWAYS)
                hbox.addItem(space)
                continue
            elif name == 'Label': f = FxLabel(h)
            elif name == 'ImageView': f = FxImageView(h,parent)
            elif name == 'ScrollImageView': f = FxScrollImageView(h,parent)
            elif name == 'Button': f = FxButton(h)
            elif name == 'ToggleButton': f = FxToggleButton(h)
            elif name == 'CheckBox': f = FxCheckBox(h)
            elif name == 'TextField': f = FxTextField(h)
            elif name == 'TextArea': f = FxTextArea(h)
            elif name == 'ChoiceBox': f = FxChoiceBox(h)
            elif name == 'ComboBox': f = FxComboBox(h)
            elif name == 'ListBox': f = FxListView(h)
            elif name == 'TreeView': f = FxTreeView(h)
            elif name == 'TableView': f = FxTableView(h)
            elif name == 'ProgressBar': f = FxProgressBar(h)
            elif name == 'TabPane': f = FxTabPane(h)
            elif name == 'HSplit': f = FxHSplitPane(h)
            elif name == 'VSplit': f = FxVSplitPane(h)
            else: continue
            hbox.addItem(f.ctrl,expand=h.get('expand'))
        vbox.addItem(hbox.ctrl,expand=expand)
    return vbox.ctrl
Exemplo n.º 3
0
def EzStatusBar(statusbar_table):
    from javafx.scene.control import Separator     
    from javafx.scene.layout import Region     
    hbox = EzHBox(1,1);
    for h in statusbar_table:
        if not h.get('name'): continue
        if h['name'] == '--' or h['name'] == '--': hbox.addItem(Separator()); continue
        if h['name'] == '<>':
            space = Region(); HBox.setHgrow(space, Priority.ALWAYS)
            hbox.addItem(space)
            continue
        name = h['name'] 
        if   name == 'Label': f = EzLabel(h)
        elif name == 'Button': f = EzButton(h)
        elif name == 'CheckBox': f = EzCheckBox(h)
        elif name == 'ChoiceBox': f = EzChoiceBox(h)
        elif name == 'ComboBox': f = EzComboBox(h)
        elif name == 'ProgressBar': f = EzProgressBar(h)
        elif name == 'ToggleButton': f = EzToggleButton(h)
        elif name == 'TextField': f = EzTextField(h)
        else: continue  
        hbox.addItem(f.ctrl);
    return hbox.ctrl
Exemplo n.º 4
0
    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()
Exemplo n.º 5
0
    def start(self, primaryStage):
        primaryStage.setTitle("JythonFX Draw")
        root = StackPane()
        screen = javafx.stage.Screen.getPrimary()
        rect = screen.visualBounds
        canvas = Canvas(rect.width/2 + 50,
                        rect.height/2 + 300)
        graphics_context = canvas.graphicsContext2D
        
        def resetAction(event):
            graphics_context.clearRect(1,1,
            graphics_context.canvas.width-2,
            graphics_context.canvas.height-2)
            
        def colorAction(newval):
            idx = newval.value
            if idx == 0:
                new_color = Color.BLACK
            elif idx == 1:
                new_color = Color.BLUE
            elif idx == 2:
                new_color = Color.RED
            elif idx == 3:
                new_color = Color.GREEN
            elif idx == 4:
                new_color = Color.BROWN
            elif idx == 5:
                new_color = Color.ORANGE
            else:
                new_color = Color.BLACK

            graphics_context.setStroke(new_color)
            
        def sizeAction(newval):
            idx = newval.value
            if idx == 0:
                graphics_context.lineWidth = 1
            elif idx == 1:
                graphics_context.lineWidth = 2
            elif idx == 2:
                graphics_context.lineWidth = 3
            elif idx == 3:
                graphics_context.lineWidth = 4
            elif idx == 4:
                graphics_context.lineWidth = 5
            else:
                graphics_context.lineWidth = 1
            
            
        resetButton = javafx.scene.control.Button(
            "Reset", onAction=resetAction)
        resetButton.translateX = 10
        
        colorChooser = javafx.scene.control.ChoiceBox(
        FXCollections.observableArrayList(
        "Black", "Blue", "Red", "Green", "Brown", "Orange"
        ))
        
        cssm = colorChooser.selectionModel
        cssm.selectedIndexProperty().addListener(colorAction)
        
        sizeChooser = javafx.scene.control.ChoiceBox(
            FXCollections.observableArrayList
            ("1", "2", "3", "4", "5")
        )
        
        scsm = sizeChooser.selectionModel
        scsm.selectedIndexProperty().addListener(sizeAction)
        
        def mouse_pressed(event):
            graphics_context.beginPath()
            graphics_context.moveTo(event.x, event.y)
            graphics_context.stroke()
            
        def mouse_dragged(event):
            graphics_context.lineTo(event.x, event.y)
            graphics_context.stroke()
        
        canvas.addEventHandler(MouseEvent.MOUSE_PRESSED,
                               mouse_pressed)
        canvas.addEventHandler(MouseEvent.MOUSE_DRAGGED,
                               mouse_dragged)
        
        buttonBox = HBox()
        buttonBox.children.addAll(colorChooser,
                                  sizeChooser, resetButton)
        
        self.init_draw(graphics_context,
                       canvas.layoutX, canvas.layoutY)
        
        container = BorderPane()
        container.top = buttonBox
        container.center = canvas
        root.children.add(container)
        
        scene = Scene(root, rect.height, rect.width)
        primaryStage.title = "JythonFX Draw"
        primaryStage.scene = scene
        primaryStage.show()