Forged Alliance Forever Forged Alliance Forever Forums 2014-11-13T16:22:55+02:00 /feed.php?f=41&t=8872 2014-11-13T16:22:55+02:00 2014-11-13T16:22:55+02:00 /viewtopic.php?t=8872&p=85805#p85805 <![CDATA[Re: Adding a sort command for the users in the chat]]> Statistics: Posted by odin002 — 13 Nov 2014, 16:22


]]>
2014-11-12T20:20:19+02:00 2014-11-12T20:20:19+02:00 /viewtopic.php?t=8872&p=85776#p85776 <![CDATA[Re: Adding a sort command for the users in the chat]]>

Sorting is possible with the friendlist in the future ;)
/viewtopic.php?p=85200#p85200


@1 (ButtonAction)
QT used Signals to fire events and you must connect this signals, e.g. to a method:
https://github.com/FAForever/lobby/blob ... er.py#L332

pyqt Signals & Slots:
http://pyqt.sourceforge.net/Docs/PyQt4/ ... slots.html

@2 (UserList)
As I implemented the Friendlist I can tell you:
Their is not single point. Each user is added to the list separately.
Normally a user is added to the chatter here:
https://github.com/FAForever/lobby/blob ... et.py#L297
The chatwidget is created in the startup process.

lt = less then
gt = greater then

This methods are "used" to sort the Chatter (QTableWidgetItem) in the List (QTableWidget).
You must fire a signal to notfiy the view that the data changed:
http://qt-project.org/doc/qt-4.8/qabstr ... ataChanged

Fire the "dataChanged" signal with QModelIndex(), QModexlIndex()
(two invalid QModelIndex are a trick to refresh the whole model)

The Nick Filter changes the model too, but it hides rows and must not call a signal.
https://github.com/FAForever/lobby/blob ... el.py#L147

BUT
A better solution is to enable the TableHeader and use the internal sorting algorithm ;)
Or use a SortFilterProxyModel:
http://qt-project.org/doc/qt-4.8/qsortf ... model.html

Ps.: I refactored the chatter:
https://github.com/FAForever/lobby/pull/122

New sorting functions:
https://github.com/IDragonfire/lobby/bl ... er.py#L117

Maybe I will add this idea ...
because it is hard to implement it as beginner :D

Statistics: Posted by Dragonfire — 12 Nov 2014, 20:20


]]>
2014-11-12T20:04:59+02:00 2014-11-12T20:04:59+02:00 /viewtopic.php?t=8872&p=85775#p85775 <![CDATA[Re: Adding a sort command for the users in the chat]]>
odin002 wrote:
First problem (the blind one):
So yeah I'm happy, I've added this button but it's just "shown", it does nothing, if I wanted for example to add a message on the tab "Server" (the thing no one looks on it...) with self.serverLogArea.appendPlainText("You clicked on sort by country, gj") or Debug.message (I don't remember the exact name of the function, but it's not that hard to find the exact name, anyway it's not important), I don't even know where to add that line to make it happen when I click on "sort users by country". I must be blind...

Code:
        # Triggers
        actionStats.triggered.connect(self.viewStats)
        actionSelectAvatar.triggered.connect(self.selectAvatar)
        actionReplay.triggered.connect(self.viewReplay)
        actionVaultReplay.triggered.connect(self.viewVaultReplay)
        actionJoin.triggered.connect(self.joinInGame)
        #actionInvite.triggered.connect(self.invite)

you have to add a function an connect it to the menu item.
in the function you have to set a variable to indicate how the sorting should be done.
that variable should be used in __lt__.
the variable must be outside the Chatter class: there is one Chatter instance for each name
in the user list. so probably put that variable in the parent.
it might also be a bad idea to set the sorting when you click on a nickname, as the sorting
is not a thing that applies to a single nickname but to all nicknames. but then again you
might wanna do that instead of adding another button to the interface. in any case the
sort option is semantically not a thing that applies to a single nickname therefore the
variable that is set must be outside the Chatter class. But you can of course reference
the variable in the __lt__ function. The parent object is most likely the same for all
Chatter objects and therefore a good place to put the variable.


Second one (the wtf one):
I can sort the users when you connect, but I don't see where the call for showing the list is made.


there is currently no functionality to change the sort order and you have to somehow
execute the sorting again, i.e. "redraw" the whole nickname-list widget.
or try and call sortItems (see below).


So to be able to sort by country I've just modified the __lt__ function in chatter.py .
So I look in all the files of the source code of the client where the "__lt__" is written, to find it and to see who is calling it to sort the users in the list of users of chat).

So __ge__ is calling it. and that's all. and no one is calling __ge__(did the same, looked in all the files of the source code of the client), what kind of sorcery is that? :lol:
Obviously, I'm wrong the __lt__ or/and __gt__ is called, it's not a useless code, and if it was the case it shouldn't have an impact on the lobby(the list of users shouldn't be sorted), but, uh, dunno what to think about that.


the function is called when 'a < b' or 'a > b' is executed with a and b being Chatter objects.
and those comparisons are executed somewhere in
Code:
    def setup(self):
        if not self.private:
            # Non-query channels have a sorted nicklist
            self.nickList.sortItems(Chatter.SORT_COLUMN)

the sortItems function. You dont have to concern yourself with that detail.

Statistics: Posted by rootbeer23 — 12 Nov 2014, 20:04


]]>
2014-11-12T19:20:11+02:00 2014-11-12T19:20:11+02:00 /viewtopic.php?t=8872&p=85771#p85771 <![CDATA[Adding a sort command for the users in the chat]]>
Okay It has been some days that I'm looking for modifying that (I've never used python in the past and I'm not a heavy coder. I'm rather doing that for fun, trying stuff, and help a bit maybe if I can).

So I've succeeded in making the list of users sorted by country(or even custom rating, but it can be whatever, it's just for test).
I've also added the "Sort users by country" when you right click on a user in the list of users . But uh, I've no clue on how to do more...
testonsorting.png

To add another choice/option when you right click on a user (for example ) :
In chatter.py
Code:
def pressed(self, item):   
(..)

        actionSortUsersByCountry = QtGui.QAction("Sort users  by country", menu)
(..)
        menu.addAction(actionSortUsersByCountry)


First problem (the blind one):
So yeah I'm happy, I've added this button but it's just "shown", it does nothing, if I wanted for example to add a message on the tab "Server" (the thing no one looks on it...) with self.serverLogArea.appendPlainText("You clicked on sort by country, gj") or Debug.message (I don't remember the exact name of the function, but it's not that hard to find the exact name, anyway it's not important), I don't even know where to add that line to make it happen when I click on "sort users by country". I must be blind...

Second one (the wtf one):
I can sort the users when you connect, but I don't see where the call for showing the list is made.

So to be able to sort by country I've just modified the __lt__ function in chatter.py .
So I look in all the files of the source code of the client where the "__lt__" is written, to find it and to see who is calling it to sort the users in the list of users of chat).

So __ge__ is calling it. and that's all. and no one is calling __ge__(did the same, looked in all the files of the source code of the client), what kind of sorcery is that? :lol:
Obviously, I'm wrong the __lt__ or/and __gt__ is called, it's not a useless code, and if it was the case it shouldn't have an impact on the lobby(the list of users shouldn't be sorted), but, uh, dunno what to think about that.

Statistics: Posted by odin002 — 12 Nov 2014, 19:20


]]>