Ejemplo n.º 1
0
    def __init__(self, glyph, callback, x, y):
        self.glyph = glyph
        self.callback = callback
        # create the modal dialog (from dialogKit)
        self.w = ModalDialog((200, 150),
                             "Shapes Tool",
                             okCallback=self.okCallback,
                             cancelCallback=self.cancelCallback)

        # add some text boxes
        self.w.xText = TextBox((10, 43, 100, 22), "x")
        self.w.wText = TextBox((10, 13, 100, 22), "w")
        self.w.yText = TextBox((100, 43, 100, 22), "y")
        self.w.hText = TextBox((100, 13, 100, 22), "h")

        # adding input boxes
        self.w.xInput = EditText((30, 40, 50, 22), "%i" % x)
        self.w.wInput = EditText((30, 10, 50, 22))
        self.w.yInput = EditText((120, 40, 50, 22), "%i" % y)
        self.w.hInput = EditText((120, 10, 50, 22))

        # a radio shape choice group
        # (the RadioGroup isn't standaard in dialogKit, this is a vanilla object)
        self.shapes = ["oval", "rect"]
        self.w.shape = RadioGroup((10, 70, -10, 22),
                                  self.shapes,
                                  isVertical=False)
        self.w.shape.set(0)

        self.w.open()
 def __init__(self, message, value, title):
     self.w = ModalDialog((360, 140), title)
     self.w.button1 = Button((-100, -300, 80, 24),
                             'OK',
                             callback=self.buttonCallback)
     self.w.t = TextBox((5, 10, -5, 27), message)
     self.w.inputValue = EditText((5, 35, -5, 50), value)
     self.w.open()
Ejemplo n.º 3
0
class GeometricShapesWindow(object):
    """
    The Modal window that allows numbers input to draw basic geometric shapes.
    """
    def __init__(self, glyph, callback, x, y):
        self.glyph = glyph
        self.callback = callback
        # create the modal dialog (from dialogKit)
        self.w = ModalDialog((200, 150),
                             "Shapes Tool",
                             okCallback=self.okCallback,
                             cancelCallback=self.cancelCallback)

        # add some text boxes
        self.w.xText = TextBox((10, 43, 100, 22), "x")
        self.w.wText = TextBox((10, 13, 100, 22), "w")
        self.w.yText = TextBox((100, 43, 100, 22), "y")
        self.w.hText = TextBox((100, 13, 100, 22), "h")

        # adding input boxes
        self.w.xInput = EditText((30, 40, 50, 22), "%i" % x)
        self.w.wInput = EditText((30, 10, 50, 22))
        self.w.yInput = EditText((120, 40, 50, 22), "%i" % y)
        self.w.hInput = EditText((120, 10, 50, 22))

        # a radio shape choice group
        # (the RadioGroup isn't standaard in dialogKit, this is a vanilla object)
        self.shapes = ["oval", "rect"]
        self.w.shape = RadioGroup((10, 70, -10, 22),
                                  self.shapes,
                                  isVertical=False)
        self.w.shape.set(0)

        self.w.open()

    def okCallback(self, sender):
        # draw the shape in the glyph
        # get the shape from the radio group
        shape = self.shapes[self.w.shape.get()]
        # try to get some integers from the input fields
        try:
            x = int(self.w.xInput.get())
            y = int(self.w.yInput.get())
            w = int(self.w.wInput.get())
            h = int(self.w.hInput.get())
        # if this fails just do nothing and print a tiny traceback
        except:
            print "A number is required!"
            return
        # draw the shape with the callback given on init
        self.callback(shape, (x, y, w, h), self.glyph)

    def cancelCallback(self, sender):
        # do nothing :)
        pass
class GeometricShapesWindow(object):
    """
    The Modal window that allows numbers input to draw basic geometric shapes.
    """
    
    def __init__(self, glyph, callback, x, y):
        self.glyph = glyph
        self.callback = callback
        ## create the modal dialog (from dialogKit)
        self.w = ModalDialog((200, 150), 
                            "Shapes Tool", 
                            okCallback=self.okCallback, 
                            cancelCallback=self.cancelCallback)
        
        ## add some text boxes
        self.w.xText = TextBox((10, 13, 100, 22), "x")
        self.w.yText = TextBox((10, 43, 100, 22), "y")
        self.w.wText = TextBox((100, 13, 100, 22), "w")
        self.w.hText = TextBox((100, 43, 100, 22), "h")
        
        ## adding input boxes
        self.w.xInput = EditText((30, 10, 50, 22), "%i" %x)
        self.w.yInput = EditText((30, 40, 50, 22), "%i" %y)
        self.w.wInput = EditText((120, 10, 50, 22))
        self.w.hInput = EditText((120, 40, 50, 22))
        
        ## a radio shape choice group 
        ## (the RadioGroup isn't standaard in dialogKit, this is a vanilla object)
        self.shapes = ["rect", "oval"]
        self.w.shape = RadioGroup((10, 70, -10, 22), self.shapes, isVertical=False)
        self.w.shape.set(0)
        
        self.w.open()
        
    def okCallback(self, sender):
        ## draw the shape in the glyph
        ## get the shape from the radio group
        shape = self.shapes[self.w.shape.get()]
        ## try to get some integers from the input fields
        try:
            x = int(self.w.xInput.get())
            y = int(self.w.yInput.get())
            w = int(self.w.wInput.get())
            h = int(self.w.hInput.get())
        ## if this fails just do nothing and print a tiny traceback
        except:
            print "Input wan't a number!" 
            return
        ## draw the shape with the callback given on init
        self.callback(shape, (x, y, w, h), self.glyph)
    
    def cancelCallback(self, sender):
        ## do nothing :)
        pass
 def __init__(self, message, default=None, title="RoboFab"):
     # default is ignord?
     self.answer = -1
     self.w = ModalDialog((360, 140),
                          title,
                          okCallback=self.buttonOKCallback)
     self.w.noButton = Button((10, -35, 80, 24),
                              'No',
                              callback=self.buttonNoCallback)
     self.w.t = TextBox((5, 10, -5, 27), message)
     self.w.open()
Ejemplo n.º 6
0
class _AskStringDialog(object):
    def __init__(self, message, value, title):
        self.w = ModalDialog((360, 140), title)
        self.w.button1 = Button((-100, -300, 80, 24), 'OK', callback=self.buttonCallback)
        self.w.t = TextBox((5, 10, -5, 27), message)
        self.w.inputValue = EditText((5, 35, -5, 50), value)
        self.w.open()
    
    def getValue(self):
        return self.w.inputValue.get()
    
    def buttonCallback(self, sender):
        self.w.close()
class _AskStringDialog(object):
    def __init__(self, message, value, title):
        self.w = ModalDialog((360, 140), title)
        self.w.button1 = Button((-100, -300, 80, 24),
                                'OK',
                                callback=self.buttonCallback)
        self.w.t = TextBox((5, 10, -5, 27), message)
        self.w.inputValue = EditText((5, 35, -5, 50), value)
        self.w.open()

    def getValue(self):
        return self.w.inputValue.get()

    def buttonCallback(self, sender):
        self.w.close()
Ejemplo n.º 8
0
 def __init__(self, message, default=None, title="RoboFab"):
     # default is ignord?
     self.answer = -1
     self.w = ModalDialog((360, 140), title, okCallback=self.buttonOKCallback)
     self.w.noButton = Button((10, -35, 80, 24), 'No', callback=self.buttonNoCallback)
     self.w.t = TextBox((5, 10, -5, 27), message)
     self.w.open()
 def __init__(self, glyph, callback, x, y):
     self.glyph = glyph
     self.callback = callback
     ## create the modal dialog (from dialogKit)
     self.w = ModalDialog((200, 150), 
                         "Shapes Tool", 
                         okCallback=self.okCallback, 
                         cancelCallback=self.cancelCallback)
     
     ## add some text boxes
     self.w.xText = TextBox((10, 13, 100, 22), "x")
     self.w.yText = TextBox((10, 43, 100, 22), "y")
     self.w.wText = TextBox((100, 13, 100, 22), "w")
     self.w.hText = TextBox((100, 43, 100, 22), "h")
     
     ## adding input boxes
     self.w.xInput = EditText((30, 10, 50, 22), "%i" %x)
     self.w.yInput = EditText((30, 40, 50, 22), "%i" %y)
     self.w.wInput = EditText((120, 10, 50, 22))
     self.w.hInput = EditText((120, 40, 50, 22))
     
     ## a radio shape choice group 
     ## (the RadioGroup isn't standaard in dialogKit, this is a vanilla object)
     self.shapes = ["rect", "oval"]
     self.w.shape = RadioGroup((10, 70, -10, 22), self.shapes, isVertical=False)
     self.w.shape.set(0)
     
     self.w.open()
Ejemplo n.º 10
0
 def __init__(self):
     self.w = ModalDialog((200, 120),
                          'Dump/Fuse',
                          okCallback=self.okCallback)
     Selection = NSUserDefaults.standardUserDefaults().integerForKey_(
         "Fuse_Dump_DialogSelection")
     if Selection < 1 or Selection > 3:
         Selection = 2
     self.w.dumpComp = CheckBox((10, 10, 180, 20),
                                'Dump components',
                                value=(Selection == 1
                                       or Selection == 3))
     self.w.fuseComp = CheckBox((10, 40, 180, 20),
                                'Fuse components',
                                value=(Selection == 2
                                       or Selection == 3))
     self.value = 0
     self.w.open()
Ejemplo n.º 11
0
 def __init__(self,
              items_list,
              title="select options",
              width=320,
              sort=False):
     self._title = title
     self._width = width
     self._height = (self._padding * 2) + (
         (len(items_list) + 2) * self._box_height) + 50
     # sort items
     if sort:
         tmp = list(items_list)
         tmp.sort()
         items_list = tuple(tmp)
     self._items_list = items_list
     # init window
     self.w = ModalDialog((self._width, self._height),
                          self._title,
                          okCallback=self.ok_callback,
                          cancelCallback=self.cancel_callback)
     x = self._padding
     y = self._padding
     # select all / none
     self.w._select_all_checkbox = CheckBox(
         (x, y, -self._padding, self._box_height),
         'select/deselect all',
         value=self._select_all,
         callback=self._select_all_callback)
     y += (self._box_height)
     # division line
     self.w.line = HorizontalLine((x, y, -self._padding, self._box_height))
     # create checkboxes from list
     for item in self._items_list:
         self._add_checkbox(item)
     # open window
     self.w.open()
Ejemplo n.º 12
0
 class TwoChecksDK(object):
     
     def __init__(self):
         self.w = ModalDialog((200, 120), 'Dump/Fuse', okCallback=self.okCallback)
         self.w.dumpComp = CheckBox((10, 10, 180, 20), 'Dump components', callback=self.dumpCompCallback)
         self.w.fuseComp = CheckBox((10, 40, 180, 20), 'Fuse components', callback=self.fuseCompCallback, value=True)
         self.value = 2
         self.w.open()
     
     def dumpCompCallback(self, sender):
         if sender.get() == 1:
             self.value += 1
         else:
             self.value -= 1
     
     def fuseCompCallback(self, sender):
         if sender.get() == 1:
             self.value += 2
         else:
             self.value -= 2
     
     def okCallback(self, sender):
         print self.value
         return self.value
Ejemplo n.º 13
0
 def __init__(self, items_list, title="select options", width=320, sort=False):
     self._title  = title
     self._width  = width
     self._height = (self._padding * 2) + ( (len(items_list) + 2) * self._box_height ) + 50
     # sort items
     if sort:
         tmp = list(items_list)
         tmp.sort()
         items_list = tuple(tmp)
     self._items_list = items_list
     # init window
     self.w = ModalDialog(
                 (self._width,
                 self._height),
                 self._title,
                 okCallback=self.ok_callback,
                 cancelCallback=self.cancel_callback)
     x = self._padding
     y = self._padding
     # select all / none
     self.w._select_all_checkbox = CheckBox(
                 (x, y,
                 -self._padding,
                 self._box_height),
                 'select/deselect all',
                 value=self._select_all,
                 callback=self._select_all_callback)
     y += (self._box_height)
     # division line
     self.w.line = HorizontalLine(
                 (x, y,
                 -self._padding,
                 self._box_height))
     # create checkboxes from list
     for item in self._items_list:
         self._add_checkbox(item)
     # open window
     self.w.open()
Ejemplo n.º 14
0
class _AskYesNoCancelDialog(object):
    def __init__(self, message, default=None, title="RoboFab"):
        # default is ignord?
        self.answer = -1
        self.w = ModalDialog((360, 140), title, okCallback=self.buttonOKCallback)
        self.w.noButton = Button((10, -35, 80, 24), 'No', callback=self.buttonNoCallback)
        self.w.t = TextBox((5, 10, -5, 27), message)
        self.w.open()
    
    def getValue(self):
        return self.answer
    
    def buttonNoCallback(self, sender):
        self.answer = 0
        self.w.close()
        
    def buttonOKCallback(self, sender):
        self.answer = 1
        self.w.close()
class _AskYesNoCancelDialog(object):
    def __init__(self, message, default=None, title="RoboFab"):
        # default is ignord?
        self.answer = -1
        self.w = ModalDialog((360, 140),
                             title,
                             okCallback=self.buttonOKCallback)
        self.w.noButton = Button((10, -35, 80, 24),
                                 'No',
                                 callback=self.buttonNoCallback)
        self.w.t = TextBox((5, 10, -5, 27), message)
        self.w.open()

    def getValue(self):
        return self.answer

    def buttonNoCallback(self, sender):
        self.answer = 0
        self.w.close()

    def buttonOKCallback(self, sender):
        self.answer = 1
        self.w.close()
 def __init__(self, message, title):
     self.w = ModalDialog((360, 100), title)
     self.w.t = TextBox((5, 10, -5, -40), message)
     self.w.open()
Ejemplo n.º 17
0
class checkBoxBuilder(object):

    _box_height = 23
    _padding = 10

    _select_all = False
    _checkboxes = {}

    cancelled = False
    selected = []

    def __init__(self, items_list, title="select options", width=320, sort=False):
        self._title  = title
        self._width  = width
        self._height = (self._padding * 2) + ( (len(items_list) + 2) * self._box_height ) + 50
        # sort items
        if sort:
            tmp = list(items_list)
            tmp.sort()
            items_list = tuple(tmp)
        self._items_list = items_list
        # init window
        self.w = ModalDialog(
                    (self._width,
                    self._height),
                    self._title,
                    okCallback=self.ok_callback,
                    cancelCallback=self.cancel_callback)
        x = self._padding
        y = self._padding
        # select all / none
        self.w._select_all_checkbox = CheckBox(
                    (x, y,
                    -self._padding,
                    self._box_height),
                    'select/deselect all',
                    value=self._select_all,
                    callback=self._select_all_callback)
        y += (self._box_height)
        # division line
        self.w.line = HorizontalLine(
                    (x, y,
                    -self._padding,
                    self._box_height))
        # create checkboxes from list
        for item in self._items_list:
            self._add_checkbox(item)
        # open window
        self.w.open()

    def _add_checkbox(self, (title, value)):
        number = len(self._checkboxes) + 2
        attribute_name = "checkBox%d" % number
        x = self._padding
        y = self._padding + (number * self._box_height)
        checkBox = CheckBox(
                    (x, y,
                    -self._padding,
                    self._box_height),
                    title,
                    value=value,
                    callback=self.checkbox_callback)
        setattr(self.w, attribute_name, checkBox)
        self._checkboxes[checkBox] = (title, value)
Ejemplo n.º 18
0
 def __init__(self):
     self.w = ModalDialog((200, 120), 'Dump/Fuse', okCallback=self.okCallback)
     self.w.dumpComp = CheckBox((10, 10, 180, 20), 'Dump components', callback=self.dumpCompCallback)
     self.w.fuseComp = CheckBox((10, 40, 180, 20), 'Fuse components', callback=self.fuseCompCallback, value=True)
     self.value = 2
     self.w.open()
Ejemplo n.º 19
0
 def __init__(self, message, value, title):
     self.w = ModalDialog((360, 140), title)
     self.w.button1 = Button((-100, -300, 80, 24), 'OK', callback=self.buttonCallback)
     self.w.t = TextBox((5, 10, -5, 27), message)
     self.w.inputValue = EditText((5, 35, -5, 50), value)
     self.w.open()
Ejemplo n.º 20
0
class checkBoxBuilder(object):
    """An object to create a modal dialog for selecting items in a list.

    .. image:: imgs/misc/checkbox-builder.png

    .. code-block:: python

        from hTools2.dialogs.misc import checkBoxBuilder

        L = [
            ('apples', True),
            ('bananas', True),
            ('tomatos', False),
        ]

        B = checkBoxBuilder(L)

        print B.selected

        >>> ['apples', 'bananas']

    """

    # attributes

    _box_height = 23
    _padding = 10

    _select_all = False
    _checkboxes = {}

    cancelled = False
    selected = []

    # methods

    def __init__(self,
                 items_list,
                 title="select options",
                 width=320,
                 sort=False):
        self._title = title
        self._width = width
        self._height = (self._padding * 2) + (
            (len(items_list) + 2) * self._box_height) + 50
        # sort items
        if sort:
            tmp = list(items_list)
            tmp.sort()
            items_list = tuple(tmp)
        self._items_list = items_list
        # init window
        self.w = ModalDialog((self._width, self._height),
                             self._title,
                             okCallback=self.ok_callback,
                             cancelCallback=self.cancel_callback)
        x = self._padding
        y = self._padding
        # select all / none
        self.w._select_all_checkbox = CheckBox(
            (x, y, -self._padding, self._box_height),
            'select/deselect all',
            value=self._select_all,
            callback=self._select_all_callback)
        y += (self._box_height)
        # division line
        self.w.line = HorizontalLine((x, y, -self._padding, self._box_height))
        # create checkboxes from list
        for item in self._items_list:
            self._add_checkbox(item)
        # open window
        self.w.open()

    def _add_checkbox(self, xxx_todo_changeme):
        (title, value) = xxx_todo_changeme
        number = len(self._checkboxes) + 2
        attribute_name = "checkBox%d" % number
        x = self._padding
        y = self._padding + (number * self._box_height)
        checkBox = CheckBox((x, y, -self._padding, self._box_height),
                            title,
                            value=value,
                            callback=self.checkbox_callback)
        setattr(self.w, attribute_name, checkBox)
        self._checkboxes[checkBox] = (title, value)

    def _select_all_callback(self, sender):
        self._select_all = sender.get()
        # update internal values
        for _checkbox in list(self._checkboxes.keys()):
            title, value = self._checkboxes[_checkbox]
            self._checkboxes[_checkbox] = (title, self._select_all)
        # update dialog
        for _checkbox in dir(self.w):
            if _checkbox[:8] == 'checkBox':
                exec("self.w.%s.set(%s)" % (_checkbox, self._select_all))

    def checkbox_callback(self, sender):
        title, value = self._checkboxes[sender]
        value = sender.get()
        self._checkboxes[sender] = (title, value)

    def ok_callback(self, sender):
        _checkboxes = list(self._checkboxes.keys())
        _checkboxes.sort()
        for _checkbox in _checkboxes:
            title, value = self._checkboxes[_checkbox]
            if value == True:
                self.selected.append(title)

    def cancel_callback(self, sender):
        self.cancelled = True
Ejemplo n.º 21
0
class checkBoxBuilder(object):

    '''An object to create a modal dialog for selecting items in a list.

    .. image:: imgs/misc/checkbox-builder.png

    .. code-block:: python

        from hTools2.dialogs.misc import checkBoxBuilder

        L = [
            ('apples', True),
            ('bananas', True),
            ('tomatos', False),
        ]

        B = checkBoxBuilder(L)

        print B.selected

        >>> ['apples', 'bananas']

    '''

    # attributes

    _box_height = 23
    _padding = 10

    _select_all = False
    _checkboxes = {}

    cancelled = False
    selected = []

    # methods

    def __init__(self, items_list, title="select options", width=320, sort=False):
        self._title  = title
        self._width  = width
        self._height = (self._padding * 2) + ( (len(items_list) + 2) * self._box_height ) + 50
        # sort items
        if sort:
            tmp = list(items_list)
            tmp.sort()
            items_list = tuple(tmp)
        self._items_list = items_list
        # init window
        self.w = ModalDialog(
                    (self._width,
                    self._height),
                    self._title,
                    okCallback=self.ok_callback,
                    cancelCallback=self.cancel_callback)
        x = self._padding
        y = self._padding
        # select all / none
        self.w._select_all_checkbox = CheckBox(
                    (x, y,
                    -self._padding,
                    self._box_height),
                    'select/deselect all',
                    value=self._select_all,
                    callback=self._select_all_callback)
        y += (self._box_height)
        # division line
        self.w.line = HorizontalLine(
                    (x, y,
                    -self._padding,
                    self._box_height))
        # create checkboxes from list
        for item in self._items_list:
            self._add_checkbox(item)
        # open window
        self.w.open()

    def _add_checkbox(self, (title, value)):
        number = len(self._checkboxes) + 2
        attribute_name = "checkBox%d" % number
        x = self._padding
        y = self._padding + (number * self._box_height)
        checkBox = CheckBox(
                    (x, y,
                    -self._padding,
                    self._box_height),
                    title,
                    value=value,
                    callback=self.checkbox_callback)
        setattr(self.w, attribute_name, checkBox)
        self._checkboxes[checkBox] = (title, value)
Ejemplo n.º 22
0
 def __init__(self, message, title):
     self.w = ModalDialog((360, 100), title)
     self.w.t = TextBox((5, 10, -5, -40), message)
     self.w.open()