Skip navigation.
Home
The QNX Community Portal

View topic - PtMultiText and colors

PtMultiText and colors

Isn't the name clear?

PtMultiText and colors

Postby _KB_ » Wed Jun 19, 2013 3:54 pm

Hi,

I am using a PtMultiText widget to display log events. I would like to print one event per line in the widget and to associate a color to distinguish events.
I wonder if there is an easy way to colorize the full line (beyond text wrap limit) instead of text (text_color attribute), because I am not statified with the graphical result. Because each line of text does not have the same width, this is not harmonious. Or maybe is there a way to add columns to the widget and to colorize each cells separately.

Here is a snippet of code:

Code: Select all
/** Check code event to determine if FAULT, ALARM or INFO type
       */
      PtMultiTextAttributes_t lattributes;
      char lstatus[10];
      lattributes.font = Pt_DEFAULT_FONT;
      if (sevents.events[lcindex].code < 100) {
        if (sevents.events[lcindex].code == 6) {
          lattributes.background_color = Pg_RED;
          lattributes.text_color = Pg_DEFAULT_WM_COLOR;
          strncpy(lstatus, "[ALARM]  ", sizeof(lstatus));
        } else {
          lattributes.background_color = Pg_GRAY;
          lattributes.text_color = Pg_DEFAULT_WM_COLOR;
          strncpy(lstatus, "[STATUS] ", sizeof(lstatus));
        }
      } else if ((sevents.events[lcindex].code < 400)
          && (sevents.events[lcindex].code >= 100)) {

        lattributes.background_color = Pg_YELLOW;
        lattributes.text_color = Pg_DEFAULT_WM_COLOR;
        strncpy(lstatus, "[FAULT]  ", sizeof(lstatus));
      } else if (sevents.events[lcindex].code >= 400) {

        lattributes.background_color = Pg_CYAN;
        lattributes.text_color = Pg_DEFAULT_WM_COLOR;
        strncpy(lstatus, "[INFO]   ", sizeof(lstatus));
      }

      PtMultiTextModifyText(ABW_PtMultiTextEvents, insertion_pt, insertion_pt,
          insertion_pt, lstatus, 9, &lattributes, Pt_MT_FONT | Pt_MT_BACKGROUND
              | Pt_MT_TEXT_COLOR | Pt_MT_FOREGROUND);
      lattributes.background_color = Pg_DEFAULT_WM_COLOR;
      lattributes.text_color = Pg_DEFAULT_WM_COLOR;
      PtGetResource(ABW_PtMultiTextEvents, Pt_ARG_CURSOR_POSITION, &cursor, 0);
      insertion_pt = *cursor;
      PtMultiTextModifyText(ABW_PtMultiTextEvents, insertion_pt, insertion_pt,
          insertion_pt, str, sizeof(str), &lattributes, Pt_MT_FONT
              | Pt_MT_BACKGROUND | Pt_MT_TEXT_COLOR | Pt_MT_FOREGROUND);


Any tip would be great !
Thx.

KB
_KB_
Active Member
 
Posts: 24
Joined: Mon Oct 15, 2012 6:36 pm

Re: PtMultiText and colors

Postby maschoen » Wed Jun 19, 2013 7:00 pm

_KB_ wrote:Hi,

I am using a PtMultiText widget to display log events. I would like to print one event per line in the widget and to associate a color to distinguish events.
I wonder if there is an easy way to colorize the full line (beyond text wrap limit) instead of text (text_color attribute), because I am not statified with the graphical result. Because each line of text does not have the same width, this is not harmonious. Or maybe is there a way to add columns to the widget and to colorize each cells separately.


You've probably looked at the documentation already, so I suspect that the PtMultiText Widget is not going to do what you want. Have you considered using a container or list containing text widgets?
maschoen
QNX Master
 
Posts: 2644
Joined: Wed Jun 25, 2003 5:18 pm

Re: PtMultiText and colors

Postby _KB_ » Wed Jun 19, 2013 7:15 pm

Thank for the quick answer.

I can't use text widgets nor containers because I have up to 1000 events to display!
That's why I use this widget with a scrollbar.
I tried some tricks like strings with spaces padding but unfortunately it doens't do the work :|
My lines have not the same size ...

I figure someone has already try to do something similar and looking for tips aroun here!

Thanks.
_KB_
Active Member
 
Posts: 24
Joined: Mon Oct 15, 2012 6:36 pm

Re: PtMultiText and colors

Postby maschoen » Wed Jun 19, 2013 7:45 pm

_KB_ wrote:Thank for the quick answer.

I can't use text widgets nor containers because I have up to 1000 events to display!



Why is that a problem?
maschoen
QNX Master
 
Posts: 2644
Joined: Wed Jun 25, 2003 5:18 pm

Re: PtMultiText and colors

Postby _KB_ » Wed Jun 19, 2013 8:38 pm

Well I don't know where to start, never used list in Photon before.
Should I use a PtList, a PtRawlist ?

A small example would be great to help me figure this out.

For example if I have a list widget. How do I add a PtText with specific background color and text to it ?
_KB_
Active Member
 
Posts: 24
Joined: Mon Oct 15, 2012 6:36 pm

Re: PtMultiText and colors

Postby _KB_ » Thu Jun 20, 2013 1:40 pm

I've posted an answer to that yesterday but the response is still not published for a reason I ignore.
Do you have an example with list and text widget added dynamically ?

Thanks.
_KB_
Active Member
 
Posts: 24
Joined: Mon Oct 15, 2012 6:36 pm

Re: PtMultiText and colors

Postby maschoen » Fri Jun 21, 2013 4:58 pm

I can't use text widgets nor containers because I have up to 1000 events to display!


All I asked was for you to explain this statement. Why is 1000 events a problem?

I infer from your response that 1000 is not the problem, but that you don't know how to deal with lists.

The place to start is the documentation. It might help to focus on the fact that QNX widgets
are hierarchical. To know what a widget is capable of you, have to check it's properties in the documentation, and the properties of it's ancestors.
All widgets descend from a PtWidget which has basic properties. Widgets that will display on the screen also descend from a PtBasic (which descends from a PtWidget).

The most basic container widget is a PtContainer. This widget adds the ability to contain other widgets.
PtList and PtRawList are descendants of PtContainer so they too can contain widgets. They each add features which may or may not be useful to your application. To find out, you will have to look at their properties.

Given what I know, I think the most straight forward solution for you would be start with a PtScrollContainer, and add PtText widgets to it. You create the PtText widgets using PtCreateWidget() giving them the PtScrollContainer as the parent. There are args, nargs parameters to PtCreateWidget() which allow you to set the text and background color at creation time. You will need to position the text widgets yourself in the scroll widget. You can use either the Pt_ARG_AREA or Pt_ARG_POS properties to set this.

I mentioned PtList because I think it handles the positioning for you, but that doesn't mean it's the right choice.
maschoen
QNX Master
 
Posts: 2644
Joined: Wed Jun 25, 2003 5:18 pm

Re: PtMultiText and colors

Postby mario » Fri Jun 21, 2013 7:30 pm

_KB_ wrote:I've posted an answer to that yesterday but the response is still not published for a reason I ignore.
Do you have an example with list and text widget added dynamically ?

Thanks.


Do you know that Photon is to be deprecated in the next release.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Re: PtMultiText and colors

Postby maschoen » Sat Jun 22, 2013 2:12 am

mario wrote:Do you know that Photon is to be deprecated in the next release.


Mario,

What would you think if I told you that I figured out a way to make Photon programs work beyond 6.5?
maschoen
QNX Master
 
Posts: 2644
Joined: Wed Jun 25, 2003 5:18 pm

Re: PtMultiText and colors

Postby _KB_ » Sun Jun 23, 2013 1:32 pm

maschoen wrote:I infer from your response that 1000 is not the problem, but that you don't know how to deal with lists.

Exactly.

maschoen wrote:Given what I know, I think the most straight forward solution for you would be start with a PtScrollContainer, and add PtText widgets to it. You create the PtText widgets using PtCreateWidget() giving them the PtScrollContainer as the parent. There are args, nargs parameters to PtCreateWidget() which allow you to set the text and background color at creation time. You will need to position the text widgets yourself in the scroll widget. You can use either the Pt_ARG_AREA or Pt_ARG_POS properties to set this.

I mentioned PtList because I think it handles the positioning for you, but that doesn't mean it's the right choice.


Thanks! I'll look into it

mario wrote:Do you know that Photon is to be deprecated in the next release.


Yes I do but as far as I know, Qt is not part of momentics IDE yet and I was short of time at the time to try Qt and compile the GUI separately from momentics.
That's the reason why I started with Photon on this project.

Do you know when momentics will add Qt projects ?

maschoen wrote:Mario,

What would you think if I told you that I figured out a way to make Photon programs work beyond 6.5?


I would be interested to know more about it! :P
_KB_
Active Member
 
Posts: 24
Joined: Mon Oct 15, 2012 6:36 pm

Re: PtMultiText and colors

Postby maschoen » Tue Jun 25, 2013 7:00 pm

_KB_ wrote:Do you know when momentics will add Qt projects ?


It will be interesting if they do. A Qt project is a C++ project using the Qt libraries. So you can make a Qt program with the IDE. The reason I say interesting is that along with the different versions of Qt, there are two major branches. One branch has a GNU license. The other has a commercial license. So which would QNX provide?

On top of this, the current port of Qt works on top of the gf layer. This will change with the next version of QNX as both Photon and gf are going away.
maschoen
QNX Master
 
Posts: 2644
Joined: Wed Jun 25, 2003 5:18 pm

Re: PtMultiText and colors

Postby _KB_ » Wed Sep 25, 2013 1:11 pm

maschoen wrote:
_KB_ wrote:Hi,

I am using a PtMultiText widget to display log events. I would like to print one event per line in the widget and to associate a color to distinguish events.
I wonder if there is an easy way to colorize the full line (beyond text wrap limit) instead of text (text_color attribute), because I am not statified with the graphical result. Because each line of text does not have the same width, this is not harmonious. Or maybe is there a way to add columns to the widget and to colorize each cells separately.


You've probably looked at the documentation already, so I suspect that the PtMultiText Widget is not going to do what you want. Have you considered using a container or list containing text widgets?


I've just figured something. I just need to use a fixed-width font such as Courrier or Textfont.
What was I thinking at the time :roll:

Problem solved :idea:
_KB_
Active Member
 
Posts: 24
Joined: Mon Oct 15, 2012 6:36 pm


Return to GUI Programming

Who is online

Users browsing this forum: No registered users and 0 guests