Beispiel #1
0
  def __init__( self, master, **kw):
    Tkinter.Frame.__init__( self, master, **kw)
    self.editPool = Tkinter.Entry( self, width=60)
    self.editPool.pack( side='left')

    self.editPool.bind("<KeyPress>", self._key)

    # subscript numbers
    pix = Store.app.request( 'pixmap', name='subnum')
    if pix:
      self.numbersToSubButton = Tkinter.Button( self,
                                                image=pix,
                                                command=self._numbersToSubButtonPressed,
                                                bd=config.border_width)
      Store.app.balloon.bind( self.numbersToSubButton, _('Subscript numbers'))
    else:
      self.numbersToSubButton = Tkinter.Button( self,
                                               text=_('Sub numbers'),
                                               command=self._numbersToSubButtonPressed,
                                               bd=config.border_width)
    self.numbersToSubButton.pack( side='left')

    # superscript charges
    pix = Store.app.request( 'pixmap', name='supcharge')
    if pix:
      self.chargesToSupButton = Tkinter.Button( self,
                                                image=pix,
                                                command=self._chargesToSupButtonPressed,
                                                bd=config.border_width)
      Store.app.balloon.bind( self.chargesToSupButton, _('Superscript charges'))
    else:
      self.chargesToSupButton = Tkinter.Button( self,
                                                text=_('Sup charges'),
                                                command=self._chargesToSupButtonPressed,
                                                bd=config.border_width)
    self.chargesToSupButton.pack( side='left')

    # text decoration
    for i in self.font_decorations:
      pix = Store.app.request( 'pixmap', name=i)
      if pix:
        self.__dict__[ i] = Tkinter.Button( self,
                                    image=pix,
                                    command=misc.lazy_apply( self._tag_it, (self.font_decorations_to_html[i],)),
                                    bd=config.border_width)
        Store.app.balloon.bind( self.__dict__[i], i)
      else:
        self.__dict__[ i] = Tkinter.Button( self,
                                    text=i,
                                    command=misc.lazy_apply( self._tag_it, (self.font_decorations_to_html[i],)),
                                    bd=config.border_width)
      self.__dict__[i].pack( side='left')
Beispiel #2
0
  def __init__(self, master, **kw):
    Tkinter.Frame.__init__( self, master, **kw)
    self.editPool = Tkinter.Entry( self, width=60)
    self.editPool.pack( side='left')

    self.editPool.bind("<KeyPress>", self._key)

    # subscript numbers
    pix = Store.app.request( 'pixmap', name='subnum')
    if pix:
      self.numbersToSubButton = Tkinter.Button( self,
                                                image=pix,
                                                command=self._numbersToSubButtonPressed,
                                                bd=config.border_width)
      Store.app.balloon.bind( self.numbersToSubButton, _('Subscript numbers'))
    else:
      self.numbersToSubButton = Tkinter.Button( self,
                                               text=_('Sub numbers'),
                                               command=self._numbersToSubButtonPressed,
                                               bd=config.border_width)
    self.numbersToSubButton.pack( side='left')

    # superscript charges
    pix = Store.app.request( 'pixmap', name='supcharge')
    if pix:
      self.chargesToSupButton = Tkinter.Button( self,
                                                image=pix,
                                                command=self._chargesToSupButtonPressed,
                                                bd=config.border_width)
      Store.app.balloon.bind( self.chargesToSupButton, _('Superscript charges'))
    else:
      self.chargesToSupButton = Tkinter.Button( self,
                                                text=_('Sup charges'),
                                                command=self._chargesToSupButtonPressed,
                                                bd=config.border_width)
    self.chargesToSupButton.pack( side='left')

    # text decoration
    for i in self.font_decorations:
      pix = Store.app.request( 'pixmap', name=i)
      if pix:
        self.__dict__[ i] = Tkinter.Button( self,
                                    image=pix,
                                    command=misc.lazy_apply( self._tag_it, (self.font_decorations_to_html[i],)),
                                    bd=config.border_width)
        Store.app.balloon.bind( self.__dict__[i], i)
      else:
        self.__dict__[ i] = Tkinter.Button( self,
                                    text=i,
                                    command=misc.lazy_apply( self._tag_it, (self.font_decorations_to_html[i],)),
                                    bd=config.border_width)
      self.__dict__[i].pack( side='left')
Beispiel #3
0
 def __init__(self, callback, **kw):
     self.callback = callback
     Tkinter.Menu.__init__(self, Store.app, tearoff=0, **kw)
     keys = self.chars.keys()
     keys.sort()
     for k in keys:
         self.add_command(label=k, command=misc.lazy_apply(self.itemselected, (k,)))
     self.char = None
Beispiel #4
0
 def __init__(self, callback, **kw):
     self.callback = callback
     Tkinter.Menu.__init__(self, Store.app, tearoff=0, **kw)
     keys = self.chars.keys()
     keys.sort()
     for k in keys:
         self.add_command(label=k,
                          command=misc.lazy_apply(self.itemselected, (k, )))
     self.char = None
Beispiel #5
0
  def __init__( self, selected, **kw):
    Tkinter.Menu.__init__( self, Store.app, tearoff=0, **kw)
    self.selected = selected
    self.changes_made = 0
    already_there = []
    self.configurable = {} # this is similar to configurable but is prepared on init to take dynamic things into account
    # at first prepare all the items
    items = {}
    for obj_type in configurable.keys():
      if misc.myisstr(obj_type):
        objs = [o for o in self.selected if o.object_type == obj_type]
      else:
        objs = [o for o in self.selected if isinstance( o, obj_type)]

      if not objs:
        continue
      for attr in configurable[ obj_type]:
        if misc.myisstr(attr):
          # attr can be either a string (key of config_values)
          vals = config_values[ attr]
        if isinstance(attr, collections.Callable):
          # or it can be a callable that takes list of objects and returns the desired tuple
          attr, vals = attr( [o for o in self.selected if o.object_type == obj_type])

        if vals and attr not in already_there:
          items[ vals[ I18N_NAME]] = []
          self.configurable[ obj_type] = self.configurable.get( obj_type, []) + [attr]
          for v in vals[ VALUES]:
            if isinstance(v, tuple):
              items[ vals[ I18N_NAME]].append( (v[1], attr, objs, v[0]))
            else:
              items[ vals[ I18N_NAME]].append( (v, attr, objs, v))
          # to know what is already there
          already_there.append( attr)
        elif vals: # attr is already there
          for tup in items[ vals[ I18N_NAME]]:
            tup[2].extend( objs)

    # then sort the items and polulate the menu
    keys = sorted(items.keys())
    for key in keys:
      casc = Tkinter.Menu( self, tearoff=0)
      self.add_cascade( label=key, menu=casc)
      for (v1, attr, objs, v0) in items[ key]:
        casc.add_command( label=v1, command=misc.lazy_apply( self.callback, (attr, objs, v0)))

    # commands
    if already_there and len( [o for o in self.selected if o.object_type != 'mark']):
      # marks do not have entry in properties dialog
      self.add_separator()
    i = False
    i += self.register_command_by_object_type( _("Center bond"), ('bond',), center)
    i += self.register_command_by_class_name( _("Expand group"), ('group',), expand_groups)
    i += self.register_command_by_object_type( _("Set atom number"), ('atom',), set_atom_number)
    i += self.register_command_through_filter( mark_template_atom_filter, objs)
    i += self.register_command_through_filter( mark_template_bond_filter, objs)

    # common commands
    if len( [o for o in self.selected if o.object_type != 'mark']):
      # marks do not have entry in properties dialog
      if i:
        self.add_separator()
      self.add_command( label=_("Properties"), command=Store.app.paper.config_selected)
Beispiel #6
0
    def __init__(self, selected, **kw):
        Tkinter.Menu.__init__(self, Store.app, tearoff=0, **kw)
        self.selected = selected
        self.changes_made = 0
        already_there = []
        self.configurable = {
        }  # this is similar to configurable but is prepared on init to take dynamic things into account
        # at first prepare all the items
        items = {}
        for obj_type in configurable.keys():
            if type(obj_type) == types.StringType:
                objs = [o for o in self.selected if o.object_type == obj_type]
            else:
                objs = [o for o in self.selected if isinstance(o, obj_type)]

            if not objs:
                continue
            for attr in configurable[obj_type]:
                if type(attr) == types.StringType:
                    # attr can be either a string (key of config_values)
                    vals = config_values[attr]
                if type(attr) == types.FunctionType:
                    # or it can be a callable that takes list of objects and returns the desired tuple
                    attr, vals = attr([
                        o for o in self.selected if o.object_type == obj_type
                    ])

                if vals and attr not in already_there:
                    items[vals[I18N_NAME]] = []
                    self.configurable[obj_type] = self.configurable.get(
                        obj_type, []) + [attr]
                    for v in vals[VALUES]:
                        if type(v) == types.TupleType:
                            items[vals[I18N_NAME]].append(
                                (v[1], attr, objs, v[0]))
                        else:
                            items[vals[I18N_NAME]].append((v, attr, objs, v))
                    # to know what is already there
                    already_there.append(attr)
                elif vals:  # attr is already there
                    for tup in items[vals[I18N_NAME]]:
                        tup[2].extend(objs)

        # then sort the items and polulate the menu
        keys = items.keys()
        keys.sort()
        for key in keys:
            casc = Tkinter.Menu(self, tearoff=0)
            self.add_cascade(label=key, menu=casc)
            for (v1, attr, objs, v0) in items[key]:
                casc.add_command(label=v1,
                                 command=misc.lazy_apply(
                                     self.callback, (attr, objs, v0)))

        # commands
        if already_there and len(
            [o for o in self.selected if o.object_type != 'mark']):
            # marks do not have entry in properties dialog
            self.add_separator()
        i = False
        i += self.register_command_by_object_type(_("Center bond"), ('bond', ),
                                                  center)
        i += self.register_command_by_class_name(_("Expand group"),
                                                 ('group', ), expand_groups)
        i += self.register_command_by_object_type(_("Set atom number"),
                                                  ('atom', ), set_atom_number)
        i += self.register_command_through_filter(mark_template_atom_filter,
                                                  objs)
        i += self.register_command_through_filter(mark_template_bond_filter,
                                                  objs)

        # common commands
        if len([o for o in self.selected if o.object_type != 'mark']):
            # marks do not have entry in properties dialog
            if i:
                self.add_separator()
            self.add_command(label=_("Properties"),
                             command=Store.app.paper.config_selected)
Beispiel #7
0
    def __init__(self, master, buttons=("interpret", "asis"), **kw):
        Frame.__init__(self, master, **kw)
        self.text = ""
        self.interpret = 1
        self.editPool = Entry(self, width=50, state="disabled", font="Helvetica 12")
        self.editPool.pack(side="left")

        self.editPool.bind("<Return>", self._interpretButtonPressed)
        self.editPool.bind("<Escape>", self._cancel)

        self.editPool.bind("<Control-s>", lambda e: self._tag_it("sub"))
        self.editPool.bind("<Control-S>", lambda e: self._tag_it("sup"))
        self.editPool.bind("<Control-i>", lambda e: self._tag_it("i"))
        self.editPool.bind("<Control-b>", lambda e: self._tag_it("b"))

        self.editPool.bind("<KeyPress>", self._key)

        if "interpret" in buttons:
            pix = Store.app.request("pixmap", name="interpret")
            self.interpretButton = Button(
                self,
                text=_("Interpret"),
                image=pix,
                command=self._interpretButtonPressed,
                state="disabled",
                bd=config.border_width,
            )
            Store.app.balloon.bind(self.interpretButton, _("Interpret text (where applicable)"))
            self.interpretButton.pack(side="left")
        else:
            self.interpretButton = None

        if "asis" in buttons:
            pix = Store.app.request("pixmap", name="asis")
            self.setButton = Button(
                self,
                image=pix,
                text=_("As is"),
                command=self._setButtonPressed,
                state="disabled",
                bd=config.border_width,
            )
            Store.app.balloon.bind(self.setButton, _("Leave text as is - do not interpret"))
            self.setButton.pack(side="left")
        else:
            self.setButton = None

        pix = Store.app.request("pixmap", name="subnum")
        self.numbersToSubButton = Button(
            self,
            image=pix,
            text=_("Sub numbers"),
            command=self._numbersToSubButtonPressed,
            state="disabled",
            bd=config.border_width,
        )
        Store.app.balloon.bind(self.numbersToSubButton, _("Convert numbers to subscript"))
        self.numbersToSubButton.pack(side="left")

        # text decoration
        decorFrame = Frame(self)
        decorFrame.pack(padx=5, side="left")
        for i in self.font_decorations:
            pix = Store.app.request("pixmap", name=i)
            self.__dict__[i] = Button(
                self,
                image=pix,
                command=misc.lazy_apply(self._tag_it, (self.font_decorations_to_html[i],)),
                state="disabled",
                text=self.font_decorations_to_names[i],
                bd=config.border_width,
            )
            Store.app.balloon.bind(self.__dict__[i], self.font_decorations_to_names[i])
            self.__dict__[i].pack(side="left")

        # special characters
        pix = Store.app.request("pixmap", name="specialchar")
        self.specialCharButton = Button(
            self,
            image=pix,
            text=_("Special Character"),
            command=self._specialCharButtonPressed,
            state="disabled",
            bd=config.border_width,
        )
        Store.app.balloon.bind(self.specialCharButton, _("Insert a special character"))
        self.specialCharButton.pack(side="left")
        self.active = False
Beispiel #8
0
    def __init__(self, master, buttons=('interpret', 'asis'), **kw):
        Frame.__init__(self, master, **kw)
        self.text = ''
        self.interpret = 1
        self.editPool = Entry(self,
                              width=50,
                              state='disabled',
                              font="Helvetica 12")
        self.editPool.pack(side='left')

        self.editPool.bind('<Return>', self._interpretButtonPressed)
        self.editPool.bind('<Escape>', self._cancel)

        self.editPool.bind('<Control-s>', lambda e: self._tag_it("sub"))
        self.editPool.bind('<Control-S>', lambda e: self._tag_it("sup"))
        self.editPool.bind('<Control-i>', lambda e: self._tag_it("i"))
        self.editPool.bind('<Control-b>', lambda e: self._tag_it("b"))

        self.editPool.bind("<KeyPress>", self._key)

        if 'interpret' in buttons:
            pix = Store.app.request('pixmap', name='interpret')
            self.interpretButton = Button(self,
                                          text=_('Interpret'),
                                          image=pix,
                                          command=self._interpretButtonPressed,
                                          state='disabled',
                                          bd=config.border_width)
            Store.app.balloon.bind(self.interpretButton,
                                   _('Interpret text (where applicable)'))
            self.interpretButton.pack(side='left')
        else:
            self.interpretButton = None

        if 'asis' in buttons:
            pix = Store.app.request('pixmap', name='asis')
            self.setButton = Button(self,
                                    image=pix,
                                    text=_('As is'),
                                    command=self._setButtonPressed,
                                    state='disabled',
                                    bd=config.border_width)
            Store.app.balloon.bind(self.setButton,
                                   _('Leave text as is - do not interpret'))
            self.setButton.pack(side='left')
        else:
            self.setButton = None

        pix = Store.app.request('pixmap', name='subnum')
        self.numbersToSubButton = Button(
            self,
            image=pix,
            text=_('Sub numbers'),
            command=self._numbersToSubButtonPressed,
            state='disabled',
            bd=config.border_width)
        Store.app.balloon.bind(self.numbersToSubButton,
                               _('Convert numbers to subscript'))
        self.numbersToSubButton.pack(side='left')

        # text decoration
        decorFrame = Frame(self)
        decorFrame.pack(padx=5, side="left")
        for i in self.font_decorations:
            pix = Store.app.request('pixmap', name=i)
            self.__dict__[i] = Button(
                self,
                image=pix,
                command=misc.lazy_apply(self._tag_it,
                                        (self.font_decorations_to_html[i], )),
                state='disabled',
                text=self.font_decorations_to_names[i],
                bd=config.border_width)
            Store.app.balloon.bind(self.__dict__[i],
                                   self.font_decorations_to_names[i])
            self.__dict__[i].pack(side="left")

        # special characters
        pix = Store.app.request('pixmap', name='specialchar')
        self.specialCharButton = Button(self,
                                        image=pix,
                                        text=_('Special Character'),
                                        command=self._specialCharButtonPressed,
                                        state='disabled',
                                        bd=config.border_width)
        Store.app.balloon.bind(self.specialCharButton,
                               _('Insert a special character'))
        self.specialCharButton.pack(side='left')
        self.active = False