Giter Club home page Giter Club logo

gswidgetkit's Introduction

gswidgetkit

Various custom widgets for wxPython, created to be used in Gimel Studio.

Highly inspired by the look and functionality of Blender and Sketch widgets. Currently, it uses styles specific to Gimel Studio, but they can be customized as you like in constants.py.

Widget Contents

  • Buttons (with text + icon or just icon)
  • Number Field supporting integers and floats (similar to Blender's Number Field control)
  • Color Picker
  • Textctrl
  • Checkbox
  • Tooltip
  • Static Label
  • Dropdown (still needs work)
  • Color Picker Popup
  • Image Picker
  • Radio Buttons
  • Scrollbar

Get Started

Simply pip install gswidgetkit and run the demo.py file from this repository for a demo of the widgets.

Contributing

All contributions are welcome! See CONTRIBUTING.md for details. Feel free to open a PR or ask questions.

Releasing on PyPI

Navigate to the root directory

Run py -m build

Then run twine upload dist/* and follow the prompts.

License

Licensed under the Apache 2.0 License. Feel free to use these widgets as a starting point, etc for your own projects.

gswidgetkit's People

Contributors

correct-syntax avatar iwoithe avatar yasuomaidana avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gswidgetkit's Issues

Implement Color Picker Popup

A nicer color picker that is a floating popup rather than a dialog would be really nice. Should also include the color picker eyedropper (#14) for easier selection of colors.

Add docstrings to each widget

Add docstrings to each widget file so that it is self-documenting. I have seen so many undocumented "widgets" for wxpython and its terrible.

What does the cursor is suppose to do in Mac?

Hi, I just recorded a video to show how demo.py behaves in a Mac pc
what
When I click the bar to update its value, the cursor disappear. Is that ok?
Additionally there is an issue related to recursion error, I'll keep working on that.

Add a label widget

Adding a label widget will reduce the amount of lines of code. At the moment the following is required for labels.

text = wx.StaticText(self, label="Hello World!")
text.SetForegroundColour("#FFFFFF")

If the font size needs to be changed, this would require yet another line of code. A class like the following would help.

class Label(wx.StaticText):
    def __init__(self, parent, id=wx.ID_ANY, label="", colour="#FFFFFF", font_size=12, [etc...]):
        wx.StaticText.__init__(self, parent)

        [etc...]

An example of using this class would be

text = Label(self, label="Hello World!")

Button press delay solved by inheriting GenButton!!

I managed to solve the delay of the custom button by inherit from GenButton class instead of Control. Here's a bit of the code:
`import wx
from wx.lib.buttons import GenButton
from wx.lib.newevent import NewCommandEvent

button_event, EVT_BUTTON = NewCommandEvent()

class Button(GenButton):

def __init__(self, parent, id, label='', size=wx.DefaultSize, font=None, color='#a0a0a0'):
    super().__init__(parent, id, label='', size=size, style=wx.NO_BORDER)

    self.mouse_down = False
    self.buffer = None
    self.label = label

    self.SetBackgroundColour(wx.Colour(color))

    if type(font) != wx.Font:
        self.font = self.GetParent().GetFont()
    else:
        self.font = font

def OnPaint(self, evt):
    wx.BufferedPaintDC(self, self.buffer)

def OnSize(self, event):
    size = self.GetClientSize()

    # Make sure size is at least 1px to avoid
    # strange "invalid bitmap size" errors.
    if size[0] < 1:
        size = (1, 1)
    self.buffer = wx.Bitmap(*size)
    self.update()

def update(self):
    dc = wx.MemoryDC()
    dc.SelectObject(self.buffer)
    dc = wx.GCDC(dc)

    self.draw_background(dc)
    self.draw_widget(dc)

    del dc

    self.Refresh()
    self.Update()

def draw_background(self, dc):
    thickness = 1
    w, h = self.GetSize()
    dc.SetPen(wx.TRANSPARENT_PEN)
    dc.SetBrush(wx.Brush('white'))
    dc.DrawRectangle(0, 0, w, h)

def draw_widget(self, dc):
    thickness = 1
    w, h = self.GetSize()

    if self.mouse_down:
        dc.SetPen(wx.Pen('#a0a0a0', thickness))
        dc.DrawLine(0, 0, w-1, 0)
        dc.SetPen(wx.Pen(wx.Colour(self.GetBackgroundColour()).ChangeLightness(45), thickness))
        dc.DrawLine(0, thickness, w-2, thickness)

        dc.SetPen(wx.Pen('#a0a0a0', thickness))
        dc.DrawLine(0, 0, 0, h-1)
        dc.SetPen(wx.Pen(wx.Colour(self.GetBackgroundColour()).ChangeLightness(45), thickness))
        dc.DrawLine(thickness, thickness, thickness, h-2)

        dc.SetPen(wx.Pen('white', thickness))
        dc.DrawLine(w, thickness, w, h)
        dc.SetPen(wx.Pen("white", thickness))
        dc.DrawLine(2, h, w - thickness, h)

    else:
        dc.SetPen(wx.TRANSPARENT_PEN)
        dc.SetBrush(wx.Brush('white'))
        dc.DrawRectangle(0, 0, w, h)

    dc.SetFont(self.font)
    txt_w, txt_h = dc.GetTextExtent(self.label)
    txt_x = (w - txt_w) / 2
    txt_y = (h - txt_h) / 2

    if self.mouse_down:
        txt_x += thickness
        txt_y += thickness

    # Draw text
    dc.DrawText(self.label, int(txt_x), int(txt_y))

def button_function(self):
    print('no function for button')

def set_function(self, function):
    self.button_function = function

def OnLeftDown(self, evt):
    self.mouse_down = True
    self.update()
    self.button_function()
    self.send_event(True)

def OnLeftUp(self, evt):
    self.mouse_down = False
    self.update()
    self.send_event(False)

def send_event(self, pressed):
    wx.PostEvent(self, button_event(id=self.GetId(), value=pressed))`

Add a fold panel bar

Currently, the fold panel bar is inside of the Gimel Studio repo itself (so it needs to be moved). The API needs to change as well. Currently you have to set colours, icons etc. when configuring each instance of a fold panel bar. This should be combined into one class so that the following example can be used.

self.main_layout = wx.BoxSizer(wx.VERTICAL)

fpb_layout = wx.BoxSizer(wx.VERTICAL)
# [Add widgets to fpb_layout]

fpb = FoldPanelBar(self, label="Hello World", expanded=False)
fpb.SetSizer(fpb_layout)

self.main_layout.Add(fpb)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.