#pyqt | Logs for 2018-10-12

Back
[00:06:16] -!- logs has quit [Ping timeout: 244 seconds]
[00:07:26] -!- logs has joined #pyqt
[03:04:39] -!- Mrokii has quit [Quit: WeeChat 2.2]
[03:07:54] -!- kallesbar has joined #pyqt
[03:39:20] -!- anqxyr has joined #pyqt
[04:05:25] -!- crmaurei has joined #pyqt
[04:30:50] -!- hamster007_ has quit [Quit: ZNC 1.6.3+deb1ubuntu0.1 - http://znc.in]
[04:33:19] -!- hamster007_ has joined #pyqt
[04:52:13] <_val_> altendky: no not really
[04:52:29] <_val_> It automatically selects the first host and prints the VM's of the first host in the list
[04:52:36] <_val_> did you see my latest paste?
[04:58:38] <_val_> and I actually want one combobox to be filled in by get_host() function... and another combobox that is filled by get_vm_host() ... based on selection of get_host()
[05:04:36] <_val_> altendky:
[05:04:36] <_val_> self._multi.add_handle(curl)
[05:04:37] <_val_> pycurl.error: cannot add/remove handle - multi-stack is closed
[05:14:09] <_val_> altendky: http://sprunge.us
[05:37:19] <_val_> altendky: http://sprunge.us <-- see this gives me the VM's running on this specific kvm host
[06:09:15] -!- mintograde has joined #pyqt
[06:54:12] -!- mintograde has quit [Ping timeout: 252 seconds]
[07:16:02] <altendky> _val_: if you want another combobox, then make one. and use the signal to trigger a function or method that calls the second code to fill in the combobox
[07:16:10] <altendky> _val_: is there some particular place you are stuck?
[07:20:49] <_val_> altendky: yes. The app crashes
[07:21:07] <altendky> _val_: full code, full output
[07:21:07] <_val_> I can't call the function at all though. creating a second combobox wasn't that hard
[07:21:13] <_val_> hold a sec
[07:22:43] <_val_> altendky: 
[07:22:46] <_val_> http://sprunge.us
[07:23:11] <altendky> _val_: a pastebin with line numbers (gist.github.com?) would help with reading exceptions
[07:25:25] <altendky> also, full output
[07:25:58] <_val_> Oh sure
[07:31:48] <_val_> altendky: https://dpaste.de
[07:32:12] <_val_> well it doesn't crash now since I used get_host() funciton.. but once I place another get_vm_host() function in one of the comboboxes it crashes
[07:32:43] <altendky> _val_: it's hard to debug code that doesn't show the problem
[07:34:00] <altendky> _val_: but, the global CONN thing isn't great.
[07:34:40] <altendky> _val_: and you get_hosts() closes the connection without actually setting CONN back to None so it won't reconnect
[07:34:53] <_val_> altendky: oh?
[07:35:03] <_val_> I thought I'd reuse that connection...
[07:35:16] <altendky> _val_: there are alternatives to globals
[07:38:49] <_val_> altendky: I am open to improvements
[07:39:30] <altendky> _val_: if you are going to reuse the connection, don't close it. at least not without doing all the proper stuff to reset your connection reuser to a state where it will know to reconnect
[07:39:32] <_val_> Though.. I can call those functions seperately get_hosts() and get_vm_host(), I cannot have both at the same time which I can't figure out how to fix it
[07:39:46] <altendky> _val_: as i said, get_hosts() closes the connection
[07:39:57] <altendky> without 'marking' it as closed
[07:40:10] <altendky> (unless a closed connection is falsey which i wouldn't bet on)
[07:47:32] <altendky> _val_: do you understand what i'm pointing out?
[07:51:54] <_val_> altendky: I removed that
[07:51:58] <_val_> sec
[07:54:15] <_val_> https://dpaste.de
[07:54:17] <_val_> altendky:
[07:54:33] <altendky> _val_: it's still there on line 33
[07:58:09] <_val_> altendky: holy crap.. yeah that fixed it
[07:58:24] <_val_> Stupid me.. but ok.. now the second combobox is filled in but the selection doesn't matter
[07:58:30] <_val_> Can we fix that too?
[07:58:57] <altendky> _val_: full code, full output
[08:01:09] <_val_> altendky: https://dpaste.de
[08:02:13] <_val_> now both comboboxes are filled but the second combobox named: selectvm.addItems(get_vm_host()) gets always the same vms coming from the first host which is in the list of get_hosts()
[08:03:07] <altendky> _val_: you are supposed to use onActivated to fill the second combobox depending on the text selected in the first combobox
[08:04:31] <_val_> altendky: combo.activated[str].connect(self.onActivated) becomes?
[08:04:37] <_val_> becomes what?
[08:04:43] <altendky> _val_: can you describe what that line does?
[08:05:25] <_val_> this line calls
[08:05:31] <_val_> def onActivated(self, text):
[08:05:31] <_val_>
[08:05:32] <_val_> self.lbl.setText(text)
[08:05:32] <_val_> self.lbl.adjustSize()
[08:07:51] <altendky> _val_: nope. it connects the combo's activated signal to that method. that means that when the combo emits its activated signal (the docs describe when this happens) _then_ the onActivated method will be called.
[08:08:38] <altendky> _val_: so, when the user picks an item in `combo`, onActivated will be called. since it is passed the text of the selected item you can use that text to get the vms for that particular host and fill the second combo
[08:10:03] <_val_> altendky: so I would rather substitue onActivated function with get_vm_host() function?
[08:10:28] <_val_> combo.activated[str].connect(self.onActivated) becomes: combo.activated[str].connect(get_vm_host()) ?
[08:10:39] <altendky> _val_: no. small functions are good. get_vms() does that. something else can call get_vms() to get the list and then put it into the combobox
[08:11:09] <altendky> _val_: that way, if you ever just want the list of vms, you can get just that without it being put into the combo
[08:11:52] <altendky> _val_: basically, write a not-gui program, then put a gui in front of it. all the basic functionality should be able to work without any gui code. it makes automated testing much easier and makes your code more flexible.
[08:20:32] <_val_> altendky: well I wanted to fix this one
[08:20:49] <altendky> _val_: sure. just do what you want in onActivated
[08:21:07] <_val_> altendky: but onActivated is just a function ... right?
[08:21:20] <altendky> _val_: it's a method. but i'm not sure what that matters here
[08:21:27] <_val_> self.lbl.setText(text) would set the text coming from the first combobox
[08:21:59] <altendky> _val_: ok, but what you wanted was to set the items in the second combobox based on the selected host and the result of get_vms()
[08:22:10] <_val_> Yes
[08:22:19] <_val_> well the method is called get_vm_host() but yes
[08:22:39] <altendky> _val_: side note, shouldn't that take a host as a parameter?
[08:23:02] <_val_> altendky: correct
[08:23:22] <_val_> that is in the function get_vm_host()... which is host.name
[08:23:43] <altendky> _val_: get_vm_host() gets all vms for all hosts, yes?
[08:25:36] <_val_> altendky: sec
[08:26:19] <_val_> altendky: https://dpaste.de
[08:26:27] <_val_> this will get the vms on kvmhost06
[08:27:58] <altendky> _val_: the first part of `get_vm_host()` is `get_hosts()`. you should probably just call `get_hosts()`. the second part of `get_vm_host()` should be calling a new function for each host. then you'll have a function which can get the vms for a single host. that's what you would want to call in `onActivated()` i think.
[08:35:28] <_val_> altendky: I don't get it to be honest. This seems too complex :/
[08:35:47] <altendky> _val_: it's just breaking down into pieces. just a minute
[08:43:03] <altendky> _val_: https://gist.github.com -- https://www.diffchecker.com
[08:46:46] <_val_> altendky: self.selectvm.addItems(get_vm_host())
[08:46:47] <_val_> NameError: name 'get_vm_host' is not defined
[08:49:30] <altendky> _val_: https://gist.github.com (you can click the revisions tab to see a diff)
[08:51:52] <_val_> haha. Dude you are awesome!
[08:51:58] <_val_> And I like your beard :-p
[08:52:13] <_val_> It works. Now I am going to digest the python code.
[08:52:15] <altendky> _val_: alrighty, so next step is getting rid of the global (i'm assuming it 'worked')?
[08:52:27] <altendky> _val_: alrighty, let me know when you are ready for another class
[08:52:41] -!- Siecje has joined #pyqt
[08:52:54] <altendky> (as in a python class to hold the connection and methods)
[09:08:01] <_val_> altendky: reviewing..
[09:24:45] <_val_> altendky: hmm.. I want to make the combobox wider but can't seem to do that :/
[09:25:04] <_val_> 79 self.combo.setMaximumWidth(400)
[09:25:09] <_val_> nor works..
[09:25:43] <altendky> _val_: you should be using layouts and with layouts you don't just 'make it wider'. you should decide how you want the space shared between your various widgets
[09:33:21] <_val_> altendky: just a sec
[10:03:35] <_val_> altendky: https://imgur.com
[10:03:41] <_val_> this is the layout I was thinking of
[10:07:20] <_val_> altendky: gridlayout?
[10:08:07] <altendky> _val_: sure, i generally use it at the top level myself
[10:17:13] <_val_> altendky: hmm let me see if I can change that
[10:29:24] <_val_> altendky: even that is quite hard.. seems to break every time :)
[10:38:07] <_val_> altendky: https://dpaste.de
[10:38:21] <_val_> but getting errors. I know this doesn't work but what am I missing?
[10:39:14] <_val_> altendky: super(Dialog, self).__init__()
[10:39:14] <_val_> NameError: name 'Dialog' is not defined
[10:39:47] <altendky> _val_: py3, yes?
[10:40:26] <_val_> ok
[10:40:28] <altendky> _val_: so, don't pass anything to super. when you do pass to super it's the class you are in (not the one you are inheriting from, which is QDialog not Dialog).
[10:40:31] <_val_> forget that.. I made a mistake myself
[10:40:33] <_val_> now works
[10:40:51] <altendky> so it'd be super(Login, self) in py2
[10:40:52] <_val_> altendky: the idea is now to provide username, password using that Login thing
[10:40:59] <_val_> Yes
[10:41:03] <_val_> Indeed.. that fixed it
[10:43:32] <_val_> Now the idea is the have QLineEdit receive the username, pass
[10:51:34] <_val_> altendky: ok another I think more important question. I have another datacenter with kvm hosts. How can I make a change so e.g I can connect to both and list hosts on both in same combobox
[10:52:36] <altendky> _val_: a couple layers. but first, does it use the same library to get the info?
[10:54:20] <_val_> yes
[10:55:11] <altendky> _val_: alrighty, i'd say first make a class to hold all the connection stuff and make it not-global
[11:01:18] <_val_> altendky: but they have a different URL
[11:01:22] <_val_> that is the only thing that changes
[11:01:25] <altendky> _val_: sure
[11:02:09] <altendky> _val_: all the more reason to package it up nicely in a class where you can configure that. otherwise you'll end up with `get_connection_a():` and `get_connection_b():` and `get_host_vms_a():` and `get_host_vms_b():` etc
[11:11:15] <_val_> altendky: hmm
[11:11:24] <_val_> you really think I can manage that? @_@
[11:11:39] <altendky> _val_: yup
[11:14:54] <_val_> no I really cant
[11:15:20] <altendky> _val_: you think you can more easily manage to keep multiple copies of the functions in sync and straight?
[11:15:41] <altendky> _val_: are you familiar with classes? i see you wrote a couple but...
[12:00:07] <_val_> altendky: I have programmed in java few years ago. Now mostly doing bash, awk, sed and a little python
[12:00:28] <_val_> Sorry for my late reply. I just came back home
[12:01:18] <_val_> I e.g instantiated a class using class_var = new Classname(); then called methods of that class using: class_var.class_method(....)
[12:07:33] <altendky> _val_: I don't think a class is that big a stretch. I do think maintaining this otherwise might be. And learning is good :]
[12:08:29] <_val_> altendky: well I need to focus on doing one thing first.
[12:08:43] <_val_> I'll check how I could make entering username, password etc.. in the fields
[12:38:39] <altendky> _val_: if you end up wanting to store passwords, the keyring library is often recommended.
[12:53:12] <_val_> altendky: well I have no idea but that should be maye for later.. since this is too much to digest :)
[12:53:42] <altendky> _val_: sure, just making sure you don't go writing your passwords to files instead :]
[12:55:27] <_val_> Lol. Thanks. No I am aware of security implications then :>
[13:07:24] <_val_> altendky: https://i.imgur.com
[13:07:26] <_val_> :)
[13:07:48] <altendky> _val_: step by step, progress :]
[13:08:40] <_val_> altendky: yeah kinda learning by doing.. but still have to understand things better later on: https://dpaste.de
[13:08:50] <_val_> see the code that produces that (image I posted)
[13:11:09] <_val_> hmm wait.. it doesn't clear the vm's
[13:11:11] <_val_> :/
[13:33:55] <altendky> _val_: line 103? https://dpaste.de
[14:01:00] -!- kallesbar has quit [Quit: Konversation terminated!]
[14:55:12] <_val_> _val_: yes I commented that
[14:55:20] <_val_> altendky: ^
[14:55:32] <altendky> _val_: that was the thing i put there to clear the list before adding new stuff
[14:56:41] <_val_> altendky:
[14:56:45] <_val_> ok be back later
[15:12:31] <_val_> altendky: well I commented that seems to be working better but need to check a few things
[16:08:21] <_val_> ping altendky
[16:08:29] <_val_> are you still here?
[16:08:38] <altendky> _val_: just ask. if i don't get back right away, i will alter
[16:08:43] <altendky> later
[16:09:04] <_val_> altendky: alright. I fill somehow guilty of taking so much of your time
[16:09:05] <_val_> :/
[16:09:11] <_val_> So here I wrote this code: https://dpaste.de
[16:09:32] <_val_> It will traverse through all VM's and get disk size and ID.
[16:09:52] <_val_> How could I make this code work on pyqt?
[16:10:51] <altendky> _val_: i'd still break it up
[16:11:31] <altendky> _val_: remember how i took the function for getting all vm's on all host's and made a function for getting all vm's on one host? then called that from the modified original function?
[16:11:32] <_val_> altendky: so actually when a vm is selected, its disk will appear
[16:11:51] <_val_> altendky: yes I saw that
[16:11:58] <altendky> _val_: same thing here
[16:12:37] <_val_> altendky: so I need to create a method e.g get_vm_disks() ?
[16:12:44] <_val_> altendky: so I need to create a method e.g get_vm_disks(vm_name) ?
[16:12:54] <altendky> _val_: perhaps. until you put it in a class it's a function though
[16:13:38] <_val_> altendky: yeah I mean a function as in def get_vm_disks
[16:14:00] <altendky> _val_: when it's inside a class it's a method, outside it's a function
[16:15:10] <_val_> altendky: yeah I get that. SO the class first needs to be instantiated to call its methods
[16:16:09] <_val_> altendky: ok see this:
[16:16:20] <_val_> def get_vm_disks():
[16:16:20] <_val_> disks = {}
[16:16:20] <_val_> for disk in get_all_vms:
[16:16:20] <_val_> disks[disk] = get_all_vms
[16:16:22] <_val_> return disks
[16:16:50] <altendky> _val_: get_all_vms is going to return disks?
[16:16:59] <altendky> and get called also inside the loop?
[16:18:09] <_val_> altendky: I don't knokw. Though I need to loop through vm's and some vms have 2 disks
[16:18:12] <_val_> so hmm
[16:18:24] <_val_> You saw my early paste?
[16:18:45] <altendky> _val_: yes
[16:19:02] <_val_> yeah that piece gets the disks
[16:20:02] <altendky> _val_: how about a function `def get_disks(vm):`? so you can get the disks for a single vm. isn't getting all the disks for all the vm's a thing that could use that little `get_disks()` function?
[16:20:23] <_val_> altendky: ok let me work on that
[16:20:31] <_val_> Yeah was doing this .. sec
[16:23:02] <_val_> altendky: https://dpaste.de
[16:23:06] <_val_> does this make sense?
[16:23:13] <_val_> I need the return statement as well but how?
[16:24:06] <altendky> _val_: create either a list or dict depending and add to it each time through the loop. then return when done
[16:24:47] <_val_> altendky: :/
[16:31:08] <altendky> _val_: does it make sense?
[16:32:00] <_val_> altendky: no . I am trying and trying
[16:33:24] <altendky> _val_: https://repl.it
[16:33:49] <_val_> altendky: https://dpaste.de
[16:33:55] <_val_> oh
[16:34:42] <_val_> Cool. Ok I'm seeing python consol
[16:34:42] <_val_> e
[16:35:59] <_val_> altendky: well that was my attempt
[16:36:24] <altendky> _val_: did you understand the code i shared? `def double(stuff):`?
[16:36:44] <_val_> altendky: yes
[16:41:48] <altendky> _val_: what part are you having trouble connecting to your code?
[16:43:59] <_val_> altendky: https://dpaste.de this part
[16:44:21] <_val_> I tried to mimic you as you did it earlier with vms functions
[16:45:34] <altendky> _val_: get_all_disks() is ok at first glance. you don't have any loops or collections at all in get_vm_disks() though
[16:46:39] <altendky> _val_: i'm going to head out soon. this isn't pyqt specific so you should be able to get good help over in #python. i help out a lot over there so i'm not just dumping you on another channel :] just have to pick up the kids from daycare in a few minutes.
[16:47:50] <_val_> altendky: alright! thank you for your time.
[16:49:21] <_val_> I will try and figure it out. Well it works in a plain python file. I mean listing vm name , disk size and id
[16:49:31] <_val_> doesn't work when trying to combine stuff
[16:49:53] <altendky> _val_: yeah, you need to get a feel for collecting stuff other than via print :]
[16:55:51] -!- mintograde has joined #pyqt
[17:05:35] <_val_> meh this is not doable :?
[17:29:40] -!- anqxyr has quit [Read error: Connection reset by peer]
[17:37:54] -!- Siecje has parted #pyqt
[18:59:41] -!- mandeep has joined #pyqt
[19:17:06] -!- frispete has joined #pyqt
[19:18:23] -!- frispete_ has quit [Ping timeout: 250 seconds]
[19:31:33] -!- kallesbar has joined #pyqt