Exemplo n.º 1
0
 def move_check(self):
     if self.part1.features:
         mover_match, *remaining = self.part1.features
         self.features = remaining
         found = False
         mover = []
         self.movers = []
         for mover_f_list in self.part1.movers:
             if mover_f_list[0].name == mover_match.name:
                 if found:
                     if log:
                         log.critical('SMC violation in move_check')
                     else:
                         raise RuntimeError('SMC violation in move_check')
                 mover = mover_f_list[1:]
                 found = True
             else:
                 self.movers.append(mover_f_list)
         #assert found
         self.moving = []
         for (fs, moving_tree) in self.part1.moving:
             if fs[0].name == mover_match.name:
                 self.part0 = moving_tree
             else:
                 self.moving.append((fs, moving_tree))
         if mover:
             self.movers.append(mover)
             self.moving.append((mover, self.part0))
     self.category = self.part1.category
     self.head = self.part1
     self.label = self.category + "'"
Exemplo n.º 2
0
 def get_color_name(self, color) -> str:
     """ Try to find the closest matching color from a dictionary of color names
     :param color: can be HSV(!) tuple, palette key (str) or QColor
     :return:
     """
     if isinstance(color, (tuple, list)):
         cc = c()
         cc.setHsvF(color[0], color[1], color[2])
     elif isinstance(color, str):
         cc = self.get(color)
     elif isinstance(color, QColor):
         cc = color
     else:
         log.critical('Unknown color: ', color)
         return 'unknown'
     if not cc:
         log.critical('Unknown color: ', color)
         return 'unknown'
     r, g, b, a = cc.getRgb()
     d_min = 100000
     best = 0
     for i, (name, hex, rgb) in enumerate(color_names):
         ir, ig, ib = rgb
         d = (r - ir) * (r - ir) + (g - ig) * (g - ig) + (b - ib) * (b - ib)
         if d < d_min:
             d_min = d
             best = i
     return color_names[best][0]
Exemplo n.º 3
0
 def get_color_name(self, color) -> str:
     """ Try to find the closest matching color from a dictionary of color names
     :param color: can be HSV(!) tuple, palette key (str) or QColor
     :return:
     """
     if isinstance(color, (tuple, list)):
         cc = c()
         cc.setHsvF(color[0], color[1], color[2])
     elif isinstance(color, str):
         cc = self.get(color)
     elif isinstance(color, QColor):
         cc = color
     else:
         log.critical('Unknown color: ', color)
         return 'unknown'
     if not cc:
         log.critical('Unknown color: ', color)
         return 'unknown'
     r, g, b, a = cc.getRgb()
     d_min = 100000
     best = 0
     for i, (name, hex, rgb) in enumerate(color_names):
         ir, ig, ib = rgb
         d = (r - ir) * (r - ir) + (g - ig) * (g - ig) + (b - ib) * (b - ib)
         if d < d_min:
             d_min = d
             best = i
     return color_names[best][0]
Exemplo n.º 4
0
    def merge_check(self):
        if self.part0.features and self.part1.features:
            headf0, *remainders0 = self.part0.features
            headf1, *remainders1 = self.part1.features
            if headf0.value == '=' and headf1.value == '' and headf0.name == headf1.name:
                self.features = remainders0  # copy remaining head1 features
                self.movers = self.part0.movers + self.part1.movers
                if remainders1:
                    self.movers.append(remainders1)
                    self.moving.append((remainders1, self.part1))
                else:
                    #pass
                    self.part1.category += 'P'
            else:
                if log:
                    log.critical('merge_check error')
                else:
                    raise RuntimeError('merge_check error')
        self.category = self.part0.category
        self.head = self.part0
        self.label = self.category + "'"

        if self.part0.part0 or self.part0.part1:  # is it leaf?
            temp = self.part0
            self.part0 = self.part1
            self.part1 = temp
Exemplo n.º 5
0
 def get(self, key, allow_none=False) -> QColor:
     """ Shortcut to palette dictionary (self.d) """
     color = self.d.get(key, None)
     if color or allow_none:
         return color
     log.critical(f"Missing color '{key}'.")
     color = c(0, 0, 255)
     self.set_color(key, color, can_save=False)
     return color
Exemplo n.º 6
0
 def get(self, key, allow_none=False) -> QColor:
     """ Shortcut to palette dictionary (self.d) """
     color = self.d.get(key, None)
     if color or allow_none:
         return color
     log.critical(f"Missing color '{key}'.")
     color = c(0, 0, 255)
     self.set_color(key, color, can_save=False)
     return color
Exemplo n.º 7
0
 def method(self):
     """ Dump keyboard shortcuts to console. At some point, make this to use
     dialog window instead.
     :return: None
     """
     m = """(h):------- KatajaMain commands ----------
     (left arrow/,):previous structure   (right arrow/.):next structure
     (1-9, 0): switch between visualizations
     (f):fullscreen/windowed mode
     (p):print trees to file
     (b):show/hide labels in middle of edges
     (q):quit"""
     log.critical(m)
Exemplo n.º 8
0
 def method(self):
     """ Dump keyboard shortcuts to console. At some point, make this to use
     dialog window instead.
     :return: None
     """
     m = """(h):------- KatajaMain commands ----------
     (left arrow/,):previous structure   (right arrow/.):next structure
     (1-9, 0): switch between visualizations
     (f):fullscreen/windowed mode
     (p):print trees to file
     (b):show/hide labels in middle of edges
     (q):quit"""
     log.critical(m)
Exemplo n.º 9
0
 def merge_check(self):
     headf0, *remainders0 = self.part0.features
     headf1, *remainders1 = self.part1.features
     if headf0.value == '=' and headf1.value == '' and headf0.name == headf1.name:
         self.features = remainders0
         if remainders1:
             self.movers = [remainders1]
         self.movers += self.part0.movers
         self.movers += self.part1.movers
     else:
         if log:
             log.critical('merge_check error')
         else:
             raise RuntimeError('merge_check error')
Exemplo n.º 10
0
 def as_list_tree(self):
     if not (self.part0 or self.part1):
         if self.label and isinstance(self.label, str):
             # this is creating ["D'" [ "which" ] ] -trees as lists which we don't want
             return [self.category, [self.label]]
         else:
             return [self.category, [self.label]]
     elif self.part0 and self.part1:  # merge
         return [
             self.label,
             self.part0.as_list_tree(),
             self.part1.as_list_tree()
         ]
     else:
         if log:
             log.critical('XBarTree.as_list_tree')
         else:
             raise RuntimeError('XBarTree.as_list_tree')
Exemplo n.º 11
0
 def as_list_tree(self):
     if not (self.part0 or self.part1):
         if isinstance(self.label, list):
             w = ' '.join(self.label)
         else:
             w = self.label
         return '%s::%s' % (w, ' '.join([str(f) for f in self.features]))
     elif self.part0 and self.part1:  # merge
         return [
             self.label,
             self.part0.as_list_tree(),
             self.part1.as_list_tree()
         ]
     else:
         if log:
             log.critical('BareTree.as_list_tree')
         else:
             raise RuntimeError('BareTree.as_list_tree')
Exemplo n.º 12
0
 def move_check(self):
     mover_match, *remaining = self.part0.features
     self.features = remaining
     found = False
     mover = []
     self.movers = []
     assert self.part0.movers
     for mover_f_list in self.part0.movers:
         if mover_f_list[0].name == mover_match.name:
             if found:
                 if log:
                     log.critical('SMC violation in move_check')
                 else:
                     raise RuntimeError('SMC violation in move_check')
             mover = mover_f_list[1:]
             found = True
         else:
             self.movers.append(mover_f_list)
     assert found
     if mover:
         self.movers.append(mover)
Exemplo n.º 13
0
 def merge_check(self):
     if self.part0.features and self.part1.features:
         headf0, *remainders0 = self.part0.features
         headf1, *remainders1 = self.part1.features
         if headf0.value == '=' and headf1.value == '' and headf0.name == headf1.name:
             self.features = remainders0
             self.movers = self.part0.movers + self.part1.movers
             if remainders1:
                 self.movers.append(remainders1)
                 self.moving.append((remainders1, self.part1))
                 #self.part1 = BareTree(None)  # trace
         else:
             # These errors make sense in completed parses.
             if log:
                 log.critical('merge_check error')
             else:
                 raise RuntimeError('merge_check error')
     if not (self.part0.part0 or self.part0.part1):  # is it leaf?
         self.label = '<'
     else:
         self.label = '>'  # switch order to part1, part0
         temp = self.part0
         self.part0 = self.part1
         self.part1 = temp