added widget images

This commit is contained in:
paul
2024-09-23 22:49:44 +05:30
parent 33cb40d886
commit 1075112d2a
19 changed files with 140 additions and 14 deletions

View File

@@ -2,9 +2,12 @@ import React from "react"
// import { DndContext } from '@dnd-kit/core'
import { DeleteOutlined, EditOutlined, ReloadOutlined } from "@ant-design/icons"
import { DeleteOutlined, EditOutlined, FileImageOutlined, ReloadOutlined } from "@ant-design/icons"
import { Button, Tooltip, Dropdown } from "antd"
import domtoimage from "dom-to-image-more"
import { saveAs } from 'file-saver'
// import Droppable from "../components/utils/droppableDnd"
import Widget from "./widgets/base"
import Cursor from "./constants/cursor"
@@ -291,6 +294,24 @@ class Canvas extends React.Component {
label: (<div onClick={() => this.deleteSelectedWidgets([selectedWidget])}><DeleteOutlined /> Delete</div>),
icons: <DeleteOutlined />,
danger: true
},
{
type: 'divider',
},
{
key: "snap",
label: (<div onClick={() => {
domtoimage.toPng(selectedWidget.getElement(), {
width: selectedWidget.getElement().offsetWidth * 2, // Multiply element's width by 2
height: selectedWidget.getElement().offsetHeight * 2 // Multiply element's height by 2
}).then((dataUrl) => {
saveAs(dataUrl, 'widget.png')
}).catch((error) => {
console.error('Error capturing widget as PNg:', error)
})
}}>
<FileImageOutlined /> Save as Image</div>),
icons: <FileImageOutlined />,
}
]
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@@ -1,7 +1,5 @@
import Widget from "../../canvas/widgets/base"
import ButtonWidget from "./assets/widgets/button.png"
import { CheckBox, RadioButton } from "./widgets/ checkButton"
import Button from "./widgets/button"
import Frame from "./widgets/frame"
@@ -12,71 +10,83 @@ import OptionMenu from "./widgets/optionMenu"
import Slider from "./widgets/slider"
import TopLevel from "./widgets/toplevel"
import MainWindowImage from "./assets/widgets/mainwindow.png"
import TopLevelImage from "./assets/widgets/Toplevel.png"
import FrameImage from "./assets/widgets/frame2.png"
import LabelImage from "./assets/widgets/label.png"
import ButtonImage from "./assets/widgets/button.png"
import InputImage from "./assets/widgets/input.png"
import TextAreaImage from "./assets/widgets/textarea.png"
import SliderImage from "./assets/widgets/slider.png"
import DropDownImage from "./assets/widgets/dropdown.png"
import CheckButtonImage from "./assets/widgets/check.png"
import RadioButtonImage from "./assets/widgets/radio.png"
const TkinterSidebar = [
{
name: "Main window",
img: ButtonWidget,
img: MainWindowImage,
link: "https://github.com",
widgetClass: MainWindow
},
{
name: "Top Level",
img: ButtonWidget,
img: TopLevelImage,
link: "https://github.com",
widgetClass: TopLevel
},
{
name: "Frame",
img: ButtonWidget,
img: FrameImage,
link: "https://github.com",
widgetClass: Frame
},
{
name: "Label",
img: ButtonWidget,
img: LabelImage,
link: "https://github.com",
widgetClass: Label
},
{
name: "Button",
img: ButtonWidget,
img: ButtonImage,
link: "https://github.com",
widgetClass: Button
},
{
name: "Entry",
img: ButtonWidget,
img: InputImage,
link: "https://github.com",
widgetClass: Input
},
{
name: "Text",
img: ButtonWidget,
img: TextAreaImage,
link: "https://github.com",
widgetClass: Text
},
{
name: "CheckBox",
img: ButtonWidget,
img: CheckButtonImage,
link: "https://github.com",
widgetClass: CheckBox
},
{
name: "Radio button",
img: ButtonWidget,
img: RadioButtonImage,
link: "https://github.com",
widgetClass: RadioButton
},
{
name: "Scale",
img: ButtonWidget,
img: SliderImage,
link: "https://github.com",
widgetClass: Slider
},
{
name: "Option Menu",
img: ButtonWidget,
img: DropDownImage,
link: "https://github.com",
widgetClass: OptionMenu
},

View File

@@ -0,0 +1,81 @@
import Widget from "../../../canvas/widgets/base"
import Tools from "../../../canvas/constants/tools"
import { removeKeyFromObject } from "../../../utils/common"
class SpinBox extends Widget{
static widgetType = "spin_box"
constructor(props) {
super(props)
this.droppableTags = null // disables drops
const newAttrs = removeKeyFromObject("layout", this.state.attrs)
this.state = {
...this.state,
size: { width: 120, height: 40 },
attrs: {
...newAttrs,
styling: {
...newAttrs.styling,
foregroundColor: {
label: "Foreground Color",
tool: Tools.COLOR_PICKER, // the tool to display, can be either HTML ELement or a constant string
value: "#000",
onChange: (value) => {
this.setWidgetStyling("color", value)
this.setAttrValue("styling.foregroundColor", value)
}
}
},
placeHolder: {
label: "PlaceHolder",
tool: Tools.INPUT, // the tool to display, can be either HTML ELement or a constant string
toolProps: {placeholder: "text", maxLength: 100},
value: "placeholder text",
onChange: (value) => this.setAttrValue("placeHolder", value)
}
}
}
}
componentDidMount(){
super.componentDidMount()
this.setAttrValue("styling.backgroundColor", "#fff")
this.setWidgetName("Entry")
}
getToolbarAttrs(){
const toolBarAttrs = super.getToolbarAttrs()
return ({
id: this.__id,
widgetName: toolBarAttrs.widgetName,
placeHolder: this.state.attrs.placeHolder,
size: toolBarAttrs.size,
...this.state.attrs,
})
}
renderContent(){
return (
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden">
<div className="tw-p-2 tw-w-full tw-h-full tw-flex tw-place-items-center" style={this.state.widgetStyling}>
<div className="tw-text-sm tw-text-gray-300">
{this.getAttrValue("placeHolder")}
</div>
</div>
</div>
)
}
}
export default SpinBox